summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2020-09-08 15:42:03 +0200
committerLeonard Kugis <leonard@kug.is>2020-09-08 15:42:03 +0200
commit9a4fce2bab1a0754eda3a9514a44519abe148e86 (patch)
treeea6591c9fbbb51cc48359488d1178ca6956f2aba
parenta5092bd72c3b478cbe4845bf1b178f3be991af5d (diff)
EEPROM
State machine finished. EEPROM io working.
-rw-r--r--Software/pinlock.asm186
1 files changed, 158 insertions, 28 deletions
diff --git a/Software/pinlock.asm b/Software/pinlock.asm
index cda4110..12c17d9 100644
--- a/Software/pinlock.asm
+++ b/Software/pinlock.asm
@@ -61,7 +61,7 @@ init:
;stop:
;rjmp stop
- rcall write_code
+ ;rcall write_code
; Load code from EEPROM
rcall load_code
@@ -110,7 +110,7 @@ debug_heart:
main:
ldi par0, 1
- ldi par1, 0xFF
+ ldi par1, 0x30
ldi par2, 0xFF
rcall wait
;rcall debug_heart
@@ -181,6 +181,11 @@ write_code:
; ret0 = Code digits 0-1
; ret1 = Code digits 2-3
load_code:
+ ldi ret0, 0x01
+ ldi ret1, 0x23
+ sts 0, ret0
+ sts 1, ret1
+ ret
push par0
push par1
; Digits 0-1
@@ -495,19 +500,19 @@ input_write_high:
input_read:
push tmp0
; clear
- cbi PORTC, 6
+ ;cbi PORTC, 6
push par0
push par1
push par2
- ldi par0, 1
- ldi par1, 1
- ldi par2, 1
- rcall wait
- sbi PORTC, 6
- ldi par0, 1
- ldi par1, 1
- ldi par2, 1
- rcall wait
+ ;ldi par0, 1
+ ;ldi par1, 1
+ ;ldi par2, 1
+ ;rcall wait
+ ;sbi PORTC, 6
+ ;ldi par0, 1
+ ;ldi par1, 1
+ ;ldi par2, 1
+ ;rcall wait
; load
cbi PORTD, 2
ldi par0, 1
@@ -700,8 +705,8 @@ translate_map:
; D = Current display
.equ HANDLE_STATE_MASK = 0b01111100
.equ HANDLE_STATE_AUTH = (0 << 2)
-.equ HANDLE_STATE_AUTHED = (1 << 2)
-.equ HANDLE_STATE_CHANGE = (2 << 2)
+.equ HANDLE_STATE_AUTHED = (2 << 2)
+.equ HANDLE_STATE_CHANGE = (1 << 2)
handle:
push tmp0
push tmp1
@@ -710,6 +715,15 @@ handle:
andi tmp0, HANDLE_STATE_MASK
lsr tmp0
lsr tmp0
+
+ push par0
+ push par1
+ ldi par0, 3
+ mov par1, tmp0
+ rcall display
+ pop par1
+ pop par0
+
ldi ZL, LOW(handle_map)
ldi ZH, HIGH(handle_map)
ldi tmp1, 0
@@ -718,8 +732,17 @@ handle:
ijmp
handle_map:
rjmp handle_auth
- rjmp handle_authed
+ ;rjmp handle_authed
rjmp handle_change
+ rjmp handle_authed
+handle_state:
+ push tmp0
+ ldi tmp0, HANDLE_STATE_MASK
+ neg tmp0
+ and ret0, tmp0
+ or ret0, par0
+ pop tmp0
+ ret
handle_blink:
sbrs par0, 7
rjmp handle_blink_low
@@ -750,21 +773,56 @@ handle_blink_high:
handle_auth:
rcall handle_blink
cpi par1, 0xF0
- breq handle_auth_no_press
+ breq handle_auth_end
+ cpi par1, 0x0E
+ breq handle_auth_left
+ cpi par1, 0x0F
+ breq handle_auth_right
cpi par1, 0x0A
breq handle_auth_submit
+ cpi par1, 0x0B
+ breq handle_auth_illegal_key
+ cpi par1, 0x0C
+ breq handle_auth_illegal_key
+ cpi par1, 0x0D
+ breq handle_auth_illegal_key
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
rjmp handle_end
-handle_auth_no_press:
+handle_auth_illegal_key:
+ rjmp handle_end
+handle_auth_end:
+ rjmp handle_end
+handle_auth_left:
+ rjmp handle_left
+handle_auth_right:
+ rjmp handle_right
+handle_left:
+ push tmp0
+ mov tmp0, ret0
+ andi tmp0, 0b00000011
+ dec tmp0
+ andi tmp0, 0b00000011
+ andi ret0, 0b11111100
+ or ret0, tmp0
+ pop tmp0
+ rjmp handle_end
+handle_right:
+ push tmp0
+ mov tmp0, ret0
+ andi tmp0, 0b00000011
+ inc tmp0
+ andi tmp0, 0b00000011
+ andi ret0, 0b11111100
+ or ret0, tmp0
+ pop tmp0
rjmp handle_end
handle_auth_submit:
push par0
@@ -813,9 +871,9 @@ handle_auth_submit:
pop tmp1
pop tmp0
pop ret0
+ ldi par0, HANDLE_STATE_AUTHED
+ rcall handle_state
pop par0
- andi ret0, HANDLE_STATE_MASK
- ori ret0, HANDLE_STATE_AUTHED
rjmp handle_end
handle_compare_end:
pop tmp2
@@ -827,21 +885,93 @@ handle_authed:
push par0
push par1
ldi par0, 0
- ldi par1, 1
- rcall display
- ldi par0, 1
- ldi par1, 3
+ ldi par1, 0
rcall display
- ldi par0, 2
- ldi par1, 3
+ inc par0
rcall display
- ldi par0, 3
- ldi par1, 7
+ inc par0
rcall display
+ inc par0
+ ;rcall display
pop par1
pop par0
+ cpi par1, 0xF0
+ breq handle_authed_end
+ push par0
+ ldi par0, HANDLE_STATE_CHANGE
+ cpi par1, 0x0B
+ brne pc+2
+ rcall handle_state
+ ldi par0, HANDLE_STATE_AUTH
+ cpi par1, 0x0D
+ brne pc+2
+ rcall handle_state
+ pop par0
+ rjmp handle_end
+handle_authed_end:
rjmp handle_end
handle_change:
+ rcall handle_blink
+ cpi par1, 0xF0
+ breq handle_change_end
+ cpi par1, 0x0E
+ breq handle_change_left
+ cpi par1, 0x0F
+ breq handle_change_right
+ cpi par1, 0x0A
+ breq handle_change_submit
+ cpi par1, 0x0B
+ breq handle_change_authed
+ cpi par1, 0x0C
+ breq handle_change_illegal_key
+ cpi par1, 0x0D
+ breq handle_change_logout
+ push par0
+ andi par0, 0b00000011
+ rcall set_digit
+ rcall display
+ inc par0
+ andi par0, 0b00000011
+ andi ret0, 0b11111100
+ or ret0, par0
+ pop par0
+ rjmp handle_end
+handle_change_authed:
+ push par0
+ ldi par0, HANDLE_STATE_AUTHED
+ rcall handle_state
+ rjmp handle_end
+handle_change_illegal_key:
+ rjmp handle_end
+handle_change_left:
+ rjmp handle_left
+handle_change_right:
+ rjmp handle_right
+handle_change_end:
+ rjmp handle_end
+handle_change_logout:
+ push par0
+ ldi par0, HANDLE_STATE_AUTH
+ rcall handle_state
+ rjmp handle_end
+handle_change_submit:
+ push par0
+ push par1
+ push par2
+ ldi par0, 0
+ ldi par1, 0
+ mov par2, dig0
+ rcall eeprom_write
+ ldi par0, 1
+ ldi par1, 0
+ mov par2, dig1
+ rcall eeprom_write
+ pop par2
+ pop par1
+ rcall load_code
+ ldi par0, HANDLE_STATE_AUTHED
+ rcall handle_state
+ pop par0
rjmp handle_end
handle_end:
pop tmp1