Subversion Repositories MB01 Project

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 - 1
; LCD.ASM
2
; PROGETTO: B1601
3
; Compilatore Avocet X6502
4
 
5
; Gestione LCD
6
 
7
 
8
_CHIP_INC_	.SET	1
9
_KEYB_INC_	.SET	1
10
 
11
 
12
	.INCLUDE inc\global.inc
13
	.INCLUDE inc\dirp01.inc
14
 
15
 
16
; BIT di LCDFlag
17
; maschera 0 0 0 0 1 D C B
18
LCDFB_B		.EQU	0	; BLINK cursore
19
LCDFB_C		.EQU	1	; Cursore ON/OFF
20
LCDFB_D		.EQU	2	; Display ON/OFF
21
; maschera 0 0 0 1 SC RL X X
22
LCDFB_RL	.EQU	3	; Shift Destra/Sinistra
23
LCDFB_SC	.EQU	4	; Shift Cursore/Display
24
; maschera 0 0 0 0 0 1 I/D SH
25
LCDFB_SH	.EQU	5	; Shift completo
26
LCDFB_ID	.EQU	6	; Incremento/Decremento
27
LCDFB_R		.EQU	7	; LCD Ready
28
 
29
LCDMAXCOL	.EQU	20
30
LCDMAXROW	.EQU	4
31
 
32
 
33
;----------------------------------------------------------------------------
34
; SEGMENTO CODEF8
35
;----------------------------------------------------------------------------
36
 
37
	.CODEF8
38
 
39
	.GLOBAL	_LCDFlag, LCDSetup, _LCDAtXY, LCDHex
40
 
41
_LCDFlag	.EQU	(DP01ADDR + LCDFlag)
42
 
43
; NOTA - le funzioni seguenti vanno chiamate in modo 8 bit
44
 
45
	.LONGA	off
46
	.LONGI	off
47
 
48
; valore T2 VIA per ritardo 2ms
49
D2MSCNT		.EQU	(2 * 1000 * PHI2)
50
; valore T2 VIA per ritardo 45us
51
D45USCNT	.EQU	(45 * PHI2)
52
 
53
; out LCD carattere A at riga X e colonna Y
54
_LCDAtXY:
55
	php
56
	phd			; salva DP
57
	pea	#DP01ADDR	; imposta DB
58
	pld
59
	CPU08
60
	jsr	SendLCDAt
61
	pld			; ripristina DP
62
	plp
63
	rts
64
 
65
HexDigit:
66
	and	#$0F
67
	cmp	#10
68
	bcc	?01
69
	adc	#('A'-11)
70
	rts
71
?01:	adc	#'0'
72
	rts
73
 
74
Byte2Hex:
75
	pha
76
	lsr	a
77
	lsr	a
78
	lsr	a
79
	lsr	a
80
	jsr	HexDigit
81
	tax
82
	pla
83
	bra	HexDigit
84
 
85
LCDHex:
86
	php
87
	phd			; salva DP
88
	pea	#DP01ADDR	; imposta DB
89
	pld
90
	CPU08
91
	phx
92
	phy
93
	stx	LCDTmp
94
	jsr	Byte2Hex
95
	sta	LCDVal
96
	stx	LCDVal+1
97
	lda	LCDTmp
98
	ply
99
	jsr	SetLCDAddr
100
	lda	LCDVal+1
101
	jsr	SendLCDData
102
	lda	LCDVal
103
	jsr	SendLCDData
104
	lda	#' '
105
	jsr	SendLCDData
106
	plx
107
	pld			; ripristina DP
108
	plp
109
	rts
110
 
111
	.GLOBAL LCDHexL, LCDClrXL
112
 
113
LCDHexL:
114
	jsr	LCDHex
115
	rtl
116
 
117
LCDClrXL:
118
	jsr	ClearLCDRow
119
	rtl
120
 
121
;----------------------------------------------------------
122
; LCDSetup - chiamata da IOInit
123
;----------------------------------------------------------
124
; LCDSetup	- Inizializza LCD dopo reset
125
; In		- A -> flag
126
; Out		- imposta LCDFlag
127
; Registri	- A
128
LCDSetup:
129
	php
