-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphicsLCD.asm
2984 lines (2843 loc) · 119 KB
/
GraphicsLCD.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
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
;********************************************************************************************
;* Aiolos Project *
;* MSP Serial Terminal *
;********************************************************************************************
;* Graphics LCD Library for 480x320 colour LCD module. The code is made for R61581 *
;* controller IC, used on the colour LCD. (eBay store) *
;********************************************************************************************
.title "Aiolos Project: MSP Serial Terminal - Real Time Clock Library"
.tab 4
.cdecls C,LIST,"msp430.h" ; Include device header file
;============================================================================================
; DEFINITIONS - This section contains all necessary definition visible only to this file
;--------------------------------------------------------------------------------------------
LCDDataPrtH .equ 6 ;The port that holds the lower 8 data bus' bits
LCDDataPrtL .equ 5 ;The port that holds the higher 8 data bus' bits
LCDCtrlPrt .equ 4 ;The port that holds the control pins of the LCD
LCD_CS .equ BIT4 ;Mask for Chip Select pin
LCD_DC .equ BIT7 ;Mask for Control/Data pin
LCD_WR .equ BIT5 ;Mask for Write pin
LCD_RES .equ BIT3 ;Mask for Reset pin
LCD_RD .equ BIT1 ;Mask for Read pin
;Create the port mask for all MCD control pins
LCDCtrlALL .equ LCD_CS + LCD_DC + LCD_WR + LCD_RES + LCD_RD
LCDBLPort .equ 4 ;Port that holds the PWM for the backlight
LCD_BL .equ BIT6 ;Pin driving PWM for the backlight
DEFBKGRND .equ 00000h ;The default background colour
DEFFRGRND .equ 0FFFFh ;The default foreground colour
DEFFONT .equ FONT_SMALL ;The defautl font to be used
DEFBLVAL .equ 00000h ;The default value of backlight on first start
DEFBLSTEP .equ 00001h ;The default step to be used for backlight PWM
; transition
DEFCOUNTER .equ 00002h ;Transition at every PWM pulse
LCDBUFFLEN .equ 4096 ;Buffer size for designing strings, preparing data
; to LCD module, or read data from it
;============================================================================================
; LIBRARY DEFINITIONS - This section contains definitions, global to all program
;--------------------------------------------------------------------------------------------
PORTRAIT_TOPLEFT .equ 000h
PORTRAIT_BOTTOMLEFT .equ 080h
PORTRAIT_TOPRIGHT .equ 040h
PORTRAIT_BOTTOMRIGHT .equ 0C0h
PORTRAIT_MAXX .equ 0013Fh
PORTRAIT_MAXY .equ 001DFh
LANDSCAPE_TOPLEFT .equ 0A0h
LANDSCAPE_BOTTOMLEFT .equ 0E0h
LANDSCAPE_TOPRIGHT .equ 020h
LANDSCAPE_BOTTOMRIGHT .equ 060h
LANDSCAPE_MAXX .equ PORTRAIT_MAXY
LANDSCAPE_MAXY .equ PORTRAIT_MAXX
;-------------------------------< OctaPlot Arcs To Be Printed >-------------------------------
OP_BOTTOMPLUS .equ ~BIT0
OP_BOTTOMMINUS .equ ~BIT3
OP_TOPPLUS .equ ~BIT1
OP_TOPMINUS .equ ~BIT2
OP_LEFTPLUS .equ ~BIT5
OP_LEFTMINUS .equ ~BIT6
OP_RIGHTPLUS .equ ~BIT4
OP_RIGHTMINUS .equ ~BIT7
OP_TOPRIGHT90 .equ (OP_TOPPLUS & OP_RIGHTMINUS)
OP_TOPLEFT90 .equ (OP_TOPMINUS & OP_LEFTMINUS)
OP_BOTTOMRIGHT90 .equ (OP_BOTTOMPLUS & OP_RIGHTPLUS)
OP_BOTTOMLEFT90 .equ (OP_BOTTOMMINUS & OP_LEFTPLUS)
OP_LEFT180 .equ (OP_TOPLEFT90 & OP_BOTTOMLEFT90)
OP_RIGHT180 .equ (OP_TOPRIGHT90 & OP_BOTTOMRIGHT90)
OP_TOP180 .equ (OP_TOPLEFT90 & OP_TOPRIGHT90)
OP_BOTTOM180 .equ (OP_BOTTOMLEFT90 & OP_BOTTOMRIGHT90)
OP_CIRCLE .equ (OP_TOP180 & OP_BOTTOM180)
;-------------------------------------< Font Properties >-------------------------------------
FONT_PROPORTIONAL .equ BIT0
FONT_0A .equ BIT1
FONT_0D .equ BIT2
FONT_FORCEDY .equ BIT3 ;If there was not enough space for the character
;==< specify which must be global >==========================================================
.def PORTRAIT_TOPLEFT
.def PORTRAIT_BOTTOMLEFT
.def PORTRAIT_TOPRIGHT
.def PORTRAIT_BOTTOMRIGHT
.def LANDSCAPE_TOPLEFT
.def LANDSCAPE_BOTTOMLEFT
.def LANDSCAPE_TOPRIGHT
.def LANDSCAPE_BOTTOMRIGHT
.def LANDSCAPE_MAXX
.def LANDSCAPE_MAXY
.def PORTRAIT_MAXX
.def PORTRAIT_MAXY
.def OP_BOTTOMPLUS
.def OP_BOTTOMMINUS
.def OP_TOPPLUS
.def OP_TOPMINUS
.def OP_LEFTPLUS
.def OP_LEFTMINUS
.def OP_RIGHTPLUS
.def OP_RIGHTMINUS
.def OP_TOPRIGHT90
.def OP_TOPLEFT90
.def OP_BOTTOMRIGHT90
.def OP_BOTTOMLEFT90
.def OP_LEFT180
.def OP_RIGHT180
.def OP_TOP180
.def OP_BOTTOM180
.def OP_CIRCLE
.def FONT_PROPORTIONAL
;============================================================================================
; AUTO DEFINITIONS - This section contains definitions calculated by preprocessor, mainly
; according to the previously specified ones
;--------------------------------------------------------------------------------------------
; Lets specify some definitions for the LCD ports, according to the previous settings:
; LCDDataLDIR points to the direction register of the port pointed by LCDDataL
; LCDDataLIN points to the input register of the same port
; LCDDataLSEL points to the Selection register of the same port
; LCDDataLSEL2 points to the Selection2 register of the same port
; LCDDataLREN points to the Register Enable register of the same port
.if LCDDataPrtL == 1
LCDDataL .equ P1OUT
LCDDataLDIR .equ P1DIR
LCDDataLIN .equ P1IN
LCDDataLSEL .equ P1SEL
LCDDataLREN .equ P1REN
.elseif LCDDataPrtL = 2
LCDDataL .equ P2OUT
LCDDataLDIR .equ P2DIR
LCDDataLIN .equ P2IN
LCDDataLSEL .equ P2SEL
LCDDataLREN .equ P2REN
.elseif LCDDataPrtL = 3
LCDDataL .equ P3OUT
LCDDataLDIR .equ P3DIR
LCDDataLIN .equ P3IN
LCDDataLSEL .equ P3SEL
LCDDataLREN .equ P3REN
.elseif LCDDataPrtL = 4
LCDDataL .equ P4OUT
LCDDataLDIR .equ P4DIR
LCDDataLIN .equ P4IN
LCDDataLSEL .equ P4SEL
LCDDataLREN .equ P4REN
.elseif LCDDataPrtL = 5
LCDDataL .equ P5OUT
LCDDataLDIR .equ P5DIR
LCDDataLIN .equ P5IN
LCDDataLSEL .equ P5SEL
LCDDataLREN .equ P5REN
.elseif LCDDataPrtL = 6
LCDDataL .equ P6OUT
LCDDataLDIR .equ P6DIR
LCDDataLIN .equ P6IN
LCDDataLSEL .equ P6SEL
LCDDataLREN .equ P6REN
.elseif LCDDataPrtL = 7
LCDDataL .equ P7OUT
LCDDataLDIR .equ P7DIR
LCDDataLIN .equ P7IN
LCDDataLSEL .equ P7SEL
LCDDataLREN .equ P7REN
.elseif LCDDataPrtL = 8
LCDDataL .equ P8OUT
LCDDataLDIR .equ P8DIR
LCDDataLIN .equ P8IN
LCDDataLSEL .equ P8SEL
LCDDataLREN .equ P8REN
.else
.emsg "Error in LCDDataPrtL definition. Must be a number of digital port..."
.endif
; Same definitions apply to the Data high port, LCDDataH:
; LCDDataHDIR points to the direction register of the port pointed by LCDDataH
; LCDDataHIN points to the input register of the same port
; LCDDataHSEL points to the Selection register of the same port
; LCDDataHSEL2 points to the Selection2 register of the same port
; LCDDataHREN points to the Register Enable register of the same port
.if LCDDataPrtH == 1
LCDDataH .equ P1OUT
LCDDataHDIR .equ P1DIR
LCDDataHIN .equ P1IN
LCDDataHSEL .equ P1SEL
LCDDataHREN .equ P1REN
.elseif LCDDataPrtH == 2
LCDDataH .equ P2OUT
LCDDataHDIR .equ P2DIR
LCDDataHIN .equ P2IN
LCDDataHSEL .equ P2SEL
LCDDataHREN .equ P2REN
.elseif LCDDataPrtH == 3
LCDDataH .equ P3OUT
LCDDataHDIR .equ P3DIR
LCDDataHIN .equ P3IN
LCDDataHSEL .equ P3SEL
LCDDataHREN .equ P3REN
.elseif LCDDataPrtH == 4
LCDDataH .equ P4OUT
LCDDataHDIR .equ P4DIR
LCDDataHIN .equ P4IN
LCDDataHSEL .equ P4SEL
LCDDataHREN .equ P4REN
.elseif LCDDataPrtH == 5
LCDDataH .equ P5OUT
LCDDataHDIR .equ P5DIR
LCDDataHIN .equ P5IN
LCDDataHSEL .equ P5SEL
LCDDataHREN .equ P5REN
.elseif LCDDataPrtH == 6
LCDDataH .equ P6OUT
LCDDataHDIR .equ P6DIR
LCDDataHIN .equ P6IN
LCDDataHSEL .equ P6SEL
LCDDataHREN .equ P6REN
.elseif LCDDataPrtH == 7
LCDDataH .equ P7OUT
LCDDataHDIR .equ P7DIR
LCDDataHIN .equ P7IN
LCDDataHSEL .equ P7SEL
LCDDataHREN .equ P7REN
.elseif LCDDataPrtH == 8
LCDDataH .equ P8OUT
LCDDataHDIR .equ P8DIR
LCDDataHIN .equ P8IN
LCDDataHSEL .equ P8SEL
LCDDataHREN .equ P8REN
.else
.emsg "Error in LCDDataPrtH definition. Must be the number of a digital port..."
.endif
; Next are the difinitions for LCD Control port:
; LCDCtrlDIR points to the direction register of the port pointed by LCDCtrl
; LCDCtrlIN points to the input register of the same port
; LCDCtrlSEL points to the Selection register of the same port
; LCDCtrlSEL2 points to the Selection2 register of the same port
; LCDCtrlREN points to the Register Enable register of the same port
.if LCDCtrlPrt == 1
LCDCtrl .equ P1OUT
LCDCtrlDIR .equ P1DIR
LCDCtrlIN .equ P1IN
LCDCtrlSEL .equ P1SEL
LCDCtrlREN .equ P1REN
.elseif LCDCtrlPrt == 2
LCDCtrl .equ P2OUT
LCDCtrlDIR .equ P2DIR
LCDCtrlIN .equ P2IN
LCDCtrlSEL .equ P2SEL
LCDCtrlREN .equ P2REN
.elseif LCDCtrlPrt == 3
LCDCtrl .equ P3OUT
LCDCtrlDIR .equ P3DIR
LCDCtrlIN .equ P3IN
LCDCtrlSEL .equ P3SEL
LCDCtrlREN .equ P3REN
.elseif LCDCtrlPrt == 4
LCDCtrl .equ P4OUT
LCDCtrlDIR .equ P4DIR
LCDCtrlIN .equ P4IN
LCDCtrlSEL .equ P4SEL
LCDCtrlREN .equ P4REN
.elseif LCDCtrlPrt == 5
LCDCtrl .equ P5OUT
LCDCtrlDIR .equ P5DIR
LCDCtrlIN .equ P5IN
LCDCtrlSEL .equ P5SEL
LCDCtrlREN .equ P5REN
.elseif LCDCtrlPrt == 6
LCDCtrl .equ P6OUT
LCDCtrlDIR .equ P6DIR
LCDCtrlIN .equ P6IN
LCDCtrlSEL .equ P6SEL
LCDCtrlREN .equ P6REN
.elseif LCDCtrlPrt == 7
LCDCtrl .equ P7OUT
LCDCtrlDIR .equ P7DIR
LCDCtrlIN .equ P7IN
LCDCtrlSEL .equ P7SEL
LCDCtrlREN .equ P7REN
.elseif LCDCtrlPrt == 8
LCDCtrl .equ P8OUT
LCDCtrlDIR .equ P8DIR
LCDCtrlIN .equ P8IN
LCDCtrlSEL .equ P8SEL
LCDCtrlREN .equ P8REN
.else
.emsg "Error in LCDCtrlPrt definition. Must be an output register of a digital port..."
.endif
;Now we need to setup definitions for the LCD Backlight
;LCDBLOUT : Output register of port that the control pin of LCD Backlight is connected to
;LCDBLDIR : The direction register of the port the LCD Backlight control pin is connected to
;LCDBLIN : The input register of the same port
;LCDBLSEL : The special function select register of the port in question
;LCDBLREN : The Resistor Enable register of the port
;BLCTL : The TxCTL register used for the timer of PWM
;BLCCTL : The TxCCTLx register of PWM creation.
;BLCCR0 : The TxCCTL0 register of the PWM period setting
;BLCCR : The TxCCRx register, counter of PWM
;BLIV : The interrupt vector's ID for the backlight capture/compare interrupt
;BL_VECTOR : The vector address of the corresponding Timer
.if LCDBLPort == 1
LCDBLOUT .equ P1OUT
LCDBLDIR .equ P1DIR
LCDBLIN .equ P1IN
LCDBLSEL .equ P1SEL
LCDBLREN .equ P1REN
.if (LCD_BL == BIT1) || (LCD_BL == BIT5)
BLCTL .equ TACTL
BLCCTL .equ TACCTL0
BLCCR0 .equ TACCR0
BLCCR .equ TACCR0
BLIV .equ TAIV_NONE
BL_VECTOR .equ TIMERA0_VECTOR
.elseif (LCD_BL == BIT2) || (LCD_BL == BIT6)
BLCTL .equ TACTL
BLCCTL .equ TACCTL1
BLCCR0 .equ TACCR0
BLCCR .equ TACCR1
BLIV .equ TAIV_TACCR1
BL_VECTOR .equ TIMERA1_VECTOR
.elseif (LCD_BL == BIT3) || (LCD_BL == BIT7)
BLCTL .equ TACTL
BLCCTL .equ TACCTL2
BLCCR0 .equ TACCR0
BLCCR .equ TACCR2
BLIV .equ TAIV_TACCR2
BL_VECTOR .equ TIMERA1_VECTOR
.endif
.elseif LCDBLPort == 2
LCDBLOUT .equ P2OUT
LCDBLDIR .equ P2DIR
LCDBLIN .equ P2IN
LCDBLSEL .equ P2SEL
LCDBLREN .equ P2REN
.if (LCD_BL == BIT2) || (LCD_BL == BIT7)
BLCTL .equ TACTL
BLCCTL .equ TACCTL0
BLCCR0 .equ TACCR0
BLCCR .equ TACCR0
BLIV .equ TAIV_NONE
BL_VECTOR .equ TIMERA0_VECTOR
.elseif (LCD_BL == BIT3)
BLCTL .equ TACTL
BLCCTL .equ TACCTL1
BLCCR0 .equ TACCR0
BLCCR .equ TACCR1
BLIV .equ TAIV_TACCR1
BL_VECTOR .equ TIMERA1_VECTOR
.elseif (LCD_BL == BIT4)
BLCTL .equ TACTL
BLCCTL .equ TACCTL2
BLCCR0 .equ TACCR0
BLCCR .equ TACCR2
BLIV .equ TAIV_TACCR2
BL_VECTOR .equ TIMERA1_VECTOR
.endif
.elseif LCDBLPort == 3
LCDBLOUT .equ P3OUT
LCDBLDIR .equ P3DIR
LCDBLIN .equ P3IN
LCDBLSEL .equ P3SEL
LCDBLREN .equ P3REN
.elseif LCDBLPort == 4
LCDBLOUT .equ P4OUT
LCDBLDIR .equ P4DIR
LCDBLIN .equ P4IN
LCDBLSEL .equ P4SEL
LCDBLREN .equ P4REN
.if (LCD_BL == BIT0)
BLCTL .equ TBCTL
BLCCTL .equ TBCCTL0
BLCCR0 .equ TBCCR0
BLCCR .equ TBCCR0
BLIV .equ TBIV_NONE
BL_VECTOR .equ TIMERB0_VECTOR
.elseif (LCD_BL == BIT1)
BLCTL .equ TBCTL
BLCCTL .equ TBCCTL1
BLCCR0 .equ TBCCR0
BLCCR .equ TBCCR1
BLIV .equ TBIV_TBCCR1
BL_VECTOR .equ TIMERB1_VECTOR
.elseif (LCD_BL == BIT2)
BLCTL .equ TBCTL
BLCCTL .equ TBCCTL2
BLCCR0 .equ TBCCR0
BLCCR .equ TBCCR2
BLIV .equ TBIV_TBCCR2
BL_VECTOR .equ TIMERB1_VECTOR
.elseif (LCD_BL == BIT3)
BLCTL .equ TBCTL
BLCCTL .equ TBCCTL3
BLCCR0 .equ TBCCR0
BLCCR .equ TBCCR3
BLIV .equ TBIV_TBCCR3
BL_VECTOR .equ TIMERB1_VECTOR
.elseif (LCD_BL == BIT4)
BLCTL .equ TBCTL
BLCCTL .equ TBCCTL4
BLCCR0 .equ TBCCR0
BLCCR .equ TBCCR4
BLIV .equ TBIV_TBCCR4
BL_VECTOR .equ TIMERB1_VECTOR
.elseif (LCD_BL == BIT5)
BLCTL .equ TBCTL
BLCCTL .equ TBCCTL5
BLCCR0 .equ TBCCR0
BLCCR .equ TBCCR5
BLIV .equ TBIV_TBCCR5
BL_VECTOR .equ TIMERB1_VECTOR
.elseif (LCD_BL == BIT6)
BLCTL .equ TBCTL
BLCCTL .equ TBCCTL6
BLCCR0 .equ TBCCR0
BLCCR .equ TBCCR6
BLIV .equ TBIV_TBCCR6
BL_VECTOR .equ TIMERB1_VECTOR
.endif
.elseif LCDBLPort == 5
LCDBLOUT .equ P5OUT
LCDBLDIR .equ P5DIR
LCDBLIN .equ P5IN
LCDBLSEL .equ P5SEL
LCDBLREN .equ P5REN
.elseif LCDBLPort == 6
LCDBLOUT .equ P6OUT
LCDBLDIR .equ P6DIR
LCDBLIN .equ P6IN
LCDBLSEL .equ P6SEL
LCDBLREN .equ P6REN
.elseif LCDBLPort == 7
LCDBLOUT .equ P7OUT
LCDBLDIR .equ P7DIR
LCDBLIN .equ P7IN
LCDBLSEL .equ P7SEL
LCDBLREN .equ P7REN
.elseif LCDBLPort == 8
LCDBLOUT .equ P8OUT
LCDBLDIR .equ P8DIR
LCDBLIN .equ P8IN
LCDBLSEL .equ P8SEL
LCDBLREN .equ P8REN
.else
.emsg "Error in LCDBLPort definition. Must be the number of a port of the processor..."
.endif
;==< Public Definitions >====================================================================
.if $isdefed("BL_VECTOR") == 0
BL_VECTOR .equ RESERVED0_VECTOR
.endif
.if $isdefed("BLIV") == 0
BLIV .equ TAIV_NONE
.endif
.def BL_VECTOR ;Vector address for timer to be used
.def BLIV ;The associated vector value
;============================================================================================
; VARIABLES - This section contains local variables
;--------------------------------------------------------------------------------------------
.sect ".bss"
.align 1
; The PWM smooth transition is made by usage of a timer counter interrupt. In
; order for the value to be smoothly changed, there are three available variables
; BLCurVal which holds the current value of PWM setting, BLMaxVal which is the
; value the PWM subsystem must reach and the BLStep which holds the number of
; change of PWM, that is a PWM step. The step is a signed value.
; Two more variables define how fast the transition is applied. The first is
; BLMaxCntr holds the number of repetitions before PWM changes by one step and
; BLCounter holds the current number of repetitions performed before a PWM change
BLMaxVal: .space 2 ;Holds the maximum value of the backlight % for PWM
BLCurVal: .space 2 ;Holds the current value of the backlight % for PWM
BLMaxCntr: .space 2 ;Holds te maximum number of repeat counter for PWM change
BLCounter: .space 2 ;Holds the current value of repeat counter for PWM change
BLStep: .space 2 ;The increment/decrement step of the backlight value,
; during transition
LCDMaxX: .space 2 ;Holds the maximum X value for the current screen
; orientation
LCDMaxY: .space 2 ;Holds the maximum Y value for the current screen
; orientation
LCDFlags: .space 2 ;Holds some flags for the status of the LCD module
ORIENTFLG .equ BIT0 ;Bit 0 of LCDFlags expresses the orientation:
; 0: Portrait, 1: Landscape
SWAPXFLG .equ BIT1 ;It expresses if SetRegion exchanged X Axis registers
; 0: No swap performed, 1: XAxis registers swapped
SWAPYFLG .equ BIT2 ;It expresses if SetRegion exchanged Y Axis registers
; 0: No swap performed, 1: YAxis registers swapped
READLAST .equ BIT3 ;Set when this is the final block of buffer to be read
BkGrndClr: .space 2 ;The background colour for text
FrGrndClr: .space 2 ;The foreground colour for text
CurFontIdx: .space 2 ;Current font index
CurFontPtr: .space 2 ;Current font pointer entry to FontsTbl
FontProps: .space 2 ;Font properties to be used (Flags)
CurXPos: .space 2 ;The text cursor's X position in pixels
CurYPos: .space 2 ;The text cursor's Y position in pixels
TxtWinL: .space 2 ;The text window's left border
TxtWinR: .space 2 ;The text window's right border
TxtWinT: .space 2 ;The text window's top border
TxtWinB: .space 2 ;The text window's bottom border
ImgBuffer: .space LCDBUFFLEN +2 ;Buffer for prepearing strings (2 bytes more for ease of
; algorythm design)
;==< specify which must be global >==========================================================
; .def DelayMax
;==< referenced variables defined in other files >===========================================
.ref SmallFont ;Small Font's data
.ref SmallFontProp ;Small Font's glyph widths for using is as a proportional
.ref SMALLFONTH ;Small Font's height
.ref SMALLFONTW ;Small Font's width as a monospace (fixed size)
.ref SMALLFONTL ;Small Font's glyph length in bytes
.ref SMALLFONTMINCHAR;Small Font's first available character
.ref SMALLFONTMAXCHAR;Small Font's last available character
.ref SevenSegFont ;Seven Segment big font's data
.ref SevenSegProp ;Seven Segment big font's proportional widths
.ref SEVENSEGFONTH ;Seven Segment big font's glyph height
.ref SEVENSEGFONTW ;Seven Segment big font's glyph width
.ref SEVENSEGFONTL ;Seven Segment big font's glyph length in bytes
.ref SEVENSEGMINCHAR ;Seven Segment big font's first available character
.ref SEVENSEGMAXCHAR ;Seven Segment big font's last available character
.ref BigFont ;Big font's data
.ref BigFontProp ;Big font's proportional glyph widths array
.ref BIGFONTH ;Big font's glyph height
.ref BIGFONTW ;Big font's glyph width
.ref BIGFONTL ;Big font's glyph length in bytes
.ref BIGFONTMINCHAR ;Big font's first available character
.ref BIGFONTMAXCHAR ;Big font's last available character
.ref Inconsola ;Inconsola font's data
.ref InconsolaProp ;Inconsola font's proportional glyph widths array
.ref INCONSOLAH ;Inconsola font's glyph height
.ref INCONSOLAW ;Inconsola font's glyph width
.ref INCONSOLAL ;Inconsola font's glyph length in bytes
.ref INCONSOLAMINCHAR;Inconsola font's first available character
.ref INCONSOLAMAXCHAR;Inconsola font's last available character
;============================================================================================
; CONSTANTS - This section contains constant data written in Flash (.const section)
;--------------------------------------------------------------------------------------------
.sect ".const"
.align 1
InitLCDTbl:
.byte 080h,00Ah,06Bh ;Delay 5ms
.byte 082h ;Lower Reset pin
.byte 080h,014h,0D6h ;Delay 10ms
.byte 083h ;Raise Reset pin
.byte 080h,061h,02Ah ;Delay 50ms
.byte 000h,0FFh ;Dummy command
.byte 000h,0FFh ;Dummy command
.byte 080h,00Ah,06Bh ;Delay 5ms
.byte 000h,0FFh ;Dummy command
.byte 000h,0FFh ;Dummy command
.byte 000h,0FFh ;Dummy command
.byte 000h,0FFh ;Dummy command
.byte 080h,014h,0D6h ;Delay 10ms
.byte 001h,0B0h,000h ;Manufacturer Command Access Protect: Off
.byte 004h,0B3h,002h,000h,000h,010h ;Frame Memory Access & I/face setting
.byte 001h,0B4h,000h ;Display Mode & Frame Memory Write
.byte 008h,0C0h,013h,03Bh,000h ;Panel Driving setting
.byte 000h,000h,001h,000h,043h
.byte 004h,0C1h,008h,015h,008h,008h ;Normal Mode Display Timing
.byte 004h,0C4h,015h,003h,003h,001h ;Source/VCOM/Gate Driving Timing
.byte 001h,0C6h,002h ;Interface setting
.byte 014h,0C8h,00Ch,005h,00Ah,06Bh ;Gamma setting
.byte 004h,006h,015h,010h,000h,031h
.byte 010h,015h,006h,064h,00Dh,00Ah
.byte 005h,00Ch,031h,000h
.byte 001h,036h,0A0h ;Set Address Mode (Landscape, Top, Left)
.byte 001h,03Ah,055h ;Set Pixel Format
; .byte 000h,038h ;Exit Idle Mode
.byte 004h,0D0h,007h,007h,014h,0A2h ;Power setting
.byte 003h,0D1h,003h,05Ah,010h ;VCOM setting
.byte 003h,0D2h,003h,004h,004h ;Poer Setting for Normal Mode
.byte 000h,011h ;Exit Sleep Mode
.byte 080h,0FAh,000h ;Delay 120ms
.byte 004h,02Ah,000h,000h,001h,0DFh ;Set Column Address
.byte 004h,02Bh,000h,000h,001h,03Fh ;Set Page Address
.byte 080h,0D0h,055h ;Delay 100ms
.byte 000h,029h ;Set Display On
.byte 080h,00Ah,06Bh ;Delay 5ms
.byte 000h,02Ch ;Write Memory Start
.byte 080h,03Eh,080h ;Delay 30ms
.byte 0FFh ;End of initialisation sequence
;The table that follows contains data for each font that can be used. Each table
; entry contains 5 elements: The address of the font data, the address of the width
; data if this font can be used as a proportional one, the width and the height of
; each glyph and the length of each glyph in bytes. Lets define some offsets for
; manipulating the table data
FTbl_ADDR .equ 0 ;Offset for reading the font's address
FTbl_PROP .equ 4 ;Offset for proportional font's width values
FTbl_WIDTH .equ 8 ;Offset for reading the width of a glyph
FTbl_HEIGHT .equ 10 ;Offset for reading the height of a glyph
FTbl_GLEN .equ 12 ;Offset for reading the length of a glyph in bytes
FTbl_MINCHAR .equ 14 ;Offset for reading the first available character
FTbl_MAXCHAR .equ 16 ;Offset for reading the last available character
FTbl_SIZE .equ 18 ;The size of an entry of this table
FTbl_MAXINDEX .equ 3 ;The maximum entry number that can be used
FONT_SMALL .equ 0 ;Table index for small font's data
FONT_BIG .equ 1 ;Table index for big font's data
FONT_INCONSOLA .equ 2 ;Table index for inconsola font's data
FONT_7SEG .equ 3 ;Table index for seven segment big font's data
.align 1 ;Table must be word aligned
FontsTbl: .long SmallFont ;Small font's elements
.long SmallFontProp
.word SMALLFONTW
.word SMALLFONTH
.word SMALLFONTL
.word SMALLFONTMINCHAR
.word SMALLFONTMAXCHAR +1
.long BigFont ;Big font's elements
.long BigFontProp
.word BIGFONTW
.word BIGFONTH
.word BIGFONTL
.word BIGFONTMINCHAR
.word BIGFONTMAXCHAR +1
.long Inconsola ;Inconsola font's elements
.long InconsolaProp
.word INCONSOLAW
.word INCONSOLAH
.word INCONSOLAL
.word INCONSOLAMINCHAR
.word INCONSOLAMAXCHAR +1
.long SevenSegFont ;Seven segment font's elements
.long SevenSegProp
.word SEVENSEGFONTW
.word SEVENSEGFONTH
.word SEVENSEGFONTL
.word SEVENSEGMINCHAR
.word SEVENSEGMAXCHAR +1
;============================================================================================
; PROGRAM FUNCTIONS
;--------------------------------------------------------------------------------------------
;--< Some of the labels must be available to other files >-----------------------------------
.def BLFadeISR ;Interrupt Service Routine for smooth backlight
; level transition
.def InitLCDPorts ;Initialises the ports for LCD communication
.def WriteLCDData ;Writes data to LCD module
.def LCDStartData ;Puts the LCD in pixel write data mode
.def LCDContData ;Puts the LCD in pixel write data mode to
; continue writing from the last used address
.def WriteLCDCmd ;Writes command to LCD module
.def WriteLCD ;Writes data/command to LCD module
.def ClearScreen ;Fills the whole screen with a colour
.def FillRegion ;Fills R14 pixels with colour R15
.def FillRect ;Fills a whole rectangle
.def SetOrientation ;Sets the orientation of the Frame Memory
.def LCDSetPageAddr ;Sets the row of the next pixel to be altered
.def LCDSetColAddr ;Sets the column address of the next pixel
.def LCDSetRegion ;Selects a whole region (page and column)
.def ReadLCD ;Reads data from LCD module. Sets up the bus
.def ReadNextLCD ;Reads data from LCD without setting up the bus
.def InitLCD ;Initialises the LCD module
.def DrawLine ;Draws a line on screen
.def DrawRect ;Draws an empty rectangle
.def DrawRoundRect ;Draws an empty rectangle with rounded corners
.def SetHScroll ;Sets the scroll region
.def HScroll ;Sets the scroll position
.def Plot ;Plots a pixel
.def DrawArcs ;Draws arcs of a circle
.def SetTextRegion ;Sets both text area and LCD graphical region
.def SetTextWindow ;Sets the valid text window that can be used for
; text drawing
.def GetTextWindow ;Gets the current text window that can be used for
; text drawing
.def Text2Region ;Selects the region to be used in LCD module by
; the coordinates of the currently set Text region
.def SetBkGrnd ;Sets the background colour of the text
.def GetBkGrnd ;Gets the background colour of the text
.def SetFrGrnd ;Sets the foreground colour of the text
.def GetFrGrnd ;Gets the foreground colour of the text
.def SetFont ;Sets the font to be used for text printing
.def GetFont ;Gets the currently selected font used for text
; printing
.def SetTxtXPos ;Sets the X position of the text cursor on screen
.def GetTxtXPos ;Gets the X position of the text cursor on screen
.def SetTxtYPos ;Sets the Y position of the text cursor on screen
.def GetTxtYPos ;Gets the Y position of the text cursor on screen
.def GetTxtPos ;Gets the coordinates of the text cursor on screen
.def SetTxtXRel ;Sets the X position of the text cursor relative
; to the left text window border
.def SetTxtYRel ;Sets the Y position of the text cursor relative
; to the top text window border
.def SetPropFont ;Makes use of a font as proportional
.def SetFixedFont ;Makes use of a font as fixed size
.def GetPropFont ;Returns the type of font used (proportional or
; not)
.def ScrollTextUp ;Scrolls the text area up by one character line
.def PrintChr ;Prints a character on screen, using the selected
; font
.def GetEndOfScreen ;Reads the "EndOfScreen" flag after printing a
; character
.def PrintStr ;Prints a whole ASCIIZ string
.def CalcFont ;Font proportional caclulator
.def LCDBackLightOff ;Switches off the backlight without using timer
.def LCDBackLightPWM ;Enables PWM usage for backlight
.def LCDBackLightOn ;Switches on the backlight without using timer
.def LCDBackLightSet ;Sets a new value of backlight and starts the
; smooth level transition
.def FONT_SMALL ;The small font's index in fonts table
.def FONT_BIG ;The big font's index in fonts table
.def FONT_INCONSOLA ;The inconsola font's index in fonts table
.def FONT_7SEG ;The big seven segment font's index
;==< Interrupt Service Routines >============================================================
.text ;Place program in ROM (Flash)
.align 1
;==< Interrupt Service Routines >============================================================
BLFadeISR:
; Helps for a smooth transition of backlight luminocity. When there is a new set of backlight
; the interrupt is enabled. Every single pulse of PWM generated, triggers this interrupt. Its
; function is to set the new value to a bigger or smaller number, according to the willing
; step. If the wanted limit of PWM is reached, the interrupt is automatically disabled
; Input: None
; Output: None
; Registers Used: None
; Registers Altered: None, No flags affected
; Stack Usage: None
; Depend On Defs: BLCCR, BLCCTL
; Depend On Vars: BLCurVal, BLMaxVal, BLStep
; Depend On Funcs: None
DEC &BLCounter ;Decrement repetition counter by one
JC BLISRTerm ;Time to change value? No => just exit, nothing to
; do
;else, perform a PWM step
MOV &BLMaxCntr,&BLCounter ;Set the counter value for the next PWM step
ADD &BLStep,&BLCCR ;Add the signed step value to current backlight
; level (associated Timer Capture Compare)
CMP #00000h,&BLStep ;Is the step positive or negative?
JN BLISRNeg ;Negative => BLISRNeg
; Using positive step value
BLISRPos: CMP &BLMaxVal,&BLCCR ;Is the new value out of limit?
JGE BLISREnd ;Yes => End transition
MOV &BLCCR,&BLCurVal ;else, Just store the new value and
BLISRTerm: RETI ;exit interrupt service routine
; Using negative step value
BLISRNeg: CMP &BLCCR,&BLMaxVal ;Is the new value out of bounds?
JL BLISRExit ;No => Just store and exit...
BLISREnd: MOV &BLMaxVal,&BLCCR ;else, backlight value to limit
BIC #CCIE,&BLCCTL ;Disable interrupt of backlight transition
BLISRExit: MOV &BLCCR,&BLCurVal ;Store the current level value
RETI ;and exit
;-------------------------------------------
;==< Main Program >==========================================================================
InitLCDPorts:
; Initializes the port pins the LCD Module is connected. Control bus of the LCD module is
; used as output, all its pins are in logic high to make LCD inactive, and the LCD data bus
; becomes input with all its internal pull-up resistors activated.
; Input: None
; Output: None
; Registers Used: None
; Registers Altered: None, No flags affected
; Stack Usage: None
; Depend On Defs: LCDCtrl, LCDCtrlALL, LCDCtrlDIR, LCDDataH, LCDDataHDIR, LCDDataHRES,
; LCDDataL, LCDDataLDIR, LCDDataLRES
; Depend On Vars: None
; Depend On Funcs: None
BIC.B #LCD_BL,&LCDBLOUT ;Going to switch off LCD Backlight
BIS.B #LCD_BL,&LCDBLDIR ;The pin is an output (for now)
BIS.B #LCDCtrlALL,&LCDCtrl ;LCD Control pins must be all high when activated
BIS.B #LCDCtrlALL,&LCDCtrlDIR ;Also they must be all outputs
MOV.B #0FFh,&LCDDataLDIR ;LCD Data ports must be outputs. They are going to
MOV.B #0FFh,&LCDDataHDIR ; be used as bidirectional!
MOV.B #000h,&LCDDataL ;Lower all data pins (Uses the constant generator
MOV.B #000h,&LCDDataH ; to read 000h in less CPU cycles)
RET
;-------------------------------------------
LCDContData:
; Puts the LCD in the mode that every next data transaction is a colour of a pixel. It uses
; write_memory_continue LCD command
; Input: Carry Flag: 0 => Do not disable the LCD CS after reading
; 1 => Disable the LCD CS after reading
; Output: None
; Registers Used: R15
; Registers Altered: R15 -> Contains the write_memory_continue command, No flags are
; modified
; Stack Usage: None
; Depend On Defs: None
; Depend On Vars: None
; Depend On Funcs: WriteLCDCmd, WriteLCDData8
MOV.B #03Ch,R15 ;write_memory_start command
JMP WriteLCDCmd ;Send the command
;-------------------------------------------
LCDStartData:
; Puts the LCD in the mode that every next data transaction is a colour of a pixel. It uses
; write_memory_start LCD command
; Input: Carry Flag: 0 => Do not disable the LCD CS after reading
; 1 => Disable the LCD CS after reading
; Output: None
; Registers Used: R15
; Registers Altered: R15 -> Contains the write_memory_start command, No flags are modified
; Stack Usage: None
; Depend On Defs: None
; Depend On Vars: None
; Depend On Funcs: WriteLCDCmd, WriteLCDData8
MOV.B #02Ch,R15 ;write_memory_start command
; JMP WriteLCDCmd ;Send the command
;-------------------------------------------
WriteLCDCmd:
; Sends a command byte to the LCD module. It expects the direction of data ports to output
; (from MPU to LCD), as a command always is on that direction.
; Input: R15: contains the data to be sent,
; Carry Flag: 0 => Keep CS low (more data to send on the same
; transaction), 1 => Raise CS (No more data to send)
; Output: None
; Registers Used: R15
; Registers Altered: None, No flags affected
; Stack Usage: None
; Depend On Defs: LCD_CS, LCD_DC, LCD_WR, LCDCtrl, LCDDataH, LCDDataL
; Depend On Vars: None
; Depend On Funcs: WriteLCD
BIC.B #LCD_DC,&LCDCtrl ;Setup D/C low to send a command to LCD
JMP WriteLCD ;Send the command
;-------------------------------------------
WriteLCDData:
; Sends a data byte to the LCD module. It expects the data port direction to be output, as
; it is a following transaction to a WriteLCDCmd.
; Input: R15: contains the data to be sent,
; Carry Flag: 0 => Keep CS low (more data to send on the same
; transaction), 1 => Raise CS (No more data to send)
; Output: None
; Registers Used: R15
; Registers Altered: None, No flags affected
; Stack Usage: None
; Depend On Defs: LCD_CS, LCD_DC, LCD_WR, LCDCtrl, LCDDataH, LCDDataL
; Depend On Vars: None
; Depend On Funcs: WriteLCD
BIS.B #LCD_DC,&LCDCtrl ;Setup D/C high to send a data word to LCD
; JMP WriteLCD ;Since WriteLCD follows in the code there is no
; need to execute this operand
;-------------------------------------------
WriteLCD:
; Sends a word to the LCD wether it is command or data. DC pin is previously set to valid
; logic level to express if this byte corresponds to command or data
; Input: R15: contains the data to be sent,
; Carry Flag: 0 => Keep CS low (more data to send on the same
; transaction), 1 => Raise CS (No more data to send)
; Output: None
; Registers Used: R15
; Registers Altered: None, No flags affected
; Stack Usage: None
; Depend On Defs: LCD_CS, LCD_WR, LCDCtrl, LCDDataH, LCDDataL
; Depend On Vars: None
; Depend On Funcs: None
BIC.B #LCD_CS+LCD_WR,&LCDCtrl ;Lower CS and WR to enable LCD in Read mode
MOV.B R15,&LCDDataL ;Set the lower byte of data
SWPB R15 ;Swap the bytes in order to...
MOV.B R15,&LCDDataH ;... set the higher byte of the data
BIS.B #LCD_WR,&LCDCtrl ;Bring WR signal high to make the transaction
SWPB R15 ;Swap the bytes to bring R15 to its original
; state
JNC WL_Exit ;Is Carry Flag cleared? => Do not raise CS
BIS.B #LCD_CS,&LCDCtrl ;else, Disable LCD module.
WL_Exit: RET
;-------------------------------------------
WriteLCDData8:
; Sends a data byte to the LCD module. It expects the data port direction to be output, as
; it is a following transaction to a WriteLCDCmd. Also, it expects the higher byte of the
; LCD Data bus to be zeroed.
; Input: R15: contains the data to be sent (only the lower byte),
; Carry Flag: 0 => Keep CS low (more data to send on the same
; transaction), 1 => Raise CS (No more data to send)
; Output: None
; Registers Used: R15
; Registers Altered: None, No flags affected
; Stack Usage: None
; Depend On Defs: LCD_CS, LCD_DC, LCD_WR, LCDCtrl, LCDDataL
; Depend On Vars: None
; Depend On Funcs: WriteLCD
BIS.B #LCD_DC,&LCDCtrl ;Setup D/C high to send a data word to LCD
; JMP WriteLCD8 ;Since WriteLCD8 follows in the code there is
; no need to execute this operand
;-------------------------------------------
WriteLCD8:
; Sends a byte to the LCD wether it is command or data. DC pin is previously set to valid
; logic level to express if this byte corresponds to command or data. Also, it expects
; the higher byte of LCD Data bus be zeroed earlier.
; Input: R15: contains the data to be sent (only the lower byte),
; Carry Flag: 0 => Keep CS low (more data to send on the same
; transaction), 1 => Raise CS (No more data to send)
; Output: None
; Registers Used: R15
; Registers Altered: None, No flags affected
; Stack Usage: None
; Depend On Defs: LCD_CS, LCD_WR, LCDCtrl, LCDDataL
; Depend On Vars: None
; Depend On Funcs: None
BIC.B #LCD_CS+LCD_WR,&LCDCtrl ;Lower CS and WR to enable LCD in Read mode
MOV.B R15,&LCDDataL ;Set the lower byte of data
BIS.B #LCD_WR,&LCDCtrl ;Bring WR signal high to make the transaction
JNC WL8_Exit ;Is Carry Flag cleared? => Do not raise CS
BIS.B #LCD_CS,&LCDCtrl ;else, Disable LCD module.
WL8_Exit: RET
;-------------------------------------------
ReadLCD:
; Reads one word of data from the LCD. It also sets the direction of data port to input
; and the DC pin of the LCD to read data.
; Input: Carry Flag: 0 => Do not disable the LCD CS after reading
; 1 => Disable the LCD CS and set port to output after reading
; Output: R15: Contains the word read
; Registers Used: R15
; Registers Altered: R15, No flags affected
; Stack Usage: None
; Depend On Defs: LCD_CS, LCD_DC, LCD_RD, LCDCtrl, LCDDataHDIR, LCDDataHIN,
; LCDDataLDIR, LCDDataLIN
; Depend On Vars: None
; Depend On Funcs: ReadNextLCD
BIS.B #LCD_DC,&LCDCtrl ;Only data can be read from the LCD module
MOV.B #000h,&LCDDataLDIR ;Data pins must be inputs (uses the constant
MOV.B #000h,&LCDDataHDIR ;generator R3 to fetch 000h)
;-------------------------------------------
ReadNextLCD:
; Reads one word of data from the LCD. It expexts the direction of the data ports to be
; inputs and DC pin to be high.
; Input: Carry Flag: 0 => Do not disable the LCD CS after reading
; 1 => Disable the LCD CS after reading
; Output: R15: Contains the word read
; Registers Used: R15
; Registers Altered: R15, No flags affected
; Stack Usage: None
; Depend On Defs: LCD_CS, LCD_RD, LCDCtrl, LCDDataHDIR, LCDDataHIN,
; LCDDataLDIR, LCDDataLIN
; Depend On Vars: None
; Depend On Funcs: ReadNextLCD
BIC.B #LCD_CS+LCD_RD,&LCDCtrl ;Enable LCD in Write mode (from LCD to MPU)
JMP $+2 ;Wait 4 cycles
JMP $+2
MOV.B &LCDDataHIN,R15 ;Read the 8 high bits of the byte
SWPB R15
BIS.B &LCDDataLIN,R15 ;Store the 8 lower bits also
BIS.B #LCD_RD,&LCDCtrl ;Raise RD again
JNC RL_Exit ;Is Carry Flag cleared? => Do not raise CS
BIS.B #LCD_CS,&LCDCtrl ;else, disable the LCD module
MOV.B #0FFh,&LCDDataLDIR ;Set the direction of data port to output
MOV.B #0FFh,&LCDDataHDIR
RL_Exit: RET
;-------------------------------------------
InitLCD:
; Sends the correct command sequence to initialise the LCD module
; Input: None
; Output: None
; Registers Used: None
; Registers Altered: None
; Stack Usage: None
; Depend On Defs: None
; Depend On Vars: None
; Depend On Funcs: None
MOV #DEFBLVAL,&BLMaxVal ;Default maximum PWM value of the backlight
MOV #00000h,&BLCurVal ;Current PWM value of the backlight is 0.
MOV #DEFCOUNTER,&BLMaxCntr ;Default delay for PWM step change
MOV #DEFCOUNTER,&BLCounter ;The same value for current delay position count
.if $isdefed("BLCTL") ;If PWM can be used for LCD Backlight
; MOV.W #0FFFFh,&BLCCR0 ;Maximum value of PWM
MOV.W #DEFBLVAL,&BLCCR ;Default illuination PWM value of LCD Backlight
.endif
MOV.W #DEFBKGRND,&BkGrndClr ;Set the default background colour
MOV.W #DEFFRGRND,&FrGrndClr ;Set the default foreground colour
MOV.W #DEFFONT,R4 ;Going to set the font to be used
CALL #SetFont ;The font to be used is the default one
MOV.W #00000h,&FontProps ;Reset font properties
MOV.W #InitLCDTbl,R13 ;Going to use a table of data to send to the LCD
;In this table every command has the following format:
;Byte1 is the number of data bytes the LCD command contains, if positive, or
; a command to this function, if negative (like delay or End Of Sequence)
;In case of a function command the rest of the bytes are its parameters, else
;it is the LCD command byte.