-
Notifications
You must be signed in to change notification settings - Fork 1
/
24C02.asm
580 lines (578 loc) · 13.4 KB
/
24C02.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
ORG #8000
;------------------------------------
; Program For Read/Write EEPROM 24C02
; PA0=SDA (Data) (#1F)
; PB0=SCL (Clock) (#3F)
;------------------------------------
;1C CLS
;1D Set X
;1E Set X,Y
;1F Fill Sym,Num
;FF Inverse
;-----------------
SDA EQU #1F
SCL EQU #3F
PORTSET EQU #7F
;
DI
LD A,1
OUT (#FE),A
LD A,#80
OUT (PORTSET),A
LD A,#FF
OUT (SCL),A
OUT (SDA),A
;
CALL PRI_T
DEFB #1C,#FF
DEFB " Driver For Read/Write on I2C Bus ",#FF
DEFB " Copyright 2000 By (R)soft",13,13
DEFB 0
;
;=========== Read Sequence of Bytes From Adr ========
LD A,0 ;From Adr EEPROM
LD HL,#C000 ;Read To
LD DE,#100 ;How Many
CALL RND_READ
RET C
LD HL,#C000
LD BC,#100
CALL PRINTB
JP MMM
RET
;========== Read From EEPROM =============
LD HL,#C000 ;Read To
LD DE,#100 ;How Many
CALL READ
RET
;========== Read One Byte From EEPROM ========
MMM
LD A,#C0 ;Adr EEPROM
CALL READBYTE
CALL PRIHB
LD A,7
CALL READBYTE
CALL PRIHB
; CALL LLL
RET
;========== Write One Byte To EEPROM ==========
NNN
LD A,#C0 ;Adr EEPROM
LD C,#28 ;Byte To Write
CALL WRITEBYTE
RET
;========== Write Sequence of Bytes From Adr ========
LLL
LD A,#C8 ;To Adr EEPROM
LD HL,#0008 ;From MEMORY
LD DE,8 ;How Many (Maximum 8)
CALL RND_WRITE
RET
RESET
LD A,6
CALL START
CALL PUTBYTE
CALL GETACK
JP C,NOACK
CALL STOP
RET
RND_READ
LD (POINTAD),A
CALL START
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
CALL GETACK
JP C,NOACK
LD A,0 ;ADR EEPROM
POINTAD EQU $-1
CALL PUTBYTE
CALL GETACK
JP C,NOACK
CALL START
LD A,(DEVADR)
SET 0,A ;Read Mode
CALL PUTBYTE
CALL GETACK
JP C,NOACK
DEC DE
LOOPRDM
CALL GETBYTE
LD (HL),A
INC HL
CALL GIVEACK
DEC DE
LD A,E
OR D
JR NZ,LOOPRDM
CALL GETBYTE
LD (HL),A
CALL STOP
AND A
RET
READBYTE
LD (POINT1),A
CALL START
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
CALL GETACK
JP C,NOACK
LD A,0 ;ADR EEPROM
POINT1 EQU $-1
CALL PUTBYTE
CALL GETACK
JP C,NOACK
CALL START
LD A,(DEVADR)
SET 0,A ;Read Mode
CALL PUTBYTE
CALL GETACK
JP C,NOACK
CALL GETBYTE
CALL STOP
AND A
RET
READ
CALL START
LD A,(DEVADR)
SET 0,A ;Read Mode
CALL PUTBYTE
CALL GETACK
JR C,NOACK
DEC DE
LOOPRD
CALL GETBYTE
LD (HL),A
INC HL
CALL GIVEACK
DEC DE
LD A,E
OR D
JR NZ,LOOPRD
CALL GETBYTE
LD (HL),A
CALL STOP
AND A
RET
NOACK
CALL PRI_T
DEFB "Error! No ACKNOWLEDGE Signal From SLAVE IC",0
CALL STOP
SCF
RET
WRITEBYTE
LD (POINT2),A
LD A,C
LD (WBYTE),A
CALL START
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
CALL GETACK
JP C,NOACK
;
LD A,0 ;ADR EEPROM
POINT2 EQU $-1
CALL PUTBYTE
CALL GETACK
JP C,NOACK
;
LD A,0
WBYTE EQU $-1
CALL PUTBYTE
CALL GETACK
JP C,NOACK
;
CALL STOP
AND A
RET
RND_WRITE
LD (POINT3),A
CALL START
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
CALL GETACK
JP C,NOACK
;
LD A,0 ;ADR EEPROM
POINT3 EQU $-1
CALL PUTBYTE
CALL GETACK
JP C,NOACK
RNDWR
LD A,(HL)
INC HL
CALL PUTBYTE
CALL GETACK
JP C,NOACK
DEC DE
LD A,E
OR D
JR NZ,RNDWR
;
CALL STOP
AND A
RET
PRINTB
LD A,(HL)
INC HL
PUSH HL
PUSH BC
CALL PRIHB
LD A," "
CALL PRIA
LD A,(TMPX)
CP 48
JR C,NOEN
CALL PRI_T
DEFB 13,0
NOEN
POP BC
POP HL
DEC BC
LD A,C
OR B
JR NZ,PRINTB
RET
GIVEACK
PUSH AF
XOR A
OUT (SDA),A ;SDA -> 0
CALL PAUSE
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
XOR A
OUT (SCL),A ;SCL -> 0
CALL PAUSE
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
POP AF
RET
GETACK
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
OUT (SCL),A ;SCL -> 1
CALL PAUSE
LD BC,#A000
GETA1
DEC BC ;Counter of Wait
LD A,C
OR B
JR Z,GETERR
IN A,(SDA) ;Wait To SDA=0
BIT 0,A
JR NZ,GETA1
XOR A
OUT (SCL),A ;SCL -> 0
CALL PAUSE
RET
GETERR
XOR A
OUT (SCL),A
CALL PAUSE
SCF ;Set CARRY -> NO ACK
RET
PAUSEDE
DEC DE
LD A,E
OR D
JR NZ,PAUSEDE
RET
GETBYTE
LD B,8
GETBL
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
IN A,(SDA)
RRA
RL C
XOR A
OUT (SCL),A ;SCL -> 0
CALL PAUSE
DJNZ GETBL
;
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
LD A,C
RET
PUTBYTE
LD B,8
PUTBL
RLA
PUSH AF
LD A,#FF
JR C,PUTB1
LD A,0
PUTB1
OUT (SDA),A
CALL PAUSE
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
LD A,0
OUT (SCL),A ;SCL -> 0
CALL PAUSE
POP AF
DJNZ PUTBL
;
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
RET
START
PUSH AF
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
XOR A
OUT (SDA),A ;SDA -> 0
CALL PAUSE
OUT (SCL),A ;SCL -> 0
CALL PAUSE
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
POP AF
RET
STOP
PUSH AF
XOR A
OUT (SDA),A ;SDA -> 0
CALL PAUSE
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
OUT (SDA),A ;SDA -> 1
CALL PAUSE
POP AF
RET
PAUSE
PUSH BC
LD B,0
DJNZ $
POP BC
RET
;
PRI_T POP HL
CALL PRI_BB
JP (HL)
PRI_BB LD A,(HL)
INC HL
AND A
RET Z ;0 - Exit
CP 13
JR NZ,PRI_BB0
EX DE,HL
LD HL,TMPX
LD (HL),0
INC HL
LD A,(HL)
CP 23
JR Z,PRIBB0
INC (HL)
PRIBB0
CALL KOOR_Y
JR PRI_BB
PRI_BB0 CP #FF ;Inverse
JR NZ,PRI_BB1
LD A,(INVERSE)
XOR #FF
LD (INVERSE),A
JR PRI_BB
PRI_BB1 CP #20
JR C,PRI_BB2 ;<#20 - Attr Code
PUSH HL
CALL PRIA
POP HL
JR PRI_BB
PRI_BB2 CP #1F ;Fill
JR NZ,PRI_BB3
LD A,(HL) ;Symbol Fill
INC HL
LD B,(HL) ;Num Fill
INC HL
PUSH HL
PRI_BB4 PUSH BC
PUSH AF
CALL PRIA
POP AF
POP BC
DJNZ PRI_BB4
POP HL
JR PRI_BB
PRI_BB3 CP #1E ;Set Koord
JR NZ,PRI_BB5
LD E,(HL)
INC HL
LD D,(HL)
INC HL
LD (TMPX),DE
EX DE,HL
CALL KOOR_Y
JR PRI_BB
PRI_BB5 CP #1D ;Set X Koor
JR NZ,PRI_BB6
LD A,(HL)
INC HL
LD (TMPX),A
JR PRI_BB
PRI_BB6 CP #1C ;Clear Screen
JR Z,PRI_BB7
LD C,A ;1-#1B Add X Koor
LD A,(TMPX) ;(Without #0D)
ADD A,C
LD (TMPX),A
JR PRI_BB
PRI_BB7 PUSH HL
CALL CLSCR
LD HL,0
LD (TMPX),HL
CALL KOOR_Y
POP HL
JP PRI_BB
PRIHEX LD A,H
PUSH HL
CALL PRIHB
POP HL
LD A,L
PRIHB PUSH AF
RRCA
RRCA
RRCA
RRCA
CALL PRITET
POP AF
PRITET AND #0F
ADD A,#90
DAA
ADC A,#40
DAA
;==============================
PRIA LD E,A ;Symbols Print
LD A,(TMPX)
LD C,A
SRL A
LD HL,0
FOADRS EQU $-2
ADD A,L
LD L,A
LD A,C
RRA
LD D,FONT/256
LD C,0
INVERSE EQU $-1
LD B,#0F
JR C,NOCHET
LD B,#F0
NOCHET LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
LD HL,TMPX
INC (HL)
INC HL
RET
KOOR_Y LD H,TABSCR/256
LD A,(TMPY)
ADD A,A
LD L,A
LD A,(HL)
INC HL
LD H,(HL)
LD L,A
LD (FOADRS),HL
EX DE,HL
RET
CLSCR LD HL,#4000
LD E,L
LD D,H
INC DE
LD (HL),L
LD BC,#17FF
LDIR
INC DE
INC HL
LD (HL),7
LD BC,#2FF
LDIR
RET
DEVADR DEFB #A0 ;Address of Device EEPROM 24C02
TMPX DEFB 0
TMPY DEFB 0
;
;
ORG #B700
TABSCR DEFW #4000,#4020,#4040,#4060,#4080,#40A0
DEFW #40C0,#40E0,#4800,#4820,#4840,#4860
DEFW #4880,#48A0,#48C0,#48E0,#5000,#5020
DEFW #5040,#5060,#5080,#50A0,#50C0,#50E0
;
ORG #B800
FONT
; .INCBIN FONT
.RUN #8000