diff options
author | Leonard Kugis <leonard@kug.is> | 2020-09-03 23:14:50 +0200 |
---|---|---|
committer | Leonard Kugis <leonard@kug.is> | 2020-09-03 23:14:50 +0200 |
commit | 08f625ba7e355f6c37a35af5aeafcaadca866d38 (patch) | |
tree | 0f24a4a5455768d4635f4031a39bec0f53a1ad8a /Software/pinlock.asm | |
parent | c47dd91780b474f2166a5edc21666445d7fd6405 (diff) |
Input
Moved old state to test.
Diffstat (limited to 'Software/pinlock.asm')
-rw-r--r-- | Software/pinlock.asm | 118 |
1 files changed, 96 insertions, 22 deletions
diff --git a/Software/pinlock.asm b/Software/pinlock.asm index b088dab..87ce7c4 100644 --- a/Software/pinlock.asm +++ b/Software/pinlock.asm @@ -43,6 +43,12 @@ init: ldi par0, 3 ldi par1, 3 rcall display + + ldi tmp0, 0 + ldi tmp1, 0 + push tmp0 + push tmp1 + rjmp main debug_heart: @@ -65,30 +71,31 @@ debug_heart: ret main: + ; get current button states rcall input - mov par1, ret0 - lsr par1 - lsr par1 - lsr par1 - lsr par1 + ; detect raising edge on one of the buttons + pop tmp0 + pop tmp1 + push ret1 + push ret0 + eor tmp0, ret0 + eor tmp1, ret1 + and tmp0, ret0 + and tmp1, ret1 + ; check if no button has pressed + ldi tmp2, 0 + or tmp2, tmp0 + or tmp2, tmp1 + breq main + ; button pressed, process + mov par0, tmp0 + mov par1, tmp1 + rcall translate ldi par0, 0 - rcall display mov par1, ret0 - andi par1, 0x0F - ldi par0, 1 - rcall display - mov par1, ret1 - lsr par1 - lsr par1 - lsr par1 - lsr par1 - ldi par0, 2 - rcall display - mov par1, ret1 - andi par1, 0x0F - ldi par0, 3 rcall display - ;rcall debug_heart + ;mov par0, ret0 + ;rcall handle rjmp main wait: @@ -267,8 +274,8 @@ display_end: ; Parameters: ; None ; Returns: -; ret0 = 123A456B -; ret1 = 789C*0#D +; ret0 = 0852*741 +; ret1 = DCBA#963 input: ; Write selection rows ldi par0, 1 @@ -420,3 +427,70 @@ input_end: ret input_loop_j: rjmp input_loop + +; Translate input bits to keycode. +; Parameters: +; par0 = Input bits 7..0 +; par1 = Input bits 15..8 +; Returns: +; ret0 = Translated keycode +translate: + push par0 + push par1 + push tmp0 + ldi tmp0, 16 +translate_loop: + sbrs par0, 0 + rjmp translate_low + rjmp translate_high +translate_low: + rjmp translate_end +translate_high: + push tmp0 + push tmp1 + ldi ZL, LOW(translate_map << 1) + ldi ZH, HIGH(translate_map << 1) + dec tmp0 + ldi tmp1, 0 + add ZL, tmp0 + adc ZH, tmp1 + lpm ret0, Z + pop tmp1 + pop tmp0 + rjmp translate_end +translate_end: + lsr par0 + lsr par1 + brcc pc+2 + ori par0, 0x80 + dec tmp0 + brne translate_loop + pop tmp0 + pop par1 + pop par0 + ret +translate_map: + .db 0x0D, \ + 0x0C, \ + 0x0B, \ + 0x0A, \ + 0x0F, \ + 9, \ + 6, \ + 3, \ + 0, \ + 8, \ + 5, \ + 2, \ + 0x0E, \ + 7, \ + 4, \ + 1 +; ret0 = 0852*741 +; ret1 = DCBA#963 + +; Handles the given key input. +; Parameters: +; par0 = keycode +; Returns: +; |