|
问题描述:
我用3.3V单片机控制3.3V的1602,现在发现一个问题就是在上电后不显示,什么都不动它,等上1分钟左右它才显示出来了.然后就可以正常控制了,
在1602正常显示后,不断1602的电的前提下,断单片机的电又上电,可以正常显示.把1602和单片机同时断电又上电就要等上1分钟左右它才显示.
连线:
PA-->D0~D7
PB.5->E
PB.6->RS
PB.7->RW
用10K电位器调挑背光
单片机是51内核的,但把端口作为外部寄存器来读写.这点跟8051不同.
mov DPTR, #PB
MOVX A, @DPTR ;读PB口
mov DPTR, #PB
MOVX @DPTR A; 写PB口
MOV DPTR, #PACONH
MOV A, #10101010B ;set pa4~7 output
MOV DPTR, #PACONH
MOV A, #01010101B ;set pa4~7 input
程序如下:
;======================================================
;======================================================
PORT_E EQU ACC_5
PORT_RS EQU ACC_6
PORT_RW EQU ACC_7
PORT_BY EQU ACC_7
Read_1602_BY:
mov DPTR, #PB
MOVX A, @DPTR
CLR PORT_E
CLR PORT_RS ;=1:DATA;=0:CMD
SETB PORT_RW ;=1:READ;=0:WRITE
MOVX @DPTR, A
MOV DPTR, #PACONH
MOV A, #01010101B ;set pa input
MOVX @DPTR, A
MOV DPTR, #PACONL
MOV A, #01010101B
MOVX @DPTR, A
MOV DPTR, #PA
MOV A, #0FFH
MOVX @DPTR, A
read_1602_by_lp:
mov DPTR, #PB
MOVX A, @DPTR
SETB PORT_E
CLR PORT_RS ;=1:DATA;=0:CMD
SETB PORT_RW ;=1:READ;=0:WRITE
MOVX @DPTR, A
NOP
NOP
NOP
MOV DPTR, #PA
MOVX A, @DPTR
JNB PORT_BY, end_read_1602_by
JMP read_1602_by_lp
end_read_1602_by:
RET
Write_1602_cmd:
CALL Delay40us
CALL Read_1602_BY ;wait BY=0
MOV DPTR, #PB
MOVX A, @DPTR
CLR PORT_E
CLR PORT_RS ;=1:DATA;=0:CMD
CLR PORT_RW ;=1:READ;=0:WRITE
MOVX @DPTR, A
MOV DPTR, #PACONH
MOV A, #10101010B ;set pa output
MOVX @DPTR, A
MOV DPTR, #PACONL
MOV A, #10101010B
MOVX @DPTR, A
MOV DPTR, #PA
MOV A, R7
MOVX @DPTR, A
MOV DPTR, #PB
MOVX A, @DPTR
CLR PORT_RS ;=1:DATA;=0:CMD
CLR PORT_RW ;=1:READ;=0:WRITE
SETB PORT_E ;rising
MOVX @DPTR, A
NOP
NOP
NOP
NOP
CLR PORT_E
MOVX @DPTR, A
RET
Write_1602_cmd0:
MOV DPTR, #PB
MOVX A, @DPTR
CLR PORT_E
CLR PORT_RS ;=1:DATA;=0:CMD
CLR PORT_RW ;=1:READ;=0:WRITE
MOVX @DPTR, A
MOV DPTR, #PACONH
MOV A, #10101010B ;set pa output
MOVX @DPTR, A
MOV DPTR, #PACONL
MOV A, #10101010B
MOVX @DPTR, A
MOV DPTR, #PA
MOV A, R7
MOVX @DPTR, A
MOV DPTR, #PB
MOVX A, @DPTR
CLR PORT_RS ;=1:DATA;=0:CMD
CLR PORT_RW ;=1:READ;=0:WRITE
SETB PORT_E ;rising
MOVX @DPTR, A
NOP
NOP
NOP
NOP
CLR PORT_E
MOVX @DPTR, A
RET
Write_1602_data:
CALL Delay40us
CALL Read_1602_BY ;wait BY=0
MOV DPTR, #PB
MOVX A, @DPTR
CLR PORT_E
CLR PORT_RW ;=1:READ;=0:WRITE
SETB PORT_RS ;=1:DATA;=0:CMD
MOVX @DPTR, A
MOV DPTR, #PACONH
MOV A, #10101010B ;set pa output
MOVX @DPTR, A
MOV DPTR, #PACONL
MOV A, #10101010B
MOVX @DPTR, A
MOV DPTR, #PA
MOV A, R7
MOVX @DPTR, A
MOV DPTR, #PB
MOVX A, @DPTR
CLR PORT_RW ;=1:READ;=0:WRITE
SETB PORT_RS ;=1:DATA;=0:CMD
SETB PORT_E
MOVX @DPTR, A
NOP
NOP
NOP
NOP
NOP
NOP
CLR PORT_E
MOVX @DPTR, A
RET
main_1602_ini:
CALL Delay5ms
CALL Delay5ms
MOV R7, #038H
CALL Write_1602_cmd0 ;set 8bit,two line,5*11
CALL Delay5ms
CALL Delay250ms
MOV R7, #038H
CALL Write_1602_cmd0 ;不等忙信号
CALL Delay5ms
CALL Delay250ms
MOV R7, #038H
CALL Write_1602_cmd0 ;不等忙信号
CALL Delay5ms
CALL Delay5ms
MOV R7, #038H
CALL Write_1602_cmd0 ;不等忙信号
CALL Delay5ms
CALL Delay5ms
MOV R7, #00001000b ;set show off,cursor off,cursor no flash
CALL Write_1602_cmd0 ;不等忙信号
CALL Delay5ms
CALL Delay5ms
MOV R7, #01H ;set clr lcd data
CALL Write_1602_cmd0 ;不等忙信号
CALL Delay5ms
CALL Delay5ms
MOV R7, #00000110b ;set AC inc
CALL Write_1602_cmd0 ;不等忙信号
CALL Delay5ms
CALL Delay5ms
MOV R7, #00001100b ;#00001100b ;set show on,cursor off,cursor no flash
CALL Write_1602_cmd0 ;不等忙信号
CALL Delay5ms
CALL Delay5ms
ret |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|