diff options
author | Leonard Kugis <leonard@kug.is> | 2020-09-05 03:20:15 +0200 |
---|---|---|
committer | Leonard Kugis <leonard@kug.is> | 2020-09-05 03:20:15 +0200 |
commit | a5092bd72c3b478cbe4845bf1b178f3be991af5d (patch) | |
tree | 8e2a589aab284f661aab4eb1cdf93daca7768a14 /Software/pinlock.asm | |
parent | 83ffa2768754fd9f5bc3368a2aeb2f0a63a623fd (diff) |
Software
General mechanism working.
Needs refinement with EEPROM store/load.
Diffstat (limited to 'Software/pinlock.asm')
-rw-r--r-- | Software/pinlock.asm | 212 |
1 files changed, 185 insertions, 27 deletions
diff --git a/Software/pinlock.asm b/Software/pinlock.asm index 98cd0d3..cda4110 100644 --- a/Software/pinlock.asm +++ b/Software/pinlock.asm @@ -15,10 +15,12 @@ .def dig1 = r29 init: + ; Initialize stack pointer ldi tmp0, HIGH(RAMEND) out SPH, tmp0 ldi tmp0, LOW(RAMEND) out SPL, tmp0 + ; Set data directions and default outputs for ports ldi tmp0, 0b11111111 out DDRA, tmp0 ldi tmp0, 0b11111111 @@ -32,6 +34,7 @@ init: sbi DDRC, 6 ldi tmp0, 0b00000100 out PORTD, tmp0 + ; Display all zeros on displays ldi par0, 0 ldi par1, 0 rcall display @@ -44,11 +47,38 @@ init: ldi par0, 3 ldi par1, 0 rcall display + + ;ldi par0, 0 + ;ldi par1, 0 + ;ldi par2, 0x01 + ;rcall eeprom_write + ;ldi par0, 1 + ;ldi par2, 0x23 + ;rcall eeprom_write + ;ldi par0, 3 + ;ldi par1, 1 + ;rcall display +;stop: + ;rjmp stop + + rcall write_code + ; Load code from EEPROM + rcall load_code + + ;lds par1, 1 + ;ldi par0, 0 + ;rcall display +;stop: + ;rjmp stop + + ; Grab input once and but it on the stack + ; For delta bitvector rcall input push ret1 push ret2 + ; Initialize registers and stack top ldi heart, 0 ldi dig0, 0x10 ldi dig1, 0 @@ -128,6 +158,44 @@ wait_loop: pop tmp0 ret +write_code: + push par0 + push par1 + push par2 + ldi par0, 0 + ldi par1, 0 + ldi par2, 0x01 + rcall eeprom_write + ldi par0, 1 + ldi par2, 0x23 + rcall eeprom_write + pop par2 + pop par1 + pop par0 + ret + +; Load code from EEPROM and store in memory +; Parameters: +; None +; Returns: +; ret0 = Code digits 0-1 +; ret1 = Code digits 2-3 +load_code: + push par0 + push par1 + ; Digits 0-1 + ldi par0, 0 + ldi par1, 0 + rcall eeprom_read + sts 0, ret0 + ; Digits 2-3 + ldi par0, 1 + rcall eeprom_read + sts 1, ret0 + pop par1 + pop par0 + ret + ; Output bits to shift register. ; Parameters: ; par0 = Bits @@ -185,6 +253,36 @@ shift_in_loop: pop tmp0 ret +; Write to EEPROM +; Parameters: +; par0:par1 = Address +; par2 = Value +; Returns: +; None +eeprom_write: + sbic EECR, EEWE + rjmp eeprom_write + out EEARL, par0 + out EEARH, par1 + out EEDR, par2 + sbi EECR, EEMWE + sbi EECR, EEWE + ret + +; Read from EEPROM +; Parameters: +; par0:par1 = Address +; Returns: +; ret0 = Value +eeprom_read: + sbic EECR, EEWE + rjmp eeprom_read + out EEARL, par0 + out EEARH, par1 + sbi EECR, EERE + in ret0, EEDR + ret + ; Output the status ; Parameters: ; par0 = Status bits @@ -595,25 +693,21 @@ translate_map: ; Returns: ; ret0 = new state ; Descriptions: -; state = 0bCSSS00DD +; state = 0bCSSSSSDD ; C = Blinky clock ; S = State information ; 0 = reserved ; D = Current display -.equ HANDLE_STATE_AUTH = 0 -.equ HANDLE_STATE_SUCCESS = 1 -.equ HANDLE_STATE_FAILED = 2 -.equ HANDLE_STATE_CHANGE = 3 -.equ HANDLE_STATE_CHANGED = 4 -.equ HANDLE_STATE_LOGOUT = 5 +.equ HANDLE_STATE_MASK = 0b01111100 +.equ HANDLE_STATE_AUTH = (0 << 2) +.equ HANDLE_STATE_AUTHED = (1 << 2) +.equ HANDLE_STATE_CHANGE = (2 << 2) handle: push tmp0 push tmp1 mov ret0, par0 mov tmp0, par0 - andi tmp0, 0b01110000 - lsr tmp0 - lsr tmp0 + andi tmp0, HANDLE_STATE_MASK lsr tmp0 lsr tmp0 ldi ZL, LOW(handle_map) @@ -624,11 +718,8 @@ handle: ijmp handle_map: rjmp handle_auth - rjmp handle_success - rjmp handle_failed + rjmp handle_authed rjmp handle_change - rjmp handle_changed - rjmp handle_logout handle_blink: sbrs par0, 7 rjmp handle_blink_low @@ -657,34 +748,101 @@ handle_blink_high: andi ret0, 0b01111111 ret handle_auth: - push tmp0 rcall handle_blink - mov tmp0, par1 - cpi tmp0, 0xF0 + cpi par1, 0xF0 breq handle_auth_no_press + cpi par1, 0x0A + breq handle_auth_submit push par0 andi par0, 0b00000011 rcall set_digit rcall display + inc par0 + sbrc par0, 2 + andi par0, 0b00000011 + andi ret0, 0b11111100 + or ret0, par0 pop par0 - inc ret0 - sbrc ret0, 2 - andi ret2, 0b11111000 - pop tmp0 rjmp handle_end handle_auth_no_press: + rjmp handle_end +handle_auth_submit: + push par0 + push ret0 + push tmp0 + push tmp1 + push tmp2 + lds tmp0, 0 + lds tmp1, 1 + ; Compare digit 0 + mov tmp2, tmp0 + lsr tmp2 + lsr tmp2 + lsr tmp2 + lsr tmp2 + ldi par0, 0 + rcall get_digit + cp tmp2, ret0 + brne handle_compare_end + ; Compare digit 1 + mov tmp2, tmp0 + andi tmp2, 0x0F + ldi par0, 1 + rcall get_digit + cp tmp2, ret0 + brne handle_compare_end + ; Compare digit 2 + mov tmp2, tmp1 + lsr tmp2 + lsr tmp2 + lsr tmp2 + lsr tmp2 + ldi par0, 2 + rcall get_digit + cp tmp2, ret0 + brne handle_compare_end + ; Compare digit 3 + mov tmp2, tmp1 + andi tmp2, 0x0F + ldi par0, 3 + rcall get_digit + cp tmp2, ret0 + brne handle_compare_end + ; All digits match + pop tmp2 + pop tmp1 pop tmp0 + pop ret0 + pop par0 + andi ret0, HANDLE_STATE_MASK + ori ret0, HANDLE_STATE_AUTHED rjmp handle_end -handle_success: +handle_compare_end: + pop tmp2 + pop tmp1 + pop tmp0 + pop par0 rjmp handle_end -handle_failed: +handle_authed: + push par0 + push par1 + ldi par0, 0 + ldi par1, 1 + rcall display + ldi par0, 1 + ldi par1, 3 + rcall display + ldi par0, 2 + ldi par1, 3 + rcall display + ldi par0, 3 + ldi par1, 7 + rcall display + pop par1 + pop par0 rjmp handle_end handle_change: rjmp handle_end -handle_changed: - rjmp handle_end -handle_logout: - rjmp handle_end handle_end: pop tmp1 pop tmp0 |