LPC Demo Board Lessons
© 2005 Microchip Technology Inc. DS51556A-page 15
3.2.2 Lesson 2: Delay Loop (Blink a LED)
The first lesson showed how to turn on a LED, this lesson shows how to make it blink.
While this might seem a trivial change from Lesson 1, the reasons will soon become
apparent.
New Instructions
CLRF Clear file register
INCF Increment file register
DECF Decrement file register
INCFSZ Increment file register, Skip next instruction if zero
DECFSZ Decrement file register, Skip next instruction if zero
GOTO Jump to a new location in the program
EXAMPLE 3-2: PICkit 2, LESSON 2: BLINK
While adding a BCF instruction and making it loop will make it blink, it will blink so fast
you won’t see it. It will only look dim. That loop requires 4 instruction times to execute.
The first instruction turns it on. The second one turns it off. The GOTO takes two instruc-
tion times, which means it will be on for 25% of the time.
As configured, the PICmicro executes 1 million instructions per second. At this rate, the
blinking needs to be slowed down so that the blinking can be seen, which can be done
by using a delay loop.
Loop
BSF PORTC,0 ;turn on LED C0
BCF PORTC,0 ;turn off LED C0
GOTO Loop ;do it again
Note: Counting cycles – Relating clock speed to instruction speed. The processor
requires 4 clocks to execute an instruction. Since the internal oscillator as
used in these lessons runs at 4 MHz, the instruction rate is 1 MHz.