在主机显示学号姓名,利用通信功能,在从机也显示同样的内容。- ;发送端
- ;/通用寄存器R5用于录入lcd1602的8位指令和数据
- ORG 000H
- LCD_PORT EQU P1
- COUNT EQU 30H
- RS EQU P2.5
- RW EQU P2.6
- EN EQU P2.7
- AJMP START
- ORG 00BH
- LJMP TIME0
- ORG 100H
- START:
- ;将自定义的八个字符写入CGRAM
- ACALL ENABLE
- MOV P1,#40H
- ACALL ENABLE
- MOV DPTR,#SELF1
- CALL WSELF
- MOV P1,#48H
- ACALL ENABLE
- MOV DPTR,#SELF2
- CALL WSELF
- MOV P1,#50H
- ACALL ENABLE
- MOV DPTR,#SELF3
- CALL WSELF
- MOV P1,#58H
- ACALL ENABLE
- MOV DPTR,#SELF4
- CALL WSELF
- MOV P1,#60H
- ACALL ENABLE
- MOV DPTR,#SELF5
- CALL WSELF
- MOV P1,#68H
- ACALL ENABLE
- MOV DPTR,#SELF6
- CALL WSELF
- MOV P1,#70H
- ACALL ENABLE
- MOV DPTR,#SELF7
- CALL WSELF
- MOV P1,#78H
- ACALL ENABLE
- MOV DPTR,#SELF8
- CALL WSELF
- //定时器设置
- MOV TMOD,#00100001B
- SETB EA;总开关
- MOV PCON,#80H
- MOV TH1,#0FDH
- //初始化串口//方式1发送接收均初始化
- MOV SCON,#01010000B
- SETB TR1;定时器1开始运行
- ACALL LCD1602_init;初始化lcd1602
- ACALL PRINT0
- MAIN:
- MOV DPTR,#NUM_TAB
- MOV R0,#16
- ACALL DELAY5
- ACALL SEND_DATA
- NEXT:AJMP NEXT
- //发送数据,表地址放入dptr,发送数量放入R0
- SEND_DATA:
- INC R0
- MOV A,#00H;从首位开始
- SEND_DATA_0:
- DJNZ R0,SEND_DATA_1
- ret
- SEND_DATA_1:
- ACALL D5MS
- ACALL D5MS
- PUSH ACC
- MOVC A,@A+DPTR
- MOV SBUF,A
- ACALL D5MS
- POP ACC
- INC A
- WAIT:JBC TI,SEND_DATA_0//等待发送完成
- AJMP WAIT
- //写指令,指令放入R5
- WRITE_COM:
- CLR RS ;(130)RS,RW,EN均置0,写指令
- CLR RW
- CLR EN
- MOV LCD_PORT ,R5 ;(131)指令一律写入R5,在移入P2
- SETB EN
- ACALL D5MS
- ACALL D5MS
- CLR EN ;(132)EN跳变,允许数据交换
- RET ;(134)返回原处
- //写数据,数据放入R5
- WRITE_DATA:
- SETB RS ;(130)RS置1,RW,EN均置0,写数据
- CLR RW
- CLR EN
- MOV LCD_PORT ,R5 ;(131)数据一律写入R5,在移入P2
- //ACALL D5MS
- SETB EN
- ACALL D5MS
- ACALL D5MS
- CLR EN ;(132)EN跳变,允许数据交换
- RET ;(134)返回原处
- //初始化LCD1602
- LCD1602_init:
- MOV R5,#06H ;(144)8位数据,5*7点阵,2行显示
- ACALL WRITE_COM
- MOV R5,#0CH ;(148)写一个数据后,光标右移,屏幕不移动
- ACALL WRITE_COM
- MOV R5,#38H ;(146)显示开,关光标,光标不闪烁
- ACALL WRITE_COM
- MOV R5,#01H ;(150)清屏
- ACALL WRITE_COM
- RET
- PRINT0:
- PUSH ACC;对A做保护
- PUSH 06
- PUSH 05
- MOV A,#00H
- MOV R3,#16
- MOV DPTR,#NUM_TAB
- PRINT0_0:
- PUSH ACC
- MOVC A,@A+DPTR
- MOV R5,#00H ;(49)命令载入R5
- ACALL WRITE_COM ;(50)写命令
- MOV R5,A
- ACALL WRITE_DATA
- POP ACC
- INC A
- DJNZ R3,PRINT0_0
- POP 05
- POP 06
- POP ACC
- RET
- ENABLE:
- CLR RS
- CLR RW
- CLR EN
- ACALL D5MS
- ACALL D5MS
- SETB EN
- RET
-
- WSELF:
- MOV R7,#00H
- W1:
- MOV A,R7
- MOVC A,@A+DPTR
- CALL WRITE1
- INC R7
- CJNE R7,#08H,W1
- RET
- WRITE1:
- CLR EN
- SETB RS
- CLR RW
- SETB EN
- MOV P1,A
- CLR EN
- CALL D5MS
- CALL D5MS
- RET
- //计数器0中断服务函数
- TIME0:
- PUSH ACC
- INC 30H
- MOV A,30H
- CJNE A,#02,RETIME;5*O.1S
- INC R3
- MOV 30H,#0
- RETIME:
- MOV TH0,#27H
- MOV TL0,#11H;重置定时器
- POP ACC
- RETI
- //延时5ms左右,已进行现场保护
- D5MS:
- PUSH 07
- PUSH 06
- MOV R7,#200
- DEL1:MOV R6,#125
- DEL2:DJNZ R6,DEL2
- DJNZ R7,DEL1
- POP 06
- POP 07
- RET
- //带保护现场的延时
- DELAY5:
- PUSH 02
- PUSH 03
- PUSH 04
- MOV R2,#5
- DLY1:
- MOV R3,#200
- DLY2:
- MOV R4,#250
- DJNZ R4,$
- DJNZ R3,DLY2
- DJNZ R2,DLY1
- POP 04
- POP 03
- POP 02
- RET
- //学号
- NUM_TAB: DB "0123456789",20H,05H,20H,06H,20H,07H
- //姓名
- SELF1:DB 04H,1FH,15H,1FH,15H,1FH,04H,07H
- SELF2:DB 02H,0CH,04H,1FH,0EH,15H,15H,04H
- SELF3:DB 02H,0AH,06H,02H,1FH,02H,02H,02H
- SELF4:DB 0EH,04H,04H,04H,0EH,04H,04H,0EH
- SELF5:DB 0FH,0AH,0AH,1AH,1FH,0AH,0AH,0FH
- SELF6:DB 09H,01H,1DH,07H,15H,09H,15H,03H
- SELF7:DB 04H,1FH,04H,0AH,1FH,00H,1BH,0BH
- SELF8:DB 02H,1CH,10H,14H,1FH,04H,15H,0CH
-
- END
复制代码
|