Datasheet
PICkit™ 3 Debug Express Lessons
© 2009 Microchip Technology Inc. DS41370C-page 57
3.9.3 Exploring the Lesson 9 Source Code
The Lesson 9 program code has a simple background loop in the main() function that
displays a binary count on the demo board LEDs, as shown in Figure 3-46. Each count
increment is delayed by 64,000 instruction cycles. As the clock frequency is changed,
the instruction rate changes and so the total time in seconds of the delay gets shorter
as the clock frequency increases. The effect is that the LED display will count faster as
the clock speed is increased.
At the start of the program, the internal oscillator is running at 250 kHz. Each press of
the demo board switch creates an interrupt that increases the clock frequency by a
factor of 2 up through 64 MHz, after which it returns to 250 kHz.
FIGURE 3-48: SOURCE CODE BACKGROUND LOOP
A few other things of interest in the Lesson 9 source code are:
• The interrupts are configured for only a single level of priority, where interrupt pri-
orities are disabled. This differs from the Lesson 8 source code where interrupt
priorities were enabled.
• Instead of using ADCON1 to configure the switch input RB0 as a digital input as
was done in previous lessons, the Lesson 9 source sets the Configuration bit
PBADEN = OFF. This causes all PORTB pins to default to digital, instead of ana-
log, inputs on a Reset.
• The Lesson 9 interrupt service function void InterruptService(void) dem-
onstrates calling another function
void SetIntOSC(IntOSCFreq *ClockSet)
from within the interrupt service code.
3.9.4 Build and Run the Lesson 9 Code with PICkit 3 Debug Express
Build and program the Lesson 9 project, then Run the application in the debugger.
Pressing the demo board switch causes the program to change the oscillator frequency
during execution. As the oscillator frequency increases, the rate at which the LEDs
count increases.
while (1)
{// delayand counton LEDs here.Interrupt handles switch and freqchanges
LATD =LED_Count++; //output countto PORTD LEDs
Delay1KTCYx(32); //delay 32,000cycles or about 1 secat 125kHz
}