/* * 1602的建立比较慢,上电需要比较长的时间 */ call Delay500MS /* * 初始化动作,芯片资料有详细说明 */ mov a,@00111000b call WRITE_INIT call Delay5MS mov a,@00111000b call WRITE_INIT call Delay5MS mov a,@00111000b call WRITE_INIT call Delay5MS /* * 初始化1602的寄存器等 */ CALL LCD_1602_INIT /* * 这里是测试功能,让液晶显示字符 */ mov a,@0X80 ; ADDRESS call WRITE_REG mov a,@0XBE call WRITE_DAT mov a,@0XB2 call WRITE_DAT mov a,@0XDA call WRITE_DAT mov a,@0XB2 call WRITE_DAT mov a,@0XC0 ; ADDRESS call WRITE_REG /* * 功能测试 */ mov a,@0X45 call WRITE_DAT mov a,@0X74 call WRITE_DAT mov a,@0X75 call WRITE_DAT mov a,@0X61 call WRITE_DAT mov a,@0X6C call WRITE_DAT mov a,@0X40 call WRITE_DAT mov a,@0X31 call WRITE_DAT mov a,@0X36 call WRITE_DAT mov a,@0X33 call WRITE_DAT mov a,@0X2E call WRITE_DAT mov a,@0X63 call WRITE_DAT mov a,@0X6F call WRITE_DAT mov a,@0X6D call WRITE_DAT /* * 死循环延时5ms,测试用,简单为重 */ Delay5MS: clr temp0 mov a,@1 mov temp1,a d5ms_loop: jz temp0 jmp $-1 djz temp1 jmp d5ms_loop ret
/* * 延时500ms */ Delay500MS: clr temp0 mov a,@255 mov temp1,a d500ms_loop: jz temp0 jmp $-1 djz temp1 jmp d500ms_loop ret
/* * 液晶连接脚定义 */ CNT_PORT == 0X05 LCD_RS == 2 LCD_RW == 1 LCD_EN == 0 DAT_PORT == 0X06
LCD_COUNT == 0x20
/* * 液晶初始化程序 */ LCD_1602_INIT: mov a,@00111000b ; function set CALL WRITE_REG
MOV A,@0X08 CALL WRITE_REG
MOV A,@0X01 CALL WRITE_REG CALL Delay5MS MOV A,@00000110b ; entire mode CALL WRITE_REG
MOV A,@00001101b ; display on./ off CALL WRITE_REG
RET
/* * 检测是否忙 */ LCD_CHECKBUSY: mov a,@0xff mov DAT_PORT,a iow DAT_PORT CB_LOOP: nop bc CNT_PORT,LCD_EN bc CNT_PORT,LCD_RS bs CNT_PORT,LCD_RW nop BS CNT_PORT,LCD_EN nop mov a,DAT_PORT nop bc CNT_PORT,LCD_EN and a,@0x80 ; 读出来的数据位bit7 = 1 busy ,=0 free jbs psw,z jmp CB_LOOP mov a,@0 iow DAT_PORT mov DAT_PORT,a RET
/* * 写命令初始化 */ WRITE_INIT: bc CNT_PORT,LCD_EN bc CNT_PORT,LCD_RS BC CNT_PORT,LCD_RW nop BS CNT_PORT,LCD_EN NOP MOV DAT_PORT,A NOP NOP BC CNT_PORT,LCD_EN RET
/* * 写寄存器 */ WRITE_REG: mov temp0,a call LCD_CHECKBUSY mov a,temp0 bc CNT_PORT,LCD_EN bc CNT_PORT,LCD_RS BC CNT_PORT,LCD_RW nop BS CNT_PORT,LCD_EN NOP MOV DAT_PORT,A NOP NOP BC CNT_PORT,LCD_EN RET
/* * 写数据 */ WRITE_DAT: mov temp0,a call LCD_CHECKBUSY mov a,temp0 bc CNT_PORT,LCD_EN bs CNT_PORT,LCD_RS BC CNT_PORT,LCD_RW nop BS CNT_PORT,LCD_EN NOP MOV DAT_PORT,A NOP NOP BC CNT_PORT,LCD_EN NOP RET
|