diff --git a/recipes/rc2014/ps2/ps2ctl.asm b/recipes/rc2014/ps2/ps2ctl.asm index fb869aa..f4bad78 100644 --- a/recipes/rc2014/ps2/ps2ctl.asm +++ b/recipes/rc2014/ps2/ps2ctl.asm @@ -75,6 +75,7 @@ ; - 2: awaiting parity bit ; - 3: awaiting stop bit ; it reaches 11, we know we're finished with the frame. +; R19: Register used for parity computations ; R20: data being sent to the 595 ; Y: pointer to the memory location where the next scan code from ps/2 will be ; written. @@ -88,6 +89,9 @@ .equ CE = PINB4 .equ RCLK = PINB0 +; init value for TCNT0 so that overflow occurs in 100us +.equ TIMER_INITVAL = 0x100-100 + rjmp main rjmp hdlINT0 rjmp hdlPCINT @@ -145,6 +149,13 @@ main: clr ZH ldi ZL, low(SRAM_START) + ; Setup timer. We use the timer to clear up "processbit" registers after + ; 100us without a clock. This allows us to start the next frame in a + ; fresh state. at 8MHZ, setting the counter's prescaler to 8 gives us + ; a nice 1us for each TCNT0. + ldi r16, (1< r16 + cp r1, r16 + ; TODO: implement "resend requests" on parity check failure + brne processbitReset ; r1 != r16? wrong parity inc r18 rjmp loop +processbitReset: + clr r18 + ldi r16, TIMER_INITVAL + out TCNT0, r16 + ldi r16, (1<