#picaxe 08m2
;
; SFRs
;
;To convert to Picaxe equivalent, we do the following:-
;
; 3 9 1 Example 'RAW PIC' value
;0011 1001 0001
;xx| |xx| ||||
; \ / / ||||
; | | | ||||
; v v v vvvv
; 11 1 1 0001
; F 1 Translated Picaxe value
;
;Interrupt On Change SFRs
Symbol IOCAP = $F1 ;$391 - Capture positive edges
Symbol IOCAN = $F2 ;$392 - Capture negative edges
Symbol IOCAF = $F3 ;$393 - Capture flag
;
; START PROGRAM
;
Pullup %00010010 ;Pullup C.4 (switch to gnd) and C.1 (serin)
gosub EnableInterrupts ;like it says. Interrupt when switch pressed.
PokeSfr IOCAN,%00010000 ;capture negative-going transitions on C.4
PokeSfr IOCAF,0 ;say none captured so far
do
;
; Main loop.
;
sertxd ("R")
serin 5000,TimeOut,C.1, T4800_4,b0 ;read a single byte into b0 with 5 second timeout
sertxd ("C") ;Read a character via SERIN
goto skip
Timeout:
sertxd ("T")
skip:
PeekSfr IOCAF, b1 ;get pin no.s that have edge detections
if b1 <> 0 then
;
; -ve going edge detection (can only be C.4 - not enabled for other pins)
;
sertxd(cr,lf,"EDGE",cr,lf)
PokeSfr IOCAF, 0 ;reset Switch detections
endif
loop
Interrupt:
;
; C.4 has gone LOW - switch pressed
;
sertxd (cr,lf,"INTERRUPT!",cr,lf)
;
; Re-enable interrupt for next time
;
EnableInterrupts:
do : loop while PinC.4 = 0 ;;;Wait for Switch to be released
setint %00000000,%00010000 ;;;(re)enable interrupt on PinC.4 LOW
return