📄 4bit.lst
字号:
ASEM-51 V1.3 Copyright (c) 2002 by W.W. Heinz PAGE 1
MCS-51 Family Macro Assembler A S E M - 5 1 V 1.3
=====================================================
Source File: E:\MiCrOConTroller\Coba_M-IDE\LCD4BIT\4BIT.asm
Object File: E:\MiCrOConTroller\Coba_M-IDE\LCD4BIT\4BIT.hex
List File: E:\MiCrOConTroller\Coba_M-IDE\LCD4BIT\4BIT.lst
Line I Addr Code Source
1: ;---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------
2: ;Author: Ashwin.V
3: ;Country:India
4: ;Code:LCD interface in 4bit mode
5: ;CPU:At89c51@11.0592Mhz
6: ;Tips:All you need to do is call the line where you want to display the message, mov the charecter t
o lcd_data and call datw.
7: ;If you want to display a string, move the address of the hardcodded string into dptr and call datw.
8: ;---------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------
9:
10: B 00B7 RS EQU p3.7
11: B 00B6 RW EQU p3.6
12: B 00B5 En EQU p3.5
13: N 30 LCD_DATA DATA 30h
14:
15:
16: N 0000 org 0000h
17:
18: 0000 02 01 6B ljmp lcd4_main
19:
20: N 0030 org 0030h
21:
22:
23: ;___________________________________________________________________________
24: ;---------------------delay subroutines start here--------------------------
25: ;___________________________________________________________________________
26:
27: ;-------------------------------8us delay-----------------------------------
28: 0030 00 delay_8us: nop
29: 0031 00 nop
30: 0032 00 nop
31: 0033 00 nop
32: 0034 00 nop
33: 0035 00 nop
34: 0036 22 ret
35: ;------------------------------100us delay----------------------------------
36:
37: 0037 C0 00 delay_100us: push 00
38: 0039 78 2E mov r0,#46
39: 003B D9 FE delay_100us_loop: djnz r1,delay_100us_loop
40: 003D D0 00 pop 00
ASEM-51 V1.3 Copyright (c) 2002 by W.W. Heinz PAGE 2
Line I Addr Code Source
41: 003F 22 ret
42:
43: ;------------------------------16ms delay-----------------------------------
44:
45: 0040 C0 00 delay_16ms: push 00
46: 0042 C0 01 push 01
47: 0044 78 1E mov r0,#30
48: 0046 79 FF delay_16ms_loop1: mov r1,#255
49: 0048 D9 FE delay_16ms_loop2: djnz r1,delay_16ms_loop2
50: 004A D8 FA djnz r0,delay_16ms_loop1
51: 004C D0 01 pop 01
52: 004E D0 00 pop 00
53: 0050 22 ret
54:
55: ;--------------------------half second delay-------------------------------
56:
57: 0051 C0 00 delay_half_second: push 00
58: 0053 C0 01 push 01
59: 0055 C0 02 push 02
60: 0057 7A 0A mov r2,#0ah
61: 0059 79 64 delay_half_second1: mov r1,#64h
62: 005B 78 FF delay_half_second2: mov r0,#0ffh
63: 005D D8 FE back: djnz r0,back
64: 005F D9 FA djnz r1, delay_half_second2
65: 0061 DA F6 djnz r2,delay_half_second1
66: 0063 D0 02 pop 02
67: 0065 D0 01 pop 01
68: 0067 D0 00 pop 00
69: 0069 22 ret
70:
71:
72: ;___________________________________________________________________________
73: ;---------------------delay subroutines end here----------------------------
74: ;___________________________________________________________________________
75:
76:
77: ;___________________________________________________________________________
78: ;----------------------LCD subroutines start here---------------------------
79: ;___________________________________________________________________________
80:
81: ;-----------------------------------------------------------------
82: ;----------------message definition and display-------------------
83: ;-----------------------------------------------------------------
84:
85:
86: 006A C0 E0 disp_LCD_message: push acc
87: 006C C0 00 push 00h
88: 006E 78 11 mov r0,#17
89:
90: 0070 74 00 disp_LCD_message1: mov a, #00h ; reset accumulator
91: 0072 93 movc a,@a+dptr
92: 0073 F5 30 mov lcd_data,a
93: 0075 31 2F acall datw
94: 0077 A3 inc dptr
95: 0078 D8 F6 djnz r0,disp_LCD_message1
96:
ASEM-51 V1.3 Copyright (c) 2002 by W.W. Heinz PAGE 3
Line I Addr Code Source
97: 007A D0 00 pop 00h
98: 007C D0 E0 pop acc
99: 007E 22 ret
100:
101: 007F 54 65 73 74 disp_testing: DB "Testing 4bit LCD"
0083 69 6E 67 20
0087 34 62 69 74
008B 20 4C 43 44
102: 008F 49 6E 69 74 disp_initialising: DB "Initialising...."
0093 69 61 6C 69
0097 73 69 6E 67
009B 2E 2E 2E 2E
103: 009F 20 34 62 69 disp_ready: DB " 4bit LCD ready "
00A3 74 20 4C 43
00A7 44 20 72 65
00AB 61 64 79 20
104: 00AF 20 20 20 20 disp_clear: DB " "
00B3 20 20 20 20
00B7 20 20 20 20
00BB 20 20 20 20
105:
106:
107: ;-----------------------------------------------------------------
108: ;----------------lcd initialisation starts here-------------------
109: ;-----------------------------------------------------------------
110:
111: 00BF entry_set_mode:
112:
113: 00BF 75 30 00 mov lcd_data,#00h
114: 00C2 31 03 acall cmdw4
115: 00C4 11 37 acall delay_100us
116: 00C6 22 ret
117: ;-----------------------------------------------------
118: ;-----------------------------------------------------
119: 00C7 lcd4_initialise:
120:
121: 00C7 11 40 acall delay_16ms ; wait for more than 15ms after vdd reaches 4.5v
122:
123: 00C9 75 30 20 mov lcd_data,#020h ; 4bit interface
124: 00CC 31 03 acall cmdw4
125: 00CE 11 37 acall delay_100us
126: ;-----------------------------------------------------
127: 00D0 75 30 20 mov lcd_data,#20h ; entry mode set
128: 00D3 31 03 acall cmdw4
129: 00D5 11 37 acall delay_100us
130:
131: 00D7 75 30 C0 mov lcd_data,#0c0h ; 2line 5x10 matrix
132: 00DA 31 03 acall cmdw4
133: 00DC 11 37 acall delay_100us
134: ;------------------------------------------------------
135: 00DE 11 BF acall entry_set_mode
136:
137: 00E0 75 30 80 mov lcd_data,#80h ; display off
138: 00E3 31 03 acall cmdw4
139: 00E5 11 37 acall delay_100us
140: ;-------------------------------------------------------
ASEM-51 V1.3 Copyright (c) 2002 by W.W. Heinz PAGE 4
Line I Addr Code Source
141: 00E7 11 BF acall entry_set_mode
142:
143: 00E9 75 30 10 mov lcd_data,#10h ; clear display
144: 00EC 31 03 acall cmdw4
145: 00EE 11 37 acall delay_100us
146: ;--------------------------------------------------------
147: 00F0 11 BF acall entry_set_mode
148:
149: 00F2 75 30 60 mov lcd_data,#60h ; cursor moves right, display doesn't shift
150: 00F5 31 03 acall cmdw4
151: 00F7 11 37 acall delay_100us
152: ;--------------------------------------------------------
153: 00F9 11 BF acall entry_set_mode
154:
155: 00FB 75 30 F0 mov lcd_data,#0f0h ; cursor on and blink
156: 00FE 31 03 acall cmdw4
157: 0100 11 37 acall delay_100us
158:
159: 0102 22 ret
160:
161: ;-----------------------------------------------------------------
162: ;-----------------lcd initialisation ends here--------------------
163: ;-----------------------------------------------------------------
164:
165:
166: ;-----------------------------------------------------------------
167: ;--------command and data write subroutines starts here-----------
168: ;-----------------------------------------------------------------
169:
170: ;-------------------------------------------------
171: ;--------------4bit command write-----------------
172: ;-------------------------------------------------
173:
174: 0103 cmdw4:
175: 0103 C0 E0 push acc
176: 0105 C2 B7 clr RS
177: 0107 C2 B5 clr En
178:
179: 0109 31 4A acall write_port
180: ;--------------wait 8 machine cycles-------------
181: 010B 11 30 acall delay_8us
182: ;------------------------------------------------
183: 010D D2 B5 setb En
184: 010F C2 B5 clr En
185:
186: 0111 D0 E0 pop acc
187: 0113 22 ret
188:
189: ;------------------------------------------------
190: ;--------------8bit command write----------------
191: ;------------------------------------------------
192:
193: 0114 cmdw:
194: 0114 C0 E0 push acc
195: 0116 C2 B7 clr RS
196: 0118 C2 B5 clr En
ASEM-51 V1.3 Copyright (c) 2002 by W.W. Heinz PAGE 5
Line I Addr Code Source
197:
198: 011A 31 4A acall write_port
199: ;--------------wait 8 machine cycles-------------
200: 011C 11 30 acall delay_8us
201: ;------------------------------------------------
202: 011E D2 B5 setb En
203: 0120 C2 B5 clr En
204: ;-------------wait 8 machine cycles-------------
205: 0122 11 30 acall delay_8us
206: ;------------------------------------------------
207: 0124 31 4A acall write_port
208: ;--------------wait 8 machine cycles-------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -