44-Pin Demo Board Lessons
When the master interrupt line is asserted, the PIC microcontroller finishes the current
instruction, stores the next address on the CALL stack then jumps to the Interrupt Ser-
vice Routine (ISR). It also clears the GIE bit, preventing another interrupt from occur-
ring while servicing the current one.
Save Current Context
The first thing the ISR must do is to save the current context of the processor so it can
be restored before returning to the main program. Certain SFRs that may be changed
in the ISR should be saved, such as the WREG and STATUS registers at the very least.
Make sure to save the WREG first, as moving other SFRs into it will destroy the value
needing to be saved. The last 16 bytes of each PIC16F887 file register page are
unbanked and are good places to save the context, as they may be accessed from any
register page without regard to the RP0 and RP1 bits in the STATUS register. The
location of unbanked registers may vary from part to part. Check the register map to
find the unbanked region for a specific part.
Identify Triggering Event
Next, the ISR has to figure out what triggered the interrupt. It has to check the interrupt
flags to determine what caused the interrupt. When it finds the source, it can then
service the peripheral.
Restore Context
Once the peripheral is serviced, it needs to restore the context and resume the main
program. The “context” is the state of the SFRs when the interrupt occurred. Restoring
the context is a little harder than it might seem at first. The obvious method doesn’t work
because the MOVF W_Temp,w may affect the Z flag, which was restored in the previ-
ous instruction. Instead, a pair of SWAPF instructions can restore WREG without affect-
ing the flags in the STATUS register. SWAPF exchanges the high and low nibbles. The
first SWAPF switches the nibbles in the file register and the second one switches them
back and puts the result in WREG.
EXAMPLE 3-9:
CONTEXT RESTORE
;incorrect context restore
MOVF STATUS_Temp,w
MOVWF STATUS
MOVF W_Temp ;this may change the Z bit
;in the Status register
;good
MOVF
MOVWF
context restore
STATUS_Temp,w
STATUS
SWAPF
SWAPF
W_Temp,f
W_Temp,w
;swap in place
;swap with Wreg destination
Finally, RETFIE transfers control back to the original program and sets the GIE bit,
re-enabling interrupts.
? 2007 Microchip Technology Inc.
DS41296B-page 29
相关PDF资料
DM240011 KIT STARTER MPLAB FOR PIC24F MCU
DM240021 KIT STARTER MPLAB FOR PIC24H
DM240311 BOARD DEV PIC24F16KA102 XLP
DM300018 BOARD DEMO DSPICDEM 2
DM300019 BOARD DEMO DSPICDEM 80L STARTER
DM300024 KIT DEMO DSPICDEM 1.1
DM330012 KIT USB STARTER FOR DSPIC33E
DM330013 MICROSTICK DSPIC33F/PIC24H BOARD
相关代理商/技术参数
DM240002 制造商:Microchip Technology Inc 功能描述:Explorer 16 kit(44-PIN) w/ PIC24FJ64GA00
DM240011 功能描述:开发板和工具包 - PIC / DSPIC MPLAB Starter Kit for PIC24F MCU RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM240012 功能描述:开发板和工具包 - PIC / DSPIC PIC24E USB Starter Kit RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM240013-1 功能描述:开发板和工具包 - PIC / DSPIC Microstick for 3V PIC24F K-series RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM240013-2 功能描述:开发板和工具包 - PIC / DSPIC RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM240014 制造商:Microchip Technology Inc 功能描述:MICROSTICK FOR USB PIC24F - Boxed Product (Development Kits) 制造商:Microchip Technology Inc 功能描述:ACCY MICROSTICK USB PIC24F 制造商:Microchip Technology Inc 功能描述:MICROSTICK USB PIC24F
DM240015 制造商:Microchip Technology Inc 功能描述:MPLAB STARTER KIT FOR PIC24F INTELLIGENT INTEGRATED ANALOG - Boxed Product (Development Kits) 制造商:Microchip Technology Inc 功能描述:KIT MPLAB STARTER FOR PIC24F ANL 制造商:Microchip Technology Inc 功能描述:PIC24F GC INTELLIGENT ANALOG DEV KIT 制造商:Microchip Technology Inc 功能描述:PIC24F, GC INTELLIGENT ANALOG, DEV KIT 制造商:Microchip Technology Inc 功能描述:Starter Kit for PIC24F Intelligent Integrated Analog Series 制造商:Microchip Technology Inc 功能描述:Development Boards & Kits - PIC / DSPIC 制造商:Microchip Technology Inc 功能描述:PIC24F, GC INTELLIGENT ANALOG, DEV KIT, Silicon Manufacturer:Microchip, Core Arc 制造商:Microchip Technology Inc 功能描述:PIC24F, GC INTELLIGENT ANALOG, DEV KIT, Silicon Manufacturer:Microchip, Core Architecture:PIC, Core Sub-Architecture:PIC24, Silicon Core Number:PIC24FJ128GC010, Silicon Family Name:PIC24FJxxxGCxxx, Kit Contents:Starter Board 制造商:Microchip Technology Inc 功能描述:MPLAB Starter Kit for PIC24F Intelligent Integrated Analog, Starter Kits
DM240021 功能描述:开发板和工具包 - PIC / DSPIC MPLAB STARTER KIT FOR PIC24H RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压: