-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAST_SAVE_MICROS_PRPOJECT.asm
283 lines (196 loc) · 3.98 KB
/
LAST_SAVE_MICROS_PRPOJECT.asm
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
;
; Project.asm
;
; Created: 9/10/2017 3:13:47 PM
; Author : Preshen Goobiah & Marc Karp
;
.include "m328pdef.inc" // change for other devices
.def temp = r16
.def counter = r17
.def red = r18
.def I = r21
.def J = R22
.equ a = 21 ;(16000000 / 256) / 440(frequency of A) - 1
// change to change ports
.equ SEG7_PORT= PORTC
.equ SEG7_DDR = DDRC
.CSEG
.ORG 0
jmp reset
.ORG 0x002 ; interupt 0
jmp entrance_handler
.ORG 0X004 ; interupt 1
jmp exit_handler
segments: //digits 0-9
.db 0b01000000, 0b01110011, 0b00001001, 0b00001100
.db 0b0010110, 0b10100100, 0b00100000, 0b01011100
.db 0b00000000, 0b00010100
RESET:
LDI temp,LOW(RAMEND) ; Set up stack - needed for sub-routines
OUT SPL,temp
LDI temp,HIGH(RAMEND)
OUT SPH,temp
; ldi Zl,low(segments * 2) ; * to convert cseg address to byte addressing
; ldi Zh,high(segments * 2)
Ldi ZL, low(segments*2)
LDI ZH, high(segments*2)
ser temp ; 7-SEG Port as outputs (FFh)
out SEG7_DDR, temp
; lpm temp, Z+
clr counter
start_main:
ser r16
out DDRB, R16 ; ALL OUTPUTS
sbi PORTB, 4 ; FOR MIDDLE SEG TO BE ON
SBI PORTB, 2 ; ORANGE
CBI PORTB, 3 ; RED OFF
// SET UP PWM FOR VARYING INTENSITY OF BEEP
ldi r16, (1<<ISC01)|(1<<ISC00)| (1<<ISC11) | (1<<ISC10);
sts EICRA, r16
ldi r16, (1<<int0)|(1<<int1)
out EIMSK, r16
wait:
nop
sei
;CBI PORTB,5 ;INCLUDING THIS HERE, CAUSES THE COUNTER TO GO TO 9
sleep
sbrs red, 0
SBI PORTB, 2
jmp wait
exit_handler:
call delay
cpi counter, 0
breq empty
nop
rcall RED_OFF
dec counter
cbi PORTB, 4 ; MIDDLE 7\_SEG ALWAYS ON UNTIL 1 OR 7 OR 0
sbiw z, 1
lpm temp, Z ;read a byte from 'segments' and increment Z
out SEG7_PORT, temp ; DISPLAY NUMBER ON 7 SEG
cpi counter, 0
breq one_condition2
cpi counter,1
breq one_condition2
cpi counter, 7
breq one_condition2
nop
call BEEPER
reti
red_off:
cbi PORTB, 3
ret
empty:
reti
one_condition2:
sbi PORTB, 4
call BEEPER
reti
entrance_handler:
// add a delay!!!
cbi PORTB, 4 ; PUT THE MIDDLE 7SEG LED ON ALWAYS
cpi counter, 9
brpl parking_full
nop
inc counter
adiw z, 1
lpm temp, Z ;read a byte from 'segments' and increment Z
out SEG7_PORT, temp ; DISPLAY NUMBER ON 7 SEG
cpi counter,1
breq one_condition
;nop
cpi counter, 7
breq one_condition
nop
// GENERATE SOUND
call BEEPER
CBI PORTB, 2
jmp do_nothing
; CHECK FOR 0,1,7
do_nothing:
sbi PORTB, 5
; Delay 10 000 000 cycles
; 500ms at 20 MHz
call delay
cbi PORTB, 5
reti
one_condition:
sbi PORTB, 4 ; MIDDLE 7 SEG
rcall delay_9ms
sbi PORTB, 5 ; GREEN ON
cbi PORTB, 2
; Delay 10 000 000 cycles
; 500ms at 20 MHz
call delay
cbi PORTB, 5 ; GREEN OFF
call BEEPER
reti
/* reset_counter:
Ldi ZL, low(segments*2)
LDI ZH, high(segments*2)
lpm temp,Z+
OUT SEG7_PORT, temp
sbi PORTB, 4
clr counter
reti*/ ; FOR LOOPING 0-9
parking_full:
sbi PORTB, 3
cbi portb, 2
call pause
ldi red, 255
jmp wait ; RETI RETURNS TO RESET FOR SOME REASON. WANT IT TO SLEEP
delay:
ldi r18, 51
ldi r19, 187
ldi r20, 224
L1: dec r20
brne L1
dec r19
brne L1
dec r18
brne L1
rjmp PC+1
ret
; Delay 199 998 cycles
; 9ms 999us 900 ns at 20 MHz
delay_9ms:
ldi r18, 2
ldi r19, 4
ldi r20, 186
L2: dec r20
brne L1
dec r19
brne L1
dec r18
brne L1
rjmp PC+1
ret
BEEPER:
ldi r16, 0b00100011
OUT tccr0a, r16
ldi r16, 0b00001100
OUT tccr0b, r16
ldi temp, a
out ocr0a, temp
;ocr0b = ocr0a/2 to obtain a duty cycle of 50%
clr temp
ldi temp, a
sub temp, counter
out ocr0b, temp ; DUTY CYLE
BEEP: CLR I
BLUPE:
;TURN SPKR ON
sbi ddrd, 5
rcall pause
cbi ddrd, 5
rcall pause
DEC I
BRNE BLUPE
ret
PAUSE:
CLR J
PLUPE:
NOP
DEC J
BRNE PLUPE
RET