[Flashforth-devel] interrupt on input change - one solution
Brought to you by:
oh2aun
From: Bob E. <bob...@ti...> - 2013-02-04 19:22:25
|
Hi Folks, Having asked about an interrupt driven shaft encoder I had a go at programming with success on a PIC18F4450. This is my solution: - \ interrupt driven shaft encoder connected to portb bits 6 and 7 \ free to use at your own risk - Bob Edwards G4BBY rbie intcon mclr false di is irq ei -knob marker -knob $fff2 con intcon $ff81 con portb $ff93 con trisb $1 con rbif $8 con rbie ram variable knobcount ram variable oldportb ram variable oldticks : knob_int ( -- ) [i rbif intcon mtst if rbif intcon mclr oldportb @ portb c@ $c0 and dup oldportb ! 2dup <> if 2/ xor $40 and if 1 else -1 then knobcount +! else 2drop then then i] ;i : knobgo ( -- ) \ install knob interrupt $c0 trisb mset ['] knob_int is irq rbie intcon mset ; : readknob ( -- n1 n2) \ n2 knob counts recieved in the last n1 milliseconds di ticks oldticks 2dup @ - dup ?negate >r ! r> knobcount @ 0 knobcount ! ei ; : knobstop ( -- ) \ remove knob interrupt rbie intcon mclr false di is irq ei ; Cheers, Bob |