130
	phd			; salva DP
131
	pea	#DP01ADDR	; imposta DB
132
	pld
133
	CPU08
134
	jsr	InitLCD
135
	pld			; ripristina DP
136
	plp
137
	rts
138
 
139
 
140
; NOTA - le funzioni locali seguenti vanno chiamate con DP = DP01ADDR
141
; e in modo 8 bit
142
 
143
;----------------------------------------------------------
144
; ClearLCDRow
145
;----------------------------------------------------------
146
; ClearLCDRow	- Cancella una riga del display
147
; In		- X = riga da cancellare
148
; Out		- X = riga da cancellare
149
; Registri	- nessuno
150
 
151
ClearLCDRow:
152
	bit	LCDFlag		; esce se LCD non presente
153
	bpl	?03
154
	cpx	#LCDMAXROW
155
	bcc	?01
156
	ldx	#LCDMAXROW
157
?01:	pha
158
	phy
159
	txa			; A = row
160
	ldy	#0		; Y = col
161
	jsr	SetLCDAddr
162
	ldy	#LCDMAXCOL
163
?02:	lda	#' '
164
	jsr	SendLCDData
165
	dey
166
	bne	?02
167
	txa
168
	jsr	SetLCDAddr
169
	ply
170
	pla
171
?03:	rts
172
 
173
 
174
Delay45us:
175
	ldx	#(.LOW.D45USCNT)
176
	lda	#(.HIGH.D45USCNT)
177
	bra	DoDelay
178
 
179
Delay2ms:
180
	ldx	#(.LOW.D2MSCNT)
181
	lda	#(.HIGH.D2MSCNT)
182
 
183
DoDelay:
184
	stx	VIA0+VIAT2CL
185
	sta	VIA0+VIAT2CH
186
	lda	#T2IFRB
187
?01:	bit	VIA0+VIAIFR		; test T2 flag
188
	beq	?01			; attende timeout
189
	rts
190
 
191
;----------------------------------------------------------
192
; InitLCD
193
;----------------------------------------------------------
194
; InitLCD	- Inizializza LCD dopo reset
195
; In		- nessuno
196
; Out		- imposta LCDFlag
197
; Registri	- A
198
 
199
InitLCD:
200
	sta	LCDFlag
201
	cmp	#0
202
	beq	?98
203
	;lda	#$80		; imposta flag LCD presente
204
	;tsb	LCDFlag
205
	;;bra	?99
206
 
207
	lda	#$38
208
	clc
209
	jsr	WriteLCD2
210
	jsr	Delay45us
211
	lda	#$0C
212
	clc
213
	jsr	WriteLCD2
214
	jsr	Delay45us
215
 
216
	lda	#$01
217
	clc
218
	jsr	WriteLCD2
219
	jsr	Delay2ms
220
 
221
	lda	#00111000B	; 8 bit - 4 righe - font 5 x 8
222
	;lda	#00110000B	; 8 bit - 4 righe - font 5 x 8
223
 
224
		lda	#00000010B		; Incremento - no shift
225
		;jsr	SendLCDCmd
226
		jsr	SetLCDMode
227
?98:	rts
228
 
229
 
230
?99:
231
	jsr	OffLCD		; LCD OFF
232
	lda	#00111100B	; 8 bit - 4 righe - font 5 x 8
233
	jsr	SendLCDCmd
234
	jsr	OnLCD		; LCD ON
235
	lda	#00000010B	; Incremento - no shift
236
	;jsr	SendLCDCmd
237
	jsr	SetLCDMode
238
	bra	ClearLCD	; cancella display
239
 
240
;----------------------------------------------------------
241
; SetLCDAddr
242
;----------------------------------------------------------
243
; SetLCDAddr	- Imposta indirizzo DD RAM LCD
244
; In		- A = riga LCD
245
;		  Y = colonna LCD
246
; Out		- DD-RAM LCD impostata
247
; Registri	- A
248
 
249
SetLCDAddr:
250
	sty	LCDTmp		; salva colonna
251
	clc
252
	ror	a		; Bit0 e Bit1 in Bit6 e Bit7
253
	ror	a
254
	ror	a
255
	and	#$C0		; maschera on bit6 e bit7
256
	bpl	?01		; riga = 0, 1
257
	ora	#$14		; riga 2,3 - somma offset
258
?01:	clc
259
	adc	LCDTmp		; somma colonna
260
	ora	#$80		; Bit7 = 1 - setta DD RAM
261
	brl	SendLCDCmd	; invia comando a LCD
262
 
263
 
264
;----------------------------------------------------------
265
; ClearLCD
266
;----------------------------------------------------------
267
; ClearLCD	- cancella LCD
268
; In		- nessuno
269
; Out		- nessuno
270
; Registri	- A
271
 
272
ClearLCD:
273
	lda	#$01
274
	brl	SendLCDCmd
275
 
276
 
277
;----------------------------------------------------------
278
; HomeLCD
279
;----------------------------------------------------------
280
; HomeLCD	- posiziona cursore a 0,0
281
; In		- nessuno
282
; Out		- nessuno
283
; Registri	- A
284
 
285
HomeLCD:
286
	lda	#$02
287
	brl	SendLCDCmd
288
 
289
 
290
;----------------------------------------------------------
291
; OnLCD
292
;----------------------------------------------------------
293
; OnLCD		- LCD ON
294
; In		- nessuno
295
; Out		- LCDFlag
296
; Registri	- A
297
 
298
OnLCD:
299
	lda	#LCDFB_D
300
	tsb	LCDFlag		; LCDFlag<2>->1 LCD ON
301
	bra	SetLCDCurs2
302
 
303
 
304
;----------------------------------------------------------
305
; CursLCDOn
306
;----------------------------------------------------------
307
; CursLCDOn	- Cursore LCD ON
308
; In		- nessuno
309
; Out		- LCDFlag
310
; Registri	- A
311
 
312
CursLCDOn:
313
	lda	#LCDFB_C
314
	tsb	LCDFlag		; LCDFlag<1>->1 CURSORE LCD ON
315
	bra	SetLCDCurs2
316
 
317
 
318
;----------------------------------------------------------
319
; BlinkLCDOn
320
;----------------------------------------------------------
321
; BlinkLCDOn	- Blink Cursore LCD ON
322
; In		- nessuno
323
; Out		- LCDFlag
324
; Registri	- A
325
 
326
BlinkLCDOn:
327
	lda	#LCDFB_B
328
	tsb	LCDFlag		; LCDFlag<0>->1 BLINK CURSORE LCD ON
329
	bra	SetLCDCurs2
330
 
331
;----------------------------------------------------------
332
; OffLCD
333
;----------------------------------------------------------
334
; OffLCD	- LCD OFF
335
; In		- nessuno
336
; Out		- LCDFlag
337
; Registri	- A
338
 
339
OffLCD:
340
	lda	#LCDFB_D
341
	trb	LCDFlag		; LCDFlag<2>->0 LCD OFF
342
	bra	SetLCDCurs2
343
 
344
 
345
;----------------------------------------------------------
346
; CursLCDOff
347
;----------------------------------------------------------
348
; CursLCDOff	- Cursore LCD OFF
349
; In		- nessuno
350
; Out		- LCDFlag
351
; Registri	- A
352
 
353
CursLCDOff:
354
	lda	#LCDFB_C
355
	trb	LCDFlag		; LCDFlag<1>->0 CURSORE LCD OFF
356
	bra	SetLCDCurs2
357
 
358
 
359
;----------------------------------------------------------
360
; BlinkLCDOff
361
;----------------------------------------------------------
362
; BlinkLCDOff	- Blink Cursore LCD OFF
363
; In		- nessuno
364
; Out		- LCDFlag
365
; Registri	- A
366
 
367
BlinkLCDOff:
368
	lda	#LCDFB_B
369
	trb	LCDFlag		; LCDFlag<0>->0 BLINK CURSORE LCD OFF
370
	bra	SetLCDCurs2
371
 
372
 
373
;----------------------------------------------------------
374
; SetLCDCurs
375
;----------------------------------------------------------
376
; SetLCDCurs	- Imposta cursore e stato on/off LCD
377
; In		- A: flag -> 0 0 0 0 0 D C B
378
; Out		- LCDFlag
379
; Registri	- A
380
 
