Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
interrupts,
counters and timers
Chapter Six
INTCON:
SFR 0Bh
Dr. Gheith Abandah 5
PIC Response to an Interrupt
movf plo,0
addwf qlo,0 ;What happens on an interrupt here?
movwf rlo
btfsc status,0
Int_Routine
bcf status,0 ;clear the Carry flag
movlw 0ff ;change W reg value
bcf intcon,intf
retfie
end
Dr. Gheith Abandah 11
Solution: Context Saving
PUSH movwf w_temp ;Copy W to W_TEMP register
swapf status,0 ;Swap status into W
movwf status_temp ;Save status
...
Actual ISR goes here
...
POP swapf status_temp,0 ;Swap nibbles into W
movwf status ;Move W into STATUS register
swapf w_temp,1 ;Swap nibbles in W_TEMP
swapf w_temp,0 ;Swap nibbles in W_TEMP into W
Clear interrupt flag(s) here
retfie
Dr. Gheith Abandah 12
Critical Regions
In critical regions, we cannot allow
the intrusion of an interrupt.
Critical regions generally include all
time-sensitive activity and any
calculation where the ISR makes use of
the result.
Disable, or mask, the interrupts for
their duration, by manipulating the
enable bits in the INTCON register.
Dr. Gheith Abandah 13
Counters and Timers
A digital counter is
usually made of flip
flops and counts up
or down.
When the
triggering event is
a constant
frequency clock,
we get a timer.
Use polling or
interrupts