diff options
Diffstat (limited to 'Software')
-rw-r--r-- | Software/pinlock.asm | 367 |
1 files changed, 281 insertions, 86 deletions
diff --git a/Software/pinlock.asm b/Software/pinlock.asm index 87ce7c4..98cd0d3 100644 --- a/Software/pinlock.asm +++ b/Software/pinlock.asm @@ -11,6 +11,8 @@ .def par4 = r25 .def ret2 = r26 .def heart = r27 +.def dig0 = r28 +.def dig1 = r29 init: ldi tmp0, HIGH(RAMEND) @@ -28,26 +30,32 @@ init: sbi DDRC, 0 sbi DDRC, 1 sbi DDRC, 6 - ldi tmp0, 0b00000000 + ldi tmp0, 0b00000100 out PORTD, tmp0 - ldi heart, 0 ldi par0, 0 ldi par1, 0 rcall display ldi par0, 1 - ldi par1, 1 + ldi par1, 0 rcall display ldi par0, 2 - ldi par1, 2 + ldi par1, 0 rcall display ldi par0, 3 - ldi par1, 3 + ldi par1, 0 rcall display + rcall input + push ret1 + push ret2 + + ldi heart, 0 + ldi dig0, 0x10 + ldi dig1, 0 ldi tmp0, 0 - ldi tmp1, 0 + ldi tmp2, 0 + push tmp0 push tmp0 - push tmp1 rjmp main @@ -61,9 +69,9 @@ debug_heart: rcall display mov par0, heart rcall status - ldi par0, 0xFF - ldi par1, 1 - ldi par2, 1 + ldi par0, 1 + ldi par1, 0xFF + ldi par2, 0xFF rcall wait pop par2 pop par1 @@ -71,6 +79,11 @@ debug_heart: ret main: + ldi par0, 1 + ldi par1, 0xFF + ldi par2, 0xFF + rcall wait + ;rcall debug_heart ; get current button states rcall input ; detect raising edge on one of the buttons @@ -82,30 +95,26 @@ main: 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 + mov par0, tmp2 mov par1, ret0 - rcall display - ;mov par0, ret0 - ;rcall handle + rcall handle + mov tmp2, ret0 rjmp main wait: push tmp0 push tmp1 + push tmp2 mov tmp0, par0 mov tmp1, par1 + mov tmp2, par2 wait_loop: - dec tmp0 nop + dec tmp0 brne wait_loop mov tmp0, par0 dec tmp1 @@ -114,6 +123,7 @@ wait_loop: mov tmp1, par1 dec tmp2 brne wait_loop + pop tmp2 pop tmp1 pop tmp0 ret @@ -220,55 +230,145 @@ status_clk: ; Returns: ; None display: + push par1 push tmp0 - push tmp1 - mov tmp0, par1 - andi tmp0, 0x0F - cpi par0, 0 - breq display_0 - cpi par0, 1 - breq display_1 - cpi par0, 2 - breq display_2 - cpi par0, 3 - breq display_3 - rjmp display_end + andi par1, 0x0F + ldi ZL, LOW(display_map) + ldi ZH, HIGH(display_map) + ldi tmp0, 0 + add ZL, par0 + adc ZH, tmp0 + icall + pop tmp0 + pop par1 + ret +display_map: + rjmp display_0 + rjmp display_1 + rjmp display_2 + rjmp display_3 display_0: - in tmp1, PORTA - andi tmp1, 0xF0 - or tmp1, tmp0 - out PORTA, tmp1 - rjmp display_end + in tmp0, PORTA + andi tmp0, 0xF0 + or tmp0, par1 + out PORTA, tmp0 + ret display_1: - in tmp1, PORTB - andi tmp1, 0xF0 - or tmp1, tmp0 - out PORTB, tmp1 - rjmp display_end + in tmp0, PORTB + andi tmp0, 0xF0 + or tmp0, par1 + out PORTB, tmp0 + ret display_2: - in tmp1, PORTA - andi tmp1, 0x0F - lsl tmp0 - lsl tmp0 - lsl tmp0 - lsl tmp0 - or tmp1, tmp0 - out PORTA, tmp1 - rjmp display_end + in tmp0, PORTA + andi tmp0, 0x0F + lsl par1 + lsl par1 + lsl par1 + lsl par1 + or tmp0, par1 + out PORTA, tmp0 + ret display_3: - in tmp1, PORTB - andi tmp1, 0x0F - lsl tmp0 - lsl tmp0 - lsl tmp0 - lsl tmp0 - or tmp1, tmp0 - out PORTB, tmp1 - rjmp display_end -display_end: - pop tmp1 + in tmp0, PORTB + andi tmp0, 0x0F + lsl par1 + lsl par1 + lsl par1 + lsl par1 + or tmp0, par1 + out PORTB, tmp0 + ret + +; Sets the corresponding digit number. +; Parameters: +; par0 = Digit number (0-3) +; par1 = Digit (0x00-0x0F) +set_digit: + push tmp0 + push par1 + andi par1, 0x0F + ldi tmp0, 0 + ldi ZL, LOW(set_digit_n) + ldi ZH, HIGH(set_digit_n) + add ZL, par0 + adc ZH, tmp0 + icall + pop par1 pop tmp0 ret +set_digit_n: + rjmp set_digit_0 + rjmp set_digit_1 + rjmp set_digit_2 + rjmp set_digit_3 +set_digit_0: + lsl par1 + lsl par1 + lsl par1 + lsl par1 + andi dig0, 0x0F + or dig0, par1 + ret +set_digit_1: + andi dig0, 0xF0 + or dig0, par1 + ret +set_digit_2: + lsl par1 + lsl par1 + lsl par1 + lsl par1 + andi dig1, 0x0F + or dig1, par1 + ret +set_digit_3: + andi dig1, 0xF0 + or dig1, par1 + ret + +; Gets the corresponding digit number. +; Parameters: +; par0 = Digit number (0-3) +; Returns: +; ret0 = Digit +get_digit: + push tmp0 + ldi tmp0, 0 + ldi ZL, LOW(get_digit_n) + ldi ZH, HIGH(get_digit_n) + add ZL, par0 + adc ZH, tmp0 + icall + pop tmp0 + ret +get_digit_n: + rjmp get_digit_0 + rjmp get_digit_1 + rjmp get_digit_2 + rjmp get_digit_3 +get_digit_0: + mov ret0, dig0 + lsr ret0 + lsr ret0 + lsr ret0 + lsr ret0 + ret +get_digit_1: + mov ret0, dig0 + andi ret0, 0x0F + ret +get_digit_2: + mov ret0, dig1 + lsr ret0 + lsr ret0 + lsr ret0 + lsr ret0 + ret +get_digit_3: + mov ret0, dig1 + andi ret0, 0x0F + ret ; Read the input buttons. ; Parameters: @@ -310,15 +410,14 @@ input_read: ldi par1, 1 ldi par2, 1 rcall wait - pop par2 - pop par1 - pop par0 ; load - sbi PORTD, 2 cbi PORTD, 2 - push par0 - push par1 - push par2 + ldi par0, 1 + ldi par1, 1 + ldi par2, 1 + rcall wait + rcall input_read_clk + sbi PORTD, 2 ldi par0, 1 ldi par1, 1 ldi par2, 1 @@ -326,8 +425,6 @@ input_read: pop par2 pop par1 pop par0 - rcall input_read_clk - sbi PORTD, 2 ; shift in push par0 ldi par0, HIGH(input_read_clk) @@ -361,12 +458,12 @@ input_write_clk: ldi par0, 1 ldi par1, 1 ldi par2, 1 - ;rcall wait + rcall wait sbi PORTC, 1 ldi par0, 1 ldi par1, 1 ldi par2, 1 - ;rcall wait + rcall wait pop par2 pop par1 pop par0 @@ -379,12 +476,12 @@ input_read_clk: ldi par0, 1 ldi par1, 1 ldi par2, 1 - ;rcall wait + rcall wait sbi PORTD, 5 ldi par0, 1 ldi par1, 1 ldi par2, 1 - ;rcall wait + rcall wait pop par2 pop par1 pop par0 @@ -444,7 +541,17 @@ translate_loop: rjmp translate_low rjmp translate_high translate_low: - rjmp translate_end + lsr par0 + lsr par1 + brcc pc+2 + ori par0, 0x80 + dec tmp0 + brne translate_loop + ldi ret0, 0xF0 + pop tmp0 + pop par1 + pop par0 + ret translate_high: push tmp0 push tmp1 @@ -457,14 +564,6 @@ translate_high: 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 @@ -491,6 +590,102 @@ translate_map: ; Handles the given key input. ; Parameters: -; par0 = keycode +; par0 = state +; par1 = keycode ; Returns: -; +; ret0 = new state +; Descriptions: +; state = 0bCSSS00DD +; 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 +handle: + push tmp0 + push tmp1 + mov ret0, par0 + mov tmp0, par0 + andi tmp0, 0b01110000 + lsr tmp0 + lsr tmp0 + lsr tmp0 + lsr tmp0 + ldi ZL, LOW(handle_map) + ldi ZH, HIGH(handle_map) + ldi tmp1, 0 + add ZL, tmp0 + adc ZH, tmp1 + ijmp +handle_map: + rjmp handle_auth + rjmp handle_success + rjmp handle_failed + rjmp handle_change + rjmp handle_changed + rjmp handle_logout +handle_blink: + sbrs par0, 7 + rjmp handle_blink_low + rjmp handle_blink_high +handle_blink_low: + push par0 + push par1 + andi par0, 0b00000011 + ldi par1, 0x0F + rcall display + pop par1 + pop par0 + ori ret0, 0b10000000 + ret +handle_blink_high: + push par0 + push par1 + push ret0 + andi par0, 0b00000011 + rcall get_digit + mov par1, ret0 + rcall display + pop ret0 + pop par1 + pop par0 + andi ret0, 0b01111111 + ret +handle_auth: + push tmp0 + rcall handle_blink + mov tmp0, par1 + cpi tmp0, 0xF0 + breq handle_auth_no_press + push par0 + andi par0, 0b00000011 + rcall set_digit + rcall display + pop par0 + inc ret0 + sbrc ret0, 2 + andi ret2, 0b11111000 + pop tmp0 + rjmp handle_end +handle_auth_no_press: + pop tmp0 + rjmp handle_end +handle_success: + rjmp handle_end +handle_failed: + rjmp handle_end +handle_change: + rjmp handle_end +handle_changed: + rjmp handle_end +handle_logout: + rjmp handle_end +handle_end: + pop tmp1 + pop tmp0 + ret |