Datasheet

PICkit™ 3 Debug Express
DS41370C-page 24 © 2009 Microchip Technology Inc.
Headers for the libraries can be found in the MCC18 header directory C:\MCC18\h.
The source code for most of the libraries can be found in C:\MCC18\src, and the
libraries themselves are in C:\MCC18\lib. For more detailed information on the
included library functions see theMPLAB C18 C Compiler Libraries” document
(DS51297).
The other new line of special interest is a function call to a function in the delays library:
Delay1KTCYx(50);
This function creates a time delay with a software of 1000 (1k) instruction cycles (TCY)
times the argument value. In this case, the argument is 50 so this function will delay for
50 x 1,000 = 50,000 instruction cycles. The instruction rate on PIC18FXXXX
microcontrollers is equal to 1/4
th
the oscillator clock; in other words, it takes 4 clocks to
execute an instruction. In this case the clock is the internal oscillator at 1 MHz, so the
instruction rate is 250 kHz, or TCY = 4us per instruction. The total delay is 50,000 x 4us
= 200 ms, which is slow enough for the human eye to see the LED turning on and off.
The Lesson 2 program runs this delay inside an indefinite while loop, which sets the
RD7 I/O pin to the complement of its current value (the effect is to switch it back and
forth between high and low) with a 200 ms delay in between each RD7 output level
change. This blinks the demo board LED 7.
3.2.4 Build and Program the Lesson 2 Code
Select MPLAB IDE menu, build the Lesson 2 project and program the code into the
demo board PIC18F45K20 using the PICkit 3 Programmer as we did in Lesson 1.
The demo board LED 7 will blink continuously at 200 ms on and 200 ms off.