PIC Part5 Interrupts
PIC Part5 Interrupts
Programming
Interrupt I/O
Input status
Poll and Wait
Until Device Ready
…
Program Execution
.
. ISR
Start Device Procedure
. For device
Service
. Routine
. .
. RETURN
Compare/Capture/PWM-1 interrupt
Timer2 interrupt
Timer1 interrupt
EEPROM interrupt
Bus Collision(I2C) interrupt
Compare/Capture/PWM-2 interrupt
CpE 112 : Klinkhachorn
16F87X Interrupt Logic
Mainline ….
….
;initialize any required registers and variables
;Enable any required interrupt mask, e.g. INTE.
;
IntService
;Polling interrupt flag and goto specific interrupt handler routines
;do what it need to be done
.
;on exit
; ON exit restore PCLATH, STATUS and W
swapf PCLATH_Te mp, W ;Restore PCLATH
m ovwf PCLATH ;Move W into PCLATH
swapf Status_Te mp,W ;Swap Status_Te mp register into W
;(sets data me mory bank to original state)
IntService
;Polling routine
btfsc Register_Nam e,Flag_bit;Arrange from the
;highest priority
;interrupt source
goto Interrupt_A ;if set, do it!
btfsc ... ;check next highest
;priority…
goto ... ;if set, go for it
.
.
;repeat until get to the lowest interrupt source
Done
;restore the necessary registers
#INT_xxx Na me()
{
; your codes
}
CCS support the following:
INT_EXT (External Interrupt)
INT_RTCC (Timer0 [RTCC] overflow)
INT_RB (Change on B4-B7 PIN)
INT_AD (A/D Converter)
INT_TIMER1 (Timer1 overflow)
INT_TIMER2 (Timer2 overflow)
INT_SSP (S mart Serial Port (SPI,I2C))
INT_PSP (Parallel Slave Port)
...
DISABLE_INTERRUPTS(XXX)
W here XXX is
Global (GIE)
INT_EXT (External Interrupt)
INT_RTCC (Timer0 [RTCC] overflow)
INT_RB (Change on B4-B7 PIN)
INT_AD (A/D Converter)
INT_TIMER1 (Timer1 overflow)
INT_TIMER2 (Timer2 overflow)
INT_SSP (S mart Serial Port (SPI,I2C))
INT_PSP (Parallel Slave Port)
…
Exa mple: disable_interrupts(global);
ENABLE_INTERR UPTS(XXX)
W here XXX is
Global (GIE)
INT_EXT (External Interrupt)
INT_RTCC (Timer0 [RTCC] overflow)
INT_RB (Change on B4-B7 PIN)
INT_AD (A/D Converter)
INT_TIMER1 (Timer1 overflow)
INT_TIMER2 (Timer2 overflow)
INT_SSP (S mart Serial Port (SPI,I2C))
INT_PSP (Parallel Slave Port)
…
Exa mple: enable_interrupts(global);
EXT_INT_EDGE(edge)
W here edge is
L_to_H
H_to_L
One cycle
ON/OFF
determines CCW/CW
CpE 112 : Klinkhachorn
INT_EXT Interrupt : Example
Main Program
.
. . .
enable_interrupts(int_EXT);
enable_interrupts(global);
. . .
PIC16F877
✔ PIC16F877
–Timer0
–Timer1
–Timer2
✔ Run on internal RC
– If enable during SLEEP mode, WDT will
continue running and will be able to wake up
the processor on Time-out!
✔ With Prescaler (Post) set to 1:128, typical
maximum delay time can be approximately
18*128 ms or over 2 seconds!