Although it is a program of two hundred million lines, I debugged it for one day and got something wrong.
It turns out that # 0ffh was not written to P0 when reading P0. After a long time, I finally found a C Proteus simulation program and a C program of Keil on csdn. It's okay to stick to my circuit diagram. At last, I joined Keil and Proteus step by step to find out the error.
I would like to return to my friends who uploaded the C source program and the Proteus simulation program. However, today I have not been able to upload the program. I only need to send a graph and a compilation program here. When the resources can be uploaded, I will upload them and get some points to learn something!
Good luck!
RS bit p2.5; register selection Signal
Rorw bit p2.6; read and write selection Signal
E bit p2.7; enable control
Org 0000 h
Ljmp main
Org 0030 H
Main:
MoV sp, #60 h; set the stack pointer
Lcall Init; call the LCM initialization program
Lcall first; set the display address to 1st rows and 1st position subroutines
MoV dptr, # tab1; set the first address of the first line of 1st characters
Lcall display; call the display character subroutine
Lcall second; set the display address to 2nd rows and 1st position subroutines
MoV dptr, # tab2; set the first address of the 2nd Line Character
Lcall display; call the display character subroutine
Sjmp $; main program ended
; LCM initialization program (this program uses the hot start command segment)
; Hot start operation steps: 1. Write the instruction code, 30 h or 38 H. 2. latency> 4.1 ms.
3. Write the instruction code, 30 h or 38 H. 4. latency> us.
5. Write the instruction code, 30 h or 38 H.
Init:
Lcall delay1; subprograms with a latency of 5 ms
Lcall delay1; latency, waiting for Stable Power Supply
MoV A, #38 h; can be written for 30 h or 38 H. I think this is a byte of writing method,
; Working Method: 0 0 1 dl n f **,
; Dl = 1, 8-Bit Data Bus, n = 1, display dual-line character lines, f = 0, use 5 * & dot matrix character body
MoV P2, # 00011111b; E, RS, and rorw are 0
NOP
Setb e; e is high, enabling
MoV P0, A; write command code
CLR E
Lcall delay1; latency: 5 ms
MoV A, #38 H
MoV P2, # 00011111b
NOP
SETB E
MoV P0,
CLR E
Lcall delay2; latency 120us subroutine
MoV A, #38 H
MoV P2, # 00011111b
NOP
SETB E
MoV P0,
CLR E
Lcall delay2; latency 120us subroutine
Hot Start program ends here
The following is the initialization program
MoV A, #38 h; working mode is set to 2 rows, 8 is the data bus, 5*7 lattice characters
Acall WRC; Judge BF and write command
MoV A, #01 H; clear display
Acall WRC
MoV A, #06 h; set the input mode to AC plus 1, move the cursor right, the screen does not move
Acall WRC
MoV A, # 0eh; set the display status to on display, show the cursor, do not flash
Acall WRC
RET
The initialization program ends here
; Interpreting BF and writing instructions
WRC:
Acall busy; interpretation BF subroutine
MoV P2, # 00011111b; E, rorw, RS is 0, ready to write
NOP
Setb e; Enable
MoV P0, A; write command code
Clr e; e is low
RET
; Judge the busy program. If not busy, return
Busy:
Push ACC
W: mov P2, # 01011111b; RS = 0, rorw = 1, E = 0, prepare read data
NOP
MoV P0, # 0ffh; Set P0 port to input port
SETB E
// Mov P0, 0ffh
NOP
NOP
MoV A, P0; read BF and acvalue
JB acc.7, W; BF is not 0, wait
CLR E
Pop ACC
RET
; Write the display data subroutine
Wrtd:
Acall busy
MoV P2, # 001111b; RS = 1, rorw = 0, E = 0, prepare to write data
SETB E
MoV P0,
CLR E
Lcall delay2
RET
; Display character programs
Display:
MoV R1, #00
Next:
MoV A, r1
Movc A, @ A + dptr; send the sequence codes referred to by dptr to the LCD display one by one
Cjne A, #21 h, DSL; To The Terminator "!" Otherwise
RET
DSL:
Lcall wrtd; call and display subprograms
INC r1
Sjmp next
First:
MoV A, # 0000000b; the address of ddram is set to 80 h, that is, the character to be displayed starts from the second position in line 1st
Call WRC
RET
Second:
MoV A, # 11000000b; the address of ddram is set to c0h, that is, the character to be displayed starts from the second position in line 2nd
Call WRC
RET
Delay1:
MoV R7, #05 h; millisecond count
Dl1:
MoV R6, # 0fah; 12 MHz, default 1 ms latency
Dl2:
NOP
NOP
Djnz R1, dl2
Djnz R7, dl1
RET
Delay2:
MoV R7, # 0ch; multiples of 10us
Dl3:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
Djnz R7, dl3
RET
Tab1:
DB 'Welcome to '; 1st characters displayed on the LCD
Db '! '; End code is "!"
Tab2:
DB 'ur University '; LCD 2nd-line display characters
Db '! '; End code is "!"
End