summaryrefslogtreecommitdiff
path: root/Software/pinlock.asm
blob: ba12dc9c5657d1d2edef644c7997a583f249aa29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
.include "m16def.inc"
.def tmp0 = r16
.def par0 = r17
.def par1 = r18
.def cnt = r19
.def tmp1 = r20
.def tmp2 = r21
.def ret0 = r22
.def ret1 = r23

init:
  ldi tmp0, HIGH(RAMEND)
  out SPH, tmp0
  ldi tmp0, LOW(RAMEND)
  ldi par0, 0xFF
  ldi par1, 0xFF
  rcall wait
  out SPL, tmp0
  ldi tmp0, 0b11111111
  out DDRA, tmp0
  ldi tmp0, 0b11111111
  out DDRB, tmp0
  ldi tmp0, 0b11101100
  out DDRD, tmp0
  ldi tmp0, 0b00000000
  out PORTD, tmp0

	ldi par0, 0
	ldi par1, 0
	rcall display
	ldi par0, 1
	ldi par1, 1
	rcall display
	ldi par0, 2
	ldi par1, 2
	rcall display
	ldi par0, 3
	ldi par1, 3
	rcall display

main:
	ldi par0, 0b11111111
	rcall status
	rjmp [tmp0]

wait:
  mov tmp0, par0
  dec par0
  nop
  brne wait
  mov par0, tmp0
  dec par1
  nop
  brne wait
  ret

; Output the status
; Parameters:
; par0 = Status bits
; Returns:
; None
status:
	ldi tmp0, 1
status_loop:
	mov tmp1, par0
	and tmp1, tmp0
	cp tmp0, tmp1
	breq status_set
	ldi tmp1, 0b00111111
	out PORTD, tmp1
	ldi tmp1, 0b10111111
	out PORTD, tmp1
	rjmp status_end
status_set:
	ldi tmp1, 0b01111111
	out PORTD, tmp1
	ldi tmp1, 0b11111111
	out PORTD, tmp1
	rjmp status_end
status_end:
	lsl tmp0
	cpi tmp0, 0
	brne status_loop
	ret

; Display the digit on a given display.
; Parameters:
; par0 = Display number
; par1 = Digit
; Returns:
; None
display:
	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
	ret
display_0:
	in tmp1, PORTA
	andi tmp1, 0xF0
	or tmp1, tmp0
	out PORTA, tmp1
	ret
display_1:
	in tmp1, PORTB
	andi tmp1, 0xF0
	or tmp1, tmp0
	out PORTB, tmp1
	ret
display_2:
	in tmp1, PORTA
	andi tmp1, 0x0F
	lsl tmp0
	lsl tmp0
	lsl tmp0
	lsl tmp0
	or tmp1, tmp0
	out PORTA, tmp1
	ret
display_3:
	in tmp1, PORTB
	andi tmp1, 0x0F
	lsl tmp0
	lsl tmp0
	lsl tmp0
	lsl tmp0
	or tmp1, tmp0
	out PORTB, tmp1
	ret

; Read the input buttons.
; Parameters:
; None
; Returns:
; ret0 = 123A456B
; ret1 = 789C*0#D
input:
	; Write selection rows
	ldi tmp0, 1
	ldi tmp1, 1
input_loop:
	mov tmp2, tmp0
	and tmp2, tmp1
	cp tmp1, tmp2
	breq input_set