
C.5
LESSON 3 – INTERRUPTS
This program demonstrates how to use the Timer0 and pin change interrupts onboard
the PIC12F6XX. In addition, the program illustrates how the PIC12F6XX is multiplexing
the LED's fast enough to give the visual representation that the LED's are all on at the
same time when in fact the LED's are lit individually. Finally, this program uses the
interrupt on-pin change to detect and debounce a button push which changes the rate
at which the LEDs are flashed.
This lesson covers the following topics:
?
?
?
?
?
How to flash LEDs on the PICkit 1 Flash Starter Kit board
How to use Timer0 and pin change interrupts on the PIC12F6XX
How to turn a source code file into a library file for easy reuse
Useful applications that can use the concepts presented in this lesson
Files needed to customize the source code for the application
C.5.1
Design
One of the challenges of using an 8-pin PIC microcontroller is having enough pins for
a robust application. The PICkit 1 Flash Starter Kit utilizes design tips and tricks to get
the most out of the 8/14-pin PIC microcontroller devices. In particular, a 12-LED array
is implemented on the PICkit 1 Flash Starter Kit by using only 4 pins. In this lesson, only
8 LED's are implemented. See Table C-1 for LED multiplexing. Also, see “TIP #2
Input/Output Multiplexing”, in the “Microchip Tips 'n Tricks 8-pin Flash PIC ? Micro-
controller” booklet (DS44040) for more details on LED multiplexing.
TABLE C-1:
LED MULTIPLEXING TRUTH TABLE
PIN
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
D10
D11
GP4
GP5
GP2
GP1
HI LOW HI LOW Z Z Z Z Z Z HI LOW
LOW HI Z Z HI LOW Z Z HI LOW Z Z
Z Z LOW HI LOW HI HI LOW Z Z Z Z
Z Z Z Z Z Z LOW HI LOW HI LOW HI
Legend: HI => Logic 1, LOW => Logic 0 and Z => TRISIO = 1
C.5.2
Implementation
The lesson utilizes interrupts to make the LED operation transparent to the main
program. The main program writes the value 0xFF to the LEDREGISTER. This flashes
8 LEDs on the PICkit 1 Flash Starter Kit board. In order to flash 4 LEDs, for example,
write 0x0F into the LEDREGISTER. The interrupt service routine uses a Timer0
interrupt for updating the LED array. A GP3 pin change interrupt detects a button push.
The Timer0 prescaler is adjusted and changes the amount of time it takes for a Timer0
interrupt to happen. This gives the visual representation that the LEDs are all on at the
same time, or sequencing.
This lesson introduces the intlib library. The intlib library contains the core functions for
flashing the LEDs and debouncing the GP3 push button. The intlib library contains the
functions Display and Debounce. The library also contains the general purpose
register, LEDREGISTER, to flash LEDs. See Section C.9.5, “Modifying the Source
Code”, for more information on the required files needed to build this project in MPLAB
IDE. Also, see the source code files for additional comments on the implementation.
? 2004 Microchip Technology Inc.
DS40051D-page 53