381
SetLCDCurs:
382
	and	#00000111B	; maschera on D C B
383
	sta	LCDTmp		; salva flag
384
	lda	LCDFlag
385
	and	#11111000B	; maschera off D C B
386
	ora	LCDTmp		; nuovo flag
387
	sta	LCDFlag
388
 
389
 
390
;----------------------------------------------------------
391
; SetLCDCurs2 - interna
392
;----------------------------------------------------------
393
; SetLCDCurs2	- Imposta cursore e stato on/off LCD
394
; In		- nessuno
395
; Out		- imposta LCD in base ai bit D C B di LCDFlag
396
; Registri	- A
397
 
398
SetLCDCurs2:
399
	lda	LCDFlag
400
	and	#00000111B	; maschera on D C B
401
	ora	#00001000B	; comando cursore
402
	bra	SendLCDCmd
403
 
404
 
405
;----------------------------------------------------------
406
; ShiftLCDCursL
407
;----------------------------------------------------------
408
; ShiftLCDCursL	- Shifta cursore LCD a sinistra
409
; In		- nessuno
410
; Out		- imposta LCDFlag
411
; Registri	- A
412
 
413
ShiftLCDCursL:
414
	lda	#(LCDFB_SC.OR.LCDFB_RL)	; LCDFlag<4>->0 - Shift Cursore
415
	trb	LCDFlag			; LCDFlag<3>->0 - Shift sinistra
416
	bra	SetLCDShift2
417
 
418
 
419
;----------------------------------------------------------
420
; ShiftLCDCursR
421
;----------------------------------------------------------
422
; ShiftLCDCursR	- Shifta cursore LCD a destra
423
; In		- nessuno
424
; Out		- imposta LCDFlag
425
; Registri	- A
426
 
427
ShiftLCDCursR:
428
	lda	#LCDFB_SC
429
	trb	LCDFlag			; LCDFlag<4>->0 - Shift Cursore
430
	lda	#LCDFB_RL
431
	tsb	LCDFlag			; LCDFlag<3>->1 - Shift destra
432
	bra	SetLCDShift2
433
 
434
 
435
;----------------------------------------------------------
436
; ShiftLCDLeft
437
;----------------------------------------------------------
438
; ShiftLCDLeft	- Shifta LCD a sinistra
439
; In		- nessuno
440
; Out		- imposta LCDFlag
441
; Registri	- A
442
 
443
ShiftLCDLeft:
444
	lda	#LCDFB_SC
445
	tsb	LCDFlag			; LCDFlag<4>->1 - Shift Display
446
	lda	#LCDFB_RL
447
	trb	LCDFlag			; LCDFlag<3>->0 - Shift sinistra
448
	bra	SetLCDShift2
449
 
450
 
451
;----------------------------------------------------------
452
; ShiftLCDRight
453
;----------------------------------------------------------
454
; ShiftLCDRight	- Shifta LCD a destra
455
; In		- nessuno
456
; Out		- imposta LCDFlag
457
; Registri	- A
458
 
459
ShiftLCDRight:
460
	lda	#(LCDFB_SC.OR.LCDFB_RL)	; LCDFlag<4>->1 - Shift Display
461
	tsb	LCDFlag			; LCDFlag<3>->1 - Shift destra
462
	bra	SetLCDShift2
463
 
464
 
465
;----------------------------------------------------------
466
; ShiftLCD
467
;----------------------------------------------------------
468
; ShiftLCD	- Shifta display e/o cursore
469
; In		- A: 0 0 0 0 0 0 SC RL
470
; Out		- imposta LCDFlag
471
; Registri	- A
472
 
473
ShiftLCD:
474
	and	#00000011B		; maschera bit SC RL
475
	asl	a			; sposta SC ed RL in Bit4 e Bit3
476
	asl	a
477
	asl	a
478
	sta	LCDTmp
479
	lda	LCDFlag
480
	and	#11100111B		; maschera off SC ed RL del flag
481
	ora	LCDTmp			; imposta nuovo flag
