Since we’re only interested in checking out the state
of RB7, our main application doesn’t have to do
anything. So, we simply put the main application
into an endless loop that does absolutely nothing:
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
while (1)
{
// Add your application code
}
The Digital Discovery is attached to the
PIC16F18345’s RB7 output pin. So, we should be
able to capture a waveform that consists of 1 mS
pulses from RB7. All we have to do on the
Discovery side is select the Logic Analyzer function
in Waveforms 2015 and assign the Discovery’s D27
input pin as the waveform capture pin. The results
of our labor are displayed in Screenshot 8. I
selected the Pulse measurement option to measure
the time between the waveform transitions emitted
by the PIC16F18345’s RB7 I/O pin.
■ SCREENSHOT 8. Everything we want and need to know
about what is happening on the PIC16F18345’s RB7 I/O pin is
shown here.
Speaking in Tongues
The Digital Discovery is
capable of decoding UART, SPI,
and I2C signal streams. In
Screenshot 9, I’ve set up the
PIC16F18345’s EUSART based
on an 8 MHz system clock. To
enable the use of printf in the
application code, I’ve checked
the Redirect STDIO to USART
box. Once again, MPLAB does
the heavy lifting.
■ SCREENSHOT 9. This PIC16F18345 EUSART configuration is based on an 8 MHz
system clock. I’ve checked the Redirect STDIO to USART box to allow the use of
printf in our application code.
I took advantage of the
PIC16F18345’s PPS (Peripheral
Pin Select) module to place the
EUSART pins at RB6 and RB7.
However, I didn’t have to figure
out the PPS register settings. I
left that to the Code
Configurator too:
To activate the PIC16F18345’s Global and Peripheral
interrupts, we must uncomment the associated lines of
code in the main.c code:
// Enable the Global Interrupts
INTERRUPT_GlobalInterruptEnable();
bool state = GIE;
GIE = 0;
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0x00; // unlock PPS
// Enable the Peripheral Interrupts
INTERRUPT_PeripheralInterruptEnable();
RXPPSbits.RXPPS = 0x0E; //RB6->EUSART:RX;
RB7PPSbits.RB7PPS = 0x14; //RB7->EUSART
//:TX;
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0x01; // lock PPS
GIE = state;
The application code is short and sweet:
50 June 2017