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.
For a high-level flowchart, see Figure C-10.
? 2004 Microchip Technology Inc.
DS40051D-page 53
相关PDF资料
DV164120 KIT STARTER PICKIT 2
DV164121 KIT PICKIT 2 DEBUG EXPRESS
DV164122 ANALYZER SRL PICKIT W/DEMO BOARD
DV164131 KIT STARTER PICKIT 3
DV164132 KIT EVAL F1 FOR PIC12F1/PIC16F1
DV243003 KIT STARTER FOR SRL MEM PRODUCTS
DVA1001 ADAPTER FOR PIC16F716 18DIP
DVA1004 DEVICE ADAPTER 8/14/20DIP
相关代理商/技术参数
DV164101 制造商:Microchip Technology Inc 功能描述:TOOLS: FLASH MICROCONTROLLER (
DV164102 功能描述:开发板和工具包 - 无线 rfPICkit RoHS:否 制造商:Arduino 产品:Evaluation Boards 工具用于评估:AT32UC3L 核心:AVR32 频率: 接口类型:USB 工作电源电压:5 V
DV164120 功能描述:电路内置调试器 PICkit 2 8/14/20P Flash RoHS:否 制造商:Microchip Technology 产品:In-Circuit Debugger Kits 工具用于评估:PIC MCUs, dsPIC DSCs 用于:07-00024, AC164113 核心:dsPIC, PIC 接口类型:USB 工作电源电压:3 V to 5 V
DV164121 功能描述:电路内置调试器 PICkit 2 Debug Express RoHS:否 制造商:Microchip Technology 产品:In-Circuit Debugger Kits 工具用于评估:PIC MCUs, dsPIC DSCs 用于:07-00024, AC164113 核心:dsPIC, PIC 接口类型:USB 工作电源电压:3 V to 5 V
DV164121 制造商:Microchip Technology Inc 功能描述:ICPICKIT2 PROGRAMMER/DEBUGGER ((NW))
DV164121+TEFLCST3 制造商:Microchip Technology Inc 功能描述:KIT PICKIT2+FLOWCODE-HOME BUNDLE 制造商:Microchip Technology Inc 功能描述:ICD, PICKIT 2, FLOW CODE, PIC, DSPIC 制造商:Microchip Technology Inc 功能描述:ICD, PICKIT 2, DEBUG EXP, FLOW CODE, PIC, DSPIC; Silicon Family Name:PIC12F6xx, PIC16F5xx; Core Architecture:PIC; Core Sub-Architecture:PIC12, PIC18, PIC24; IC Product Type:Debugger / Programmer; Series:PICkit 2 ;RoHS Compliant: Yes
DV164122 功能描述:界面开发工具 PICkit Ser Analyzer RoHS:否 制造商:Bourns 产品:Evaluation Boards 类型:RS-485 工具用于评估:ADM3485E 接口类型:RS-485 工作电源电压:3.3 V
DV164126 功能描述:开发板和工具包 - PIC / DSPIC USB Kit w/ PICkit LowPinCount RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压: