RS BIT P2.4 ;这3位是液晶屏的控制信号,连接方式由具体硬件而定 RW BIT P2.5 E BIT P2.6 ORG 00H AJMP MAIN MAIN: mov R0,#24 ACALL INITIAL ACALL DISPLAY;调用液晶显示子程序 AJMP MAIN ;-------液晶显示--------------------------------------- DISPLAY: MOV A,#80H ;第一行第1 个点 ACALL WR_CMD MOV DPTR, #LINE1 ACALL PR_STR ACALL WR_DATA DISP1: MOV A,#18H ;字符左移命令(注:实物中左移命令字为18H) ACALL WR_CMD ACALL D05S DJNZ R0,DISP1 RET ;---液晶屏初始化------------------------------------------------- INITIAL: MOV A, #01H ACALL WR_CMD MOV A, #38H ACALL WR_CMD MOV A, #0CH ACALL WR_CMD MOV A, #06H ACALL WR_CMD RET ;----写液晶指令的子程序------------------------------------------ WR_CMD: MOV P0, A CLR RS ;写入控制命令 CLR RW CLR E ACALL DELAY SETB E RET ;----写液晶数据--------------------------------------------- WR_DATA: MOV P0, A SETB RS ;写入数据 CLR RW CLR E ACALL DELAY ;判断液晶模块是否忙? SETB E RET ;-----写行字符--------------------------------------------------------------- PR_STR: CLR A MOVC A, @A+DPTR JZ END_PR ACALL WR_DATA INC DPTR AJMP PR_STR END_PR: RET ;----查看液晶忙碌信号--------------------------------------------------------- DELAY: MOV P0,#0FFH ;判断液晶显示器是否忙的子程序 CLR RS SETB RW CLR E NOP SETB E JB P0.7,DELAY ;如果P0.7为高电平表示忙就循环等待 RET ;----0.5S延时(按12MHZ算)----------------------------------------------------------------- D05S: MOV R6,#25 MOV R5,#100 MOV R4,#100 DJNZ R4,$ DJNZ R5,$-4 DJNZ R6,$-8 RET ;-------------------------------------------------------------------------------------- LINE1: DB 'Happy birthday to you!' END
|