-
Notifications
You must be signed in to change notification settings - Fork 0
/
main2.asm
250 lines (198 loc) · 3.17 KB
/
main2.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
;Halil Cuma
.INCLUDE "m328pdef.inc" ; Load addresses of (I/O) registers
.ORG 0x0000
RJMP init
.ORG 0x0020
RJMP Timer0OverFlowInterrupt
.EQU BUFFERBEGIN = 0x200
.DEF DataLength = R4
.DEF Pattern = R5
init:
LDI R16, 0b00000100 ;load Immediate 101 to R16(101: enable pre1024)
OUT TCCR0b, R16 ; timrt counter control register
; set the correct reload values 238
LDI R17, 185 ;256-(16MH/256)/880= 184.9
OUT TCNT0, R17 ; Timer counter register to initialization
; global interrupt enable
SEI
SBI DDRB,1
SBI PORTB,1
SBI DDRC,2
SBI PORTC,2
SBI DDRC,3
SBI PORTC,3
CBI DDRD,3 ;INPUT
CBI DDRD,2
CBI DDRD,1
CBI DDRD,0
SBI DDRD,7 ;OUTPUT
SBI DDRD,6
SBI DDRD,5
SBI DDRD,4
SBI PORTD,3 ;PULL RESITOR
SBI PORTD,2
SBI PORTD,1
SBI PORTD,0
RJMP MAIN
MAIN:
LDI ZL,low(BUFFERBEGIN)
LDI ZH,high(BUFFERBEGIN)
LDI ZL, Low(CodeTable<<1)
LDI ZH, High(CodeTable<<1)
/*LDI R26,4
LDI R27,2
MUL R26,R27
ADD ZL,R0
ADC ZH,R1*/
LPM DataLength,Z+
LPM Pattern, Z ;0x15 > 10101
;SBI PORTC,3
;SBI PORTC,2
RJMP CYC1
CYC1:
CBI PORTD,7
SBI PORTD,6
SBI PORTD,5
SBI PORTD,4
SBIS PIND,0
RJMP BTNF
SBIS PIND,1
;RJMP BTN9
SBIS PIND,2
;RJMP BTN8
SBIS PIND,3
RJMP BTN7
RJMP CYC2
CYC2:
SBI PORTD,7
CBI PORTD,6
SBI PORTD,5
SBI PORTD,4
SBIS PIND,0
;RJMP BTNE
SBIS PIND,1
;RJMP BTN6
SBIS PIND,2
;RJMP BTN5
SBIS PIND,3
;RJMP BTN4
RJMP CYC3
CYC3:
SBI PORTD,7
SBI PORTD,6
CBI PORTD,5
SBI PORTD,4
SBIS PIND,0
;RJMP BTND
SBIS PIND,1
;RJMP BTN3
SBIS PIND,2
;RJMP BTN2
SBIS PIND,3
;RJMP BTN1
RJMP CYC4
CYC4:
SBI PORTD,7
SBI PORTD,6
SBI PORTD,5
CBI PORTD,4
SBIS PIND,0
;RJMP BTNC
SBIS PIND,1
;RJMP BTNB
SBIS PIND,2
;RJMP BTN0
SBIS PIND,3
;RJMP BTNA
RJMP MAIN
Delay:
LDI R19,255
Loop:
LDI R20,255
Loop2:
DEC R20
BRNE Loop2
DEC R19
BRNE Loop
DEC R18
BRNE Delay
RET
/*LDI R26,3
LDI R27,2
MUL R26,R27
ADD ZL,R0
ADC ZH,R1
LPM Pattern,Z+
LPM DataLength,Z*/
SendMores:
PUSH R18
PUSH R19
PUSH R20
dotDashLoop:
RCALL SendDD
LDI R18, 50
RCALL Delay
DEC DataLength
BRNE dotDashLoop
POP R18
POP R19
POP R20
RET
SendDD:
ROR Pattern
BRCC SendDot
RJMP SendDash
RET
SendDot:
SEI
CBI PORTC,2 ; Turn ON LED3
LDI R16, 0x01 ;
STS TIMSK0, R16 ; Enable Overflow Interrupt
LDI R18,50
RCALL Delay
SBI PORTC,2 ; Turn OFF LED2
LDI R16, 0x00 ;
STS TIMSK0, R16 ; Enable Overflow Interrupt
CLI
RET
SendDash:
SEI
CBI PORTC,3 ; Turn ON LED3
LDI R16, 0x01 ;
STS TIMSK0, R16 ; Enable Overflow Interrupt
LDI R18,150
RCALL Delay
LDI R16, 0x00 ;
STS TIMSK0, R16 ; Enable Overflow Interrupt
SBI PORTC,3 ; Turn OFF LED2
CLI
RET
BTNF:
RCALL SendMores
LDI ZL,low(BUFFERBEGIN)
LDI ZH,high(BUFFERBEGIN)
RJMP MAIN
BTN7:
RCALL SendMores
RJMP MAIN
Timer0OverflowInterrupt:
SBI PINB,1 ; Toggle BUZZER
RETI ; Return to Calling location from Interrupt
CodeTable:
.db 5, 0b11111 ; [0]
/*.db 5, 0b10101 ; [1]
.db 5, 0b00001 ; [2]
.db 5, 0b00001 ; [3]
.db 5, 0b10101 ; [4]
.db 5, 0b10101 ; [5]
.db 5, 0b10101 ; [6]
.db 5, 0b10101 ; [7]
.db 5, 0b10101 ; [8]
.db 5, 0b10101; [9]
.db 5, 0b10101 ; [A]
.db 5, 0b10101 ; [B]
.db 5, 0b10101 ; [C]
.db 5, 0b10101 ; [D]
.db 5, 0b10101 ; [E]
.db 5, 0b10101 ; [F]
.db 5, 0b10101 ; [Blank]*/