forked from kodera2t/Magical_tweezersIV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiny10_I2C.asm
executable file
·333 lines (303 loc) · 5.49 KB
/
Tiny10_I2C.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
;
; 20160616_tiny10_I2C_1.asm
;
; Created: 6/16/2016 10:28:45 AM
; Author : kodera2t
;
.def data = R16
.def cnt = R17
.def cnt2 = R18
.def long_count = R19
.def display = R25
.def temp1 = R20
.def temp2 = R21
.def temp3 = R22
.def temp4 = R23
.def temp5 = R24
;.def temp6 = R25
.equ count_start = 0x04
.equ count_end = 0x01
.equ subnum = 0x01
.equ SUB_COUNT = 0x04
.equ long_delay =0xFF
; PB0: SDA, PB1: SCL
setup:
; ldi temp1,0
; out CLKPSR,temp1
; PB0 and PB1 are out, don't care receiving.
ldi temp1, 0b11
out DDRB, temp1
; as a initial, SDA and SCL are high
ldi temp1, 0b11
out PORTB, temp1
ldi display,0x00
rcall lcd_init; LCD initialize
ldi display,0xFF
rcall longdelay
rcall longdelay
mainloop:
inc display
cpi display,10
brne notclear
ldi display,0
notclear:
rcall longdelay
rcall init
rcall start
ldi data,0x7C
ldi data,0b1000_0000; cont command
rcall writedata
ldi data,0b1100_0111; second line,last digit
rcall writedata
ldi data,0b1100_0000; cont data
rcall writedata
mov temp1, display
ori temp1, 0b00110000
mov data,temp1
rcall writedata
/* ldi data,0b00_0000
rcall writedata
ldi data,0x39
rcall writedata*/
rcall ends
rjmp mainloop
delay: ; subroutine DELAY
ldi temp3, SUB_COUNT
SUB_COUNT1:
ldi temp4, COUNT_END
ldi temp5, COUNT_START
;ldi temp6, SUBNUM=0x01
COUNTER:
dec temp5
cpse temp5, temp4
rjmp COUNTER
dec temp3
cpse temp3, temp4
rjmp SUB_COUNT1
ret
start:
ldi temp1, 0b10
out PORTB, temp1
rcall delay
ldi temp1, 0b00
out PORTB, temp1
rcall delay
ret
;cl, da
ends:
ldi temp1,0b10
out PORTB, temp1
rcall delay
ldi temp1,0b11
out PORTB, temp1
rcall delay
ret
init:
ldi temp1, 0b11
out PORTB, temp1
rcall delay
ret
;cl da
bit_high:
ldi temp1, 0b00
out PORTB, temp1
rcall delay
ldi temp1, 0b01
out PORTB, temp1
rcall delay
ldi temp1, 0b11
out PORTB, temp1
rcall delay
ldi temp1, 0b01
out PORTB, temp1
rcall delay
ldi temp1, 0b00
out PORTB, temp1
rcall delay
//ldi temp1, 0b11
//out PORTB, temp1
ret
;cl=1 da=0
bit_low:
ldi temp1, 0b00
out PORTB, temp1
rcall delay
ldi temp1, 0b00
out PORTB, temp1
rcall delay
ldi temp1, 0b10
out PORTB, temp1
rcall delay
ldi temp1, 0b00
out PORTB, temp1
rcall delay
ldi temp1, 0b00
out PORTB, temp1
rcall delay
ret
;cl da
;ack:
; ldi temp1, 0b
; writing data is stored in data
writedata:
ldi cnt,0x00
ldi cnt2,0xF
rep:
mov temp2, data
andi temp2,0b10000000
cpi temp2, 0b10000000
breq highbit
rcall bit_low
rjmp sendend
highbit:
rcall bit_high
sendend:
lsl data
inc cnt
cpi cnt,8
brne rep
ldi temp1, 0b11
out PORTB, temp1
small_loop:
dec cnt2
rcall delay
cpi cnt2,0x00
brne small_loop
ret
lcd_init:
rcall init
rcall start
ldi data,0x7C
rcall writedata
ldi data,0b1000_0000
rcall writedata
ldi data,0x38
rcall writedata
ldi data,0b0000_0000
rcall writedata
ldi data,0x39
rcall writedata
rcall ends
rcall start
ldi data,0x7C
rcall writedata
ldi data,0b1000_0000
rcall writedata
ldi data,0x14
rcall writedata
ldi data,0b0000_0000
rcall writedata
ldi data,0x73
rcall writedata
rcall ends
rcall start
ldi data,0x7C
rcall writedata
ldi data,0b1000_0000
rcall writedata
ldi data,0x55
rcall writedata
ldi data,0b1000_0000
rcall writedata
ldi data,0x6c
rcall writedata
ldi data,0b1000_0000;cont
rcall writedata
ldi data,0x38
rcall writedata
ldi data,0b1000_0000;cont
rcall writedata
ldi data,0x0c
rcall writedata
ldi data,0b1000_0000;cont
rcall writedata
ldi data,0x01
rcall writedata
ldi data,0b1000_0000;cont command
rcall writedata
ldi data,0b1000_0000;address 0x00
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0100_1000; H
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0110_0101; e
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0110_1100; l
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0110_1100; l
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0110_1111; o
rcall writedata
ldi data,0b1000_0000; cont command
rcall writedata
ldi data,0b1100_0000; second line
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0100_0001; A
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0111_0100; t
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0111_0100; t
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0110_1001; i
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0110_1110; n
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0111_1001; y
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0011_0001; 1
rcall writedata
ldi data,0b1100_0000;cont data
rcall writedata
ldi data,0b0011_0000; 0
rcall writedata
rcall ends
ret
longdelay:
ldi long_count,long_delay
localloop:
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
dec long_count
cpi long_count,0x00
brne localloop
ret