482
	sta	LCDFlag
483
 
484
 
485
;----------------------------------------------------------
486
; SetLCDShift2 - interna
487
;----------------------------------------------------------
488
; SetLCDShift2	- Shifta display e/o cursore in base a LCDFlag
489
; In		- nessuno
490
; Out		- nessuno
491
; Registri	- A
492
 
493
SetLCDShift2:
494
	lda	LCDFlag
495
	and	#00011000B	; maschera SC ed RL
496
	lsr	a		; shifta 1 bit a destra
497
	ora	#00010000B	; imposta comando shift
498
	bra	SendLCDCmd
499
 
500
 
501
;----------------------------------------------------------
502
; SetLCDMode
503
;----------------------------------------------------------
504
; SetLCDMode	- imposta entry mode LCD
505
; In		- A: 0 0 0 0 0 0 ID SH
506
; Out		- imposta LCDFlag
507
; Registri	- A
508
 
509
SetLCDMode:
510
	and	#00000011B	; maschera on bit ID e SH
511
	pha			; salva
512
	asl	a		; sposta ID in Bit6
513
	asl	a
514
	asl	a
515
	asl	a
516
	asl	a
517
	sta	LCDTmp
518
	lda	LCDFlag
519
	and	#10011111B	; maschera off bit ID e SH
520
	ora	LCDTmp		; imposta nuovo flag
521
	sta	LCDFlag
522
	pla			; ripristina A
523
	ora	#00000100b	; IMPOSTA COMANDO
524
 
525
 
526
;----------------------------------------------------------
527
; SendLCDCmd - interna
528
;----------------------------------------------------------
529
; SendLCDCmd	- Invia comando a LCD
530
; In		- A = comando
531
; Out		- nessuno
532
; Registri	- A
533
 
534
SendLCDCmd:
535
	bit	LCDFlag		; esce se LCD non presente
536
	bpl	_90
537
	clc			; invia comando
538
 
539
 
540
;----------------------------------------------------------
541
; WriteLCD - interna
542
;----------------------------------------------------------
543
; WriteLCD	- Invia comando/data a LCD
544
; In		- C = 0 -> invia comando
545
;		  C = 1 -> invia data
546
;		- A = dato/comando
547
; Out		- nessuno
548
; Registri	- A
549
 
550
WriteLCD:
551
	jsr	WaitLCD		; attende LCD pronto
552
WriteLCD2:
553
	php
554
	sei
555
	phx			; salva X
556
	phb			; salva DBR
557
	ldx	#0		; imposta DBR = 0
558
	phx
559
	plb
560
	ldx	#00000010B	; E->0, RW->1, RS->0
561
	stx	PIA1+PIAPRA
562
	stz	PIA1+PIACRB	; accesso a DDRB
563
	ldx	#11111111B	; pota B in uscita
564
	stx	PIA1+PIADDRB
565
	ldx	#00000100B
566
	stx	PIA1+PIACRB	; accesso a PRB
567
	sta	PIA1+PIAPRB	; dato
568
	lda	#00000000B	; E->0, RW->0, RS->0
569
	bcc	?01		; comando - RS = 0
570
	ora	#00000001B	; dato - RS = 1
571
?01:	sta	PIA1+PIAPRA
572
	ora	#00000100B	; E->1
573
	sta	PIA1+PIAPRA
574
	nop
575
	nop
576
	nop
577
	nop
578
	and	#11111011B	; E->0
579
	sta	PIA1+PIAPRA
580
	ora	#00000010B	; RW->1
581
	sta	PIA1+PIAPRA
582
	stz	PIA1+PIADDRB	; porta B in input
583
	ldx	#00000100B
584
	stx	PIA1+PIACRB	; accesso a PRB
585
	plb			; ripristina DBR
586
	plx
587
	plp
588
_90:	rts
589
 
590
 
591
;----------------------------------------------------------
592
; SendLCDData
593
;----------------------------------------------------------
594
; SendLCDData	- Invia dato a LCD
595
; In		- A = dato
596
; Out		- nessuno
597
; Registri	- A
598
 
599
SendLCDData:
600
	bit	LCDFlag		; esce se LCD non presente
