PICDEM TM Lab Development Board User’s Guide
3.4.5
3.4.5.1
Lab 6: Push Button Interrupt
NEW REGISTERS USED IN THIS LAB
To configure the peripherals used in this lab, the following registers are used:
1. OPTION Register: OPTION (Register 2-2 in Section 2 of the PIC16F690 Data
Sheet)
- Selects the edge transition on RA2/INT that will trigger an interrupt.
2. Interrupt Control Register: INTCON (Register 2-3 in Section 2 of the PIC16F690
Data Sheet)
- Enable interrupt functionality on the PIC16F690.
- Enables the RA2/INT external interrupt.
- Contains a flag that indicates the external interrupt has occurred.
3.4.5.2
OVERVIEW
This lab expands upon Lab 5 by adding an interrupt that will occur each time the push
button connected to the RA2 pin is pressed.
As mentioned, polling a bit is heavily reliant on a number of factors such as the size of
the firmware and the timing of the software control loop. Polling does have its uses.
However, there may be times when an event, such as pressing a push button, requires
immediate attention. This is where the interrupt comes in. As the name implies, an
interrupt acts as a sort of alarm. When the Central Processing Unit receives an inter-
rupt, it immediately stops what it is doing, saves where in the code it was before the
interrupt, performs code or firmware defined by the user in the event of an interrupt
called an Interrupt Service Routine (ISR), and then returns to the previous task it was
performing prior to the interrupt.
So, why not use interrupts all the time? The answer is mainly cost. In order to
implement an interrupt for a specific function, the user may need to purchase a micro-
controller with a peripheral that accommodates the interrupt. This increases the cost of
the application. In some cases, polling a bit may be the way to go. Other cases may
require the interrupt thereby justifying the added cost of a particular peripheral.
The RA2 pin associated with the PORTA register features an external edge-triggered
interrupt capability (note the INT designation on the PIC16F690 Pin Diagram in Table
5 of the data sheet). The interrupt is configurable to occur on either the rising-edge (i.e.,
signal on RA2 pin transitions from low-to-high) or the falling-edge (i.e., signal on RA2
pin transitions from high-to-low) of the voltage on the RA2 pin. If the selected edge tran-
sition is detected on RA2, the CPU then services the interrupt before returning to the
code it was executing prior to the interrupt. Referring again to Figure 3-12, the push
button connected to the RA2 pin is pulled high when not pressed. Therefore, the inter-
rupt will be configured to trigger on the high-to-low transition indicating a push button
press.
The INTCON register contains the enable (INTE) and flag (INTF) bits for the RA2
external interrupt. These bits indicate to firmware the condition that caused an interrupt
to occur. The other bits and accompanying registers are used for other peripheral
features on the microcontroller. The Global Interrupt Enable bit (GIE) is a sort of master
switch that allows interrupts, if individually enabled, to be used by the microcontroller.
The OPTION register features the Interrupt Edge Select (INTEDG) bit that will be used
to indicate the edge transition that will trigger an interrupt.
The software flowchart for this lab is shown in Figure 3-23.
DS41369A-page 48
? 2009 Microchip Technology Inc.
相关PDF资料
DM164120-1 BOARD DEMO PICKIT 2 LP COUNT
DM164120-3 BOARD DEMO PICKIT2 28-PIN
DM164120-5 BOARD DEMO PICKIT 2 64/80-PIN
DM164123 KIT MANAGEMENT SYSTEM PICDEM
DM180021 KIT STARTER MPLAB FOR PIC18F MCU
DM183022 BOARD DEMO PIC18FXX22 64/80TQFP
DM183032 BOARD EXPLORER PICDEM PIC18
DM240001 BOARD DEMO PIC24/DSPIC33/PIC32
相关代理商/技术参数
DM163035+TEFLCST3 制造商:Microchip Technology Inc 功能描述:KIT PICDEMLAB+FLOWCODE-HOME BUNDLE/ 制造商:Microchip Technology Inc 功能描述:PICDEM, FLOW CODE, LAB, DEV KIT
DM163045 功能描述:开发板和工具包 - PIC / DSPIC PICDEM Lab Dev Kit (with PICkit 3) RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM1-63-C 功能描述:端子 Metric Fem Disc non-insulated RoHS:否 制造商:AVX 产品:Junction Box - Wire to Wire 系列:9826 线规:26-18 接线柱/接头大小: 绝缘: 颜色:Red 型式:Female 触点电镀:Tin over Nickel 触点材料:Beryllium Copper, Phosphor Bronze 端接类型:Crimp
DM1-63M-C 功能描述:端子 Metric Male Disc non-insulated, 0 RoHS:否 制造商:AVX 产品:Junction Box - Wire to Wire 系列:9826 线规:26-18 接线柱/接头大小: 绝缘: 颜色:Red 型式:Female 触点电镀:Tin over Nickel 触点材料:Beryllium Copper, Phosphor Bronze 端接类型:Crimp
DM164 制造商:SITI 制造商全称:SITI 功能描述:8x3-CHANNEL CONSTANT CURRENT LED DRIVER
DM1640 制造商:SANYO 制造商全称:Sanyo Semicon Device 功能描述:16 characters x 4 line Liquid Crystal Dot Matrix Display Module
DM1640-0AL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic
DM1640-0BL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic