-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlcd.S
1145 lines (956 loc) · 26.6 KB
/
lcd.S
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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; ****************************************************************************
;
; LCD display
;
; ****************************************************************************
#include "include.inc"
.text
; LCD pins:
; PB6: RS register select, 1=data, 0=command
; PD4: E enable, 1=enable state
; PD3: DB4
; PD2: DB5
; PD1: DB6
; PD0: DB7
; PB7: LCD power
; PD6: VO2 (OC0A)
; LCD commands
#define LCD_CLEAR B0 // 00000001 Clear Display and Home the Cursor
#define LCD_HOME B1 // 0000001* Return Cursor and LCD to Home Position
#define LCD_MOVE B2 // 000001IS Set Cursor Move Direction (I: increment/decrement; S: shift display)
#define LCD_DISPLAY B3 // 00001DCB Enable Display/Cursor (D: display on, C: cursor on, B: blink on)
#define LCD_SHIFT B4 // 0001SR** Move Cursor/Shift Display (S: diplay shift, R: direction right)
#define LCD_SETUP B5 // 001DNF** Set Interface Length (D: 8 bit interface, N: 2 rows, F: big font 5x10)
#define LCD_CGRAM B6 // 01AAAAAA Move Cursor into CGRAM (A: address)
#define LCD_DDRAM B7 // 1AAAAAAA Move Cursor to Display (A: address)
; Set data mode
#define DATA_MODE sbi _SFR_IO_ADDR(PORTB),6
; Set command mode
#define CMD_MODE cbi _SFR_IO_ADDR(PORTB),6
; Set enable state ON
#define EN_ON sbi _SFR_IO_ADDR(PORTD),4
; Set enable state OFF
#define EN_OFF cbi _SFR_IO_ADDR(PORTD),4
#define VOTAB_MAX 10 ; max. value of VOTab
; LCD contrast - OCR0A divider (TCC0B prescaler = 2)
.global VOTab
VOTab:
#if F_CPU >= 6000000
.byte 142 ; 0: 3497 Hz
.byte 113 ; 1: 4386 Hz
.byte 90 ; 2: 5495 Hz
.byte 72 ; 3: 6849 Hz
.byte 58 ; 4: 8475 Hz
.byte 46 ; 5: 10638 Hz
.byte 36 ; 6: 13514 Hz
.byte 29 ; 7: 16667 Hz
.byte 23 ; 8: 20833 Hz
.byte 18 ; 9: 26316 Hz
#else
.byte 71 ; 0: 3497 Hz
.byte 56 ; 1: 4386 Hz
.byte 45 ; 2: 5495 Hz
.byte 36 ; 3: 6849 Hz
.byte 29 ; 4: 8475 Hz
.byte 23 ; 5: 10638 Hz
.byte 18 ; 6: 13514 Hz
.byte 14 ; 7: 16667 Hz
.byte 11 ; 8: 20833 Hz
.byte 9 ; 9: 26316 Hz
#endif
; default font (every byte is 1 row of characters; only bits 0..4 are used)
.global FontDef
FontDef:
; 0 (8): sum (100, 0x84)
; 0 0 0 1 1 1 1 1
; 0 0 0 1 0 0 0 0
; 0 0 0 0 1 0 0 0
; 0 0 0 0 0 1 0 0
; 0 0 0 0 1 0 0 0
; 0 0 0 1 0 0 0 0
; 0 0 0 1 1 1 1 1
; 0 0 0 0 0 0 0 0
.byte 0x1f, 0x10, 0x08, 0x04, 0x08, 0x10, 0x1f, 0x00
; 1: backslash (60, 0x5C)
; 0 0 0 0 0 0 0 0
; 0 0 0 1 0 0 0 0
; 0 0 0 0 1 0 0 0
; 0 0 0 0 0 1 0 0
; 0 0 0 0 0 0 1 0
; 0 0 0 0 0 0 0 1
; 0 0 0 0 0 0 0 0
; 0 0 0 0 0 0 0 0
.byte 0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00
; 2: ~ wave (94, 0x7E)
; 0 0 0 0 0 0 0 0
; 0 0 0 0 0 0 0 0
; 0 0 0 0 1 1 0 1
; 0 0 0 1 0 1 1 0
; 0 0 0 0 0 0 0 0
; 0 0 0 0 0 0 0 0
; 0 0 0 0 0 0 0 0
; 0 0 0 0 0 0 0 0
.byte 0x00, 0x00, 0x0d, 0x16, 0x00, 0x00, 0x00, 0x00
; 3: pi (95, 0x7F)
; 0 0 0 0 0 0 0 0
; 0 0 0 0 0 0 0 0
; 0 0 0 1 1 1 1 1
; 0 0 0 0 1 0 1 0
; 0 0 0 0 1 0 1 0
; 0 0 0 0 1 0 1 0
; 0 0 0 1 0 0 1 1
; 0 0 0 0 0 0 0 0
.byte 0x00, 0x00, 0x1f, 0x0a, 0x0a, 0x0a, 0x13, 0x00
; 4: square root (96, 0x80)
; 0 0 0 0 0 0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 0 1 1 1 1 1
; 0 0 0 1 1 1 1 1
.byte 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f
; 7 (99, 0x83)
; 0 0 0 1 0 1 0 1
; 0 0 0 0 1 0 1 0
; 0 0 0 1 0 1 0 1
; 0 0 0 0 1 0 1 0
; 0 0 0 1 0 1 0 1
; 0 0 0 0 1 0 1 0
; 0 0 0 1 0 1 0 1
; 0 0 0 0 1 0 1 0
.byte 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a
.balign 2
; ----- font addresses
FontTab:
.word FontDef ; #define FONT_DEF 0 // default font
.word FontColL ; #define FONT_COLL 1 // columns from left
.word FontColR ; #define FONT_COLR 2 // columns from right
.word FontLine ; #define FONT_LINE 3 // lines
.word FontPix ; #define FONT_PIX 4 // pixel graphics
.balign 2
; ----------------------------------------------------------------------------
; Output nibble (takes 20 us)
; ----------------------------------------------------------------------------
; INPUT: R24 = data (bit 0..3 = nibble)
; DESTROYS: -
; ----------------------------------------------------------------------------
LCD_OutNibble:
; ----- clear output bits
cbi _SFR_IO_ADDR(PORTD),3 ; PD3: DB4
cbi _SFR_IO_ADDR(PORTD),2 ; PD2: DB5
cbi _SFR_IO_ADDR(PORTD),1 ; PD1: DB6
cbi _SFR_IO_ADDR(PORTD),0 ; PD0: DB7
; ----- set bits
sbrc r24,0
sbi _SFR_IO_ADDR(PORTD),3 ; PD3: DB4
sbrc r24,1
sbi _SFR_IO_ADDR(PORTD),2 ; PD2: DB5
sbrc r24,2
sbi _SFR_IO_ADDR(PORTD),1 ; PD1: DB6
sbrc r24,3
sbi _SFR_IO_ADDR(PORTD),0 ; PD0: DB7
; ----- enable pulse
EN_ON ; enable
; DESTROYS: -
rcall Wait10us ; delay 10 us
EN_OFF ; disable
; DESTROYS: -
rjmp Wait10us ; delay 10 us
; ----------------------------------------------------------------------------
; Write command (takes 140 us)
; ----------------------------------------------------------------------------
; INPUT: R24 = data
; DESTROYS: -
; ----------------------------------------------------------------------------
LCD_WriteCmd:
CMD_MODE ; switch to command mode
; LCD_OutByte must follow
; ----------------------------------------------------------------------------
; Output byte (takes 140 us)
; ----------------------------------------------------------------------------
; INPUT: R24 = data
; DESTROYS: -
; ----------------------------------------------------------------------------
LCD_OutByte:
swap r24 ; swap nibbles
; INPUT: R24 = data (bit 0..3 = nibble)
; DESTROYS: -
rcall LCD_OutNibble ; output high nibble
swap r24 ; swap nibbles back
; INPUT: R24 = data (bit 0..3 = nibble)
; DESTROYS: -
rcall LCD_OutNibble ; output low nibble
; DESTROYS: -
rjmp Wait100us ; delay 100 us
; ----------------------------------------------------------------------------
; Write data (takes 140 us)
; ----------------------------------------------------------------------------
; INPUT: R24 = data
; DESTROYS: -
; ----------------------------------------------------------------------------
LCD_WriteData:
DATA_MODE ; switch to data mode
rjmp LCD_OutByte ; output data byte
; ----------------------------------------------------------------------------
; Display character (takes 140 us)
; ----------------------------------------------------------------------------
; INPUT: R24 = character
; DESTROYS: -
; ----------------------------------------------------------------------------
.global DispChar
DispChar:
push r24
push r25
; ----- substitute character - default font
lds r25,SelFont ; selected font
cpi r25,FONT_DEF ; default font?
brne 3f ; no default font
cpi r24,0x5c ; backslash
brne 2f
ldi r24,CHAR_BACKSLASH ; 0x5c -> backslash
2: cpi r24,0x7e
brcs 8f
subi r24,0x7e - CHAR_WAVE
rjmp 8f
; ----- substitute character - graphics font
3: cpi r24,0x5c ; backslash
brne 4f
ldi r24,0x7c ; substitute by |
rjmp 8f
4: cpi r24,0x7b ; { (91)
brcs 8f ; not graphics character
breq 6f ; space
subi r24,0x7c ; graphics characters
rjmp 8f
6: ldi r24,' ' ; first graphics character is space
; INPUT: R24 = data
; DESTROYS: -
8: pop r25
rcall LCD_WriteData ; output data byte
; increase display X position
ldd r24,Y+DATA_POSX
inc r24 ; increase display X position
std Y+DATA_POSX,r24
pop r24
ret
; ----------------------------------------------------------------------------
; Set 8-bit interface (takes 10 ms)
; ----------------------------------------------------------------------------
; DESTROYS: R24
; ----------------------------------------------------------------------------
LCD_Set8bit:
ldi r24,B1+B0 ; (LCD_SETUP command + 8-bit interface) >> 4
LCD_Setbit:
; INPUT: R24 = data (bit 0..3 = nibble)
; DESTROYS: -
rcall LCD_OutNibble ; switch to 8-bit interface
; INPUT: R24 = numer of [ms]
; DESTROYS: -
ldi r24,10
rjmp Waitms ; delay 10 ms
; ----------------------------------------------------------------------------
; Restore LCD display
; ----------------------------------------------------------------------------
.global LCD_Restore
LCD_Restore:
; ----- start generator of LCD contrast control, update LCD contrast
rcall LCD_InitGen
; ----- LCD initialize (low voltage requires 2 initializations)
; DESTROYS: R31, R30, R24
rcall LCD_Init ; initialice LCD
; ----- restore font
lds r24,SelFont ; current font
rjmp SetFont2
; ----- refresh display
; rjmp Disp
; ----------------------------------------------------------------------------
; Initialize LCD display generator
; ----------------------------------------------------------------------------
.global LCD_InitGen
LCD_InitGen:
; ----- start generator of LCD contrast control
ldi r24,B6+2 ; toggle OC0A on compare match, mode CRC (top on OCRA)
out _SFR_IO_ADDR(TCCR0A),r24
; LCD_Update must follow
; ----------------------------------------------------------------------------
; Update LCD contrast by power voltage
; ----------------------------------------------------------------------------
; DESTROYS: R31, R30, R25..R20
; ----------------------------------------------------------------------------
;.global LCD_Update
;LCD_Update:
; set prescaler
ldi r24,2 ; prescaler 8, output sample frequency 8000000/8/(OCR0A+1)/2 = 2 kHz .. 500 kHz
out _SFR_IO_ADDR(TCCR0B),r24
; prepare required LCD contrast
ldd r24,Y+DATA_LCDVO ; user correction = 0..9
; LCD_SetVO must follow
; ----------------------------------------------------------------------------
; Set LCD contrast
; ----------------------------------------------------------------------------
; INPUT: R24 = contract 0..9
; ----------------------------------------------------------------------------
.global LCD_SetVO
LCD_SetVO:
; push registers
push r24
push r30
push r31
; limit minimum
tst r24 ; negative index?
brpl 2f
clr r24 ; minimal index 0
; limit maximum
2: cpi r24,VOTAB_MAX+1 ; maximum index
brcs 2f
ldi r24,VOTAB_MAX ; maximal index
; address in table
2: clr r31
mov r30,r24 ; contrast index
subi r30,lo8(-(VOTab))
sbci r31,hi8(-(VOTab))
; OCR0A divider
lpm r24,Z ; laod OCR0A divider
out _SFR_IO_ADDR(OCR0A),r24
; pop registers
pop r31
pop r30
pop r24
ret
; ----------------------------------------------------------------------------
; Update font
; ----------------------------------------------------------------------------
; INPUT: R24 = required font (FONT_*)
; DESTROYS: R31, R30, R25, R24
; ----------------------------------------------------------------------------
.global SetFont
SetFont:
lds r25,SelFont ; selected font
cp r24,r25 ; is required font already set?
breq LCD_SetFont9 ; font is already set
sts SelFont,r24 ; save new font
SetFont2:
add r24,r24 ; font index * 2
ldi r30,lo8(FontTab) ; font table
ldi r31,hi8(FontTab)
add r30,r24 ; add font index * 2
adc r31,R_ZERO
lpm r24,Z+ ; get font address
lpm r31,Z
mov r30,r24
rjmp LCD_SetFont
; ----------------------------------------------------------------------------
; Load fonts
; ----------------------------------------------------------------------------
; INTPUT: R31:R30 (Z) = font table (8 characters)
; DESTROYS: R31, R30, R25, R24
; ----------------------------------------------------------------------------
.global LCD_SetFontDef
LCD_SetFontDef:
ldi r30,lo8(FontDef) ; font table
ldi r31,hi8(FontDef)
sts SelFont,R_ZERO ; set font index
LCD_SetFont:
; ----- load custom characters
; INPUT: R24 = data
; DESTROYS: -
ldi r24,LCD_CGRAM
rcall LCD_WriteCmd ; set character generator start address 0
ldi r25,CHAR_NUM*8 ; number of bytes to send
2: lpm r24,Z+ ; load one byte
; INPUT: R24 = character or data
; DESTROYS: -
rcall LCD_WriteData ; output 1 byte
dec r25 ; byte counter
brne 2b ; next byte
LCD_SetFont9:
ret
; ----------------------------------------------------------------------------
; Initialize LCD display
; ----------------------------------------------------------------------------
; DESTROYS: R31, R30, R25, R24
; ----------------------------------------------------------------------------
; ADC convertor must be updated
.global LCD_Init
LCD_Init:
; ----- disable ouput
EN_OFF
; ----- wait for some time to LCD power up
; DESTROYS: R24
call Wait250ms ; wait 250 ms
; ----- set command mode
CMD_MODE
; ----- byte synchronisation using 8-bit interface - switch to 8-bit interface
; DESTROYS: R24
rcall LCD_Set8bit
rcall LCD_Set8bit
rcall LCD_Set8bit
; ----- switch to 4-bit interface
; DESTROYS: R24
ldi r24,B1 ; LCD_SETUP command >> 4
rcall LCD_Setbit
; ----- setup 4-bit interface, 2 rows, font 5x7
; INPUT: R24 = data
; DESTROYS: -
ldi r24,LCD_SETUP+B3
rcall LCD_WriteCmd
; ----- display off, cursor off, blinking off
; INPUT: R24 = data
; DESTROYS: -
ldi r24,LCD_DISPLAY
rcall LCD_WriteCmd
; ----- clear display
; DESTROYS: R24
ldi r24,LCD_CLEAR
rcall LCD_Home2
; ----- auto move cursor right
; INPUT: R24 = data
; DESTROYS: -
ldi r24,LCD_MOVE+B1
rcall LCD_WriteCmd
; ----- display on, cursor off, blinking off
; INPUT: R24 = data
; DESTROYS: -
ldi r24,LCD_DISPLAY+B2
rcall LCD_WriteCmd
; ----- load custom characters
; INTPUT: R31:R30 (Z) = font table (8 characters)
; DESTROYS: R31, R30, R25, R24
rcall LCD_SetFontDef
; ----- set cursor home position
std Y+DATA_POSX,R_ZERO ; clear display X position
ldi r24,LCD_HOME
LCD_Home2:
; INPUT: R24 = data
; DESTROYS: -
rcall LCD_WriteCmd ; write command
; INPUT: R24 = numer of [ms]
; DESTROYS: -
ldi r24,5
rjmp Waitms ; wait 5 ms
; ----------------------------------------------------------------------------
; Set display position
; ----------------------------------------------------------------------------
; INPUT: R24 = position 0..15, add ROW1 or ROW2
; DESTROYS: -
; ----------------------------------------------------------------------------
.global DispSetPos
DispSetPos:
push r24
push r25
mov r25,r24
andi r25,0x3f ; mask position X
std Y+DATA_POSX,r25 ; set new position X
ori r24,LCD_DDRAM
; INPUT: R24 = data
; DESTROYS: -
rcall LCD_WriteCmd
pop r25
pop r24
ret
; ----------------------------------------------------------------------------
; Set cursor to start or ROW2
; ----------------------------------------------------------------------------
; DESTROYS: -
; ----------------------------------------------------------------------------
.global DispSetRow2
DispSetRow2:
push r24
ldi r24,LCD_DDRAM+ROW2
rjmp DispSetRow1B
; ----------------------------------------------------------------------------
; Set cursor to start or ROW1
; ----------------------------------------------------------------------------
; DESTROYS: -
; ----------------------------------------------------------------------------
.global DispSetRow1
DispSetRow1:
push r24
ldi r24,LCD_DDRAM+ROW1
DispSetRow1B:
std Y+DATA_POSX,R_ZERO ; clear X position
; INPUT: R24 = data
; DESTROYS: -
rcall LCD_WriteCmd
pop r24
ret
; ----------------------------------------------------------------------------