Net result: we have two eight-bit numbers representing the two axes of the joystick. The ISR about sixty words long.
1/2 of actual code from ISR, with comments:
btfss pir1, ccp1if ; CCP1? goto isr_check_ccp2 btfss ccp1con, ccp1m0 goto isr_ccp1_falling movf ccpr1l, w movwf ccp1_rise_l movf ccpr1h, w movwf ccp1_rise_h bcf ccp1con, ccp1m0 ; now waiting for falling edge bcf pir1, ccp1if ; Clear interrupt flag goto isr_check_ccp2 isr_ccp1_falling: ; CCP1CON has CCP1M0 == 0, we're waiting for falling edge movf ccp1_rise_l, w subwf ccpr1l, f movf ccp1_rise_h, w btfss status, c incfsz ccp1_rise_h, w subwf ccpr1h, f ; ccpr1h/l now has the delta. TMR1 is 8:1 scaled ; on our 1uS instruction cycle, so 1mS is about ; 0x7d and 2mS is about 0xfa. ; We will subtract 0x60 from this to give ; a range of 0x1d - 0x9a for joystick_x ; we then shift right (divide by two) for a final range of ; 0x0e..0x4d (14..77). movlw 0x60 subwf ccpr1l, w ; ccpr1l = ccpr1l-0x60 movwf joystick_x bcf status, c rrf joystick_x, f bsf isr_status, isr_got_x bsf ccp1con, ccp1m0 ; now waiting for rising edge bcf pir1, ccp1if ; Clear interrupt flag ; fall through so we check the other ccp
|Previous: PIC intro||Next: Wheel speeds|