601
	bpl	_90
602
	sec
603
	bcs	WriteLCD
604
 
605
 
606
;----------------------------------------------------------
607
; SendLCDAt
608
;----------------------------------------------------------
609
; SendLCDAt	- Invia dato a riga/colonna
610
; In		- A = dato
611
;		  X = riga
612
;		  Y = colonna
613
; Out		- X, Y
614
; Registri	- A
615
 
616
SendLCDAt:
617
	bit	LCDFlag		; esce se LCD non presente
618
	bpl	_90
619
	cpx	#LCDMAXROW
620
	bcc	?01
621
	ldx	#LCDMAXROW-1
622
?01:	cpy	#LCDMAXCOL
623
	bcc	?02
624
	ldy	#LCDMAXCOL-1
625
?02:	pha			; salva dato
626
	txa			; A = row
627
	jsr	SetLCDAddr
628
	pla			; A = dato
629
	sec
630
	bra	WriteLCD
631
 
632
 
633
;----------------------------------------------------------
634
; WaitLCD - interna
635
;----------------------------------------------------------
636
; WaitLCD	- Attende Busy Flag LCD = 0
637
; In		- nessuno
638
; Out		- nessuno
639
; Registri	- nessuno - P salvato
640
 
641
WaitLCD:
642
	php			; salva P
643
	pha			; salva A
644
?01:	clc			; legge status
645
	jsr	ReadLCD
646
	and	#$80		; test Busy Flag (bit 7)
647
	bne	?01		; attende LCD pronto
648
	pla			; ripristina A
649
	plp			; ripristina P
650
	rts
651
 
652
 
653
;----------------------------------------------------------
654
; GetLCDData
655
;----------------------------------------------------------
656
; GetLCDData	- Legge dato da  LCD
657
; In		- nessuno
658
; Out		- A = dato
659
; Registri	- A
660
 
661
GetLCDData:
662
	bit	LCDFlag		; esce se LCD non presente
663
	bpl	_90
664
	sec
665
 
666
 
667
;----------------------------------------------------------
668
; ReadLCD - interna
669
;----------------------------------------------------------
670
; ReadLCD	- Legge status/data da LCD
671
; In		- C = 0 -> legge status
672
;		  C = 1 -> legge data
673
; Out		- A = status/data
674
; Registri	- A
675
 
676
ReadLCD:
677
	php
678
	sei
679
	phb			; salva DBR
680
	phx			; salva X
681
	ldx	#0		; imposta DBR = 0
682
	phx
683
	plb
684
 
685
	stz	PIA1+PIACRB
686
	stz	PIA1+PIADDRB
687
 
688
	ldx	#00000100B
689
	stx	PIA1+PIACRB	; accesso a PRB
690
 
691
	lda	#00000010B	; E->0, RW->1, RS->0
692
	bcc	?01		; legge status
693
	ora	#00000001B	; legge dato - RS->1
694
?01:	sta	PIA1+PIAPRA
695
	nop
696
	nop
697
	nop
698
	nop
699
	ora	#00000100B	; E->1
700
	sta	PIA1+PIAPRA
701
	nop
702
	nop
703
	nop
704
	nop
705
	nop
706
	nop
707
?02:	ldx	PIA1+PIAPRB	; legge bus LCD
708
	cpx	PIA1+PIAPRB	; attende lettura stabile
709
	bne	?02
710
	and	#11111011B	; E->0
711
	sta	PIA1+PIAPRA
712
	txa
713
	plx			; ripristina X
714
	plb			; ripristina DBR
715
	plp
716
	rts
717
 
718
 
719
;----------------------------------------------------------
720
; GetLCDAddr
721
;----------------------------------------------------------
722
; GetLCDAddr	- Legge indirizzo corrente da  LCD
723
; In		- nessuno
724
; Out		- A = indirizzo
725
; Registri	- A
726
 
727
GetLCDAddr:
728
	bit	LCDFlag		; esce se LCD non presente
729
	bpl	?01
730
	clc			; legge status
731
	jsr	ReadLCD
732
	and	#01111111B	; maschera busy flag
733
?01:	rts
734