task. Behind the scenes, I’ve
assigned the PIC16F18345’s
internal 16 MHz oscillator as
the clock source. As you can
see in Screenshot 7, I’ve set up
the PIC16F18345’s Timer1 to
interrupt every millisecond.
The interrupt handler work is
done within the tmr1.c file.
With the exception of the
LATB code addition (which I
made), the tmr1.c code was
generated by the Code
Configurator:
void TMR1_ISR(void)
{
static volatile
unsigned int
CountCallBack = 0;
■ SCREENSHOT 5. The MPLAB Code Configurator generates macros for every input or
output defined within its graphical interface. The Configurator code is optional as far as
usage is concerned. You can ignore the generated code and write your own macros if
you desire.
// Clear the TMR1 interrupt flag
PIR1bits.TMR1IF = 0;
TMR1H = (timer1ReloadVal >> 8);
TMR1L = timer1ReloadVal;
LATBbits.LATB7 = ~LATBbits.LATB7;
// callback function - called every
// 1000th pass
if (++CountCallBack >= TMR1_
INTERRUPT_TICKER_FACTOR)
{
// ticker function call
TMR1_CallBack();
// reset ticker counter
CountCallBack = 0;
■ SCREENSHOT 6. What you don’t see here is the configuration
menu for the pushbutton. The button can be configured to fire or
go into a high impedance state when pressed or released.
Digital Discovery
Waveforms 2015
Digilent
www.digilentinc.com
Explorer 8
PIC16F18345
MPLABX
XC8 C Compiler
Microchip
www.microchip.com
■ SCREENSHOT 7. All I had to
do to get the PIC16F18345’s
Timer1 to generate a periodic
interrupt was fill in the blanks.
What you don’t see here is that
the PIC16F18345 is running at
16 MHz on its internal oscillator.
June 2017 49