;以下为串口写指令和数据的子程序:
;This program is for 12232-9 串行
; CS--------P2.0
; SID-------P2.1
; CLK---------P2.2
CS EQU P2.0
SID EQU P2.1
CLK EQU P2.2
ORG 0000H
AJMP START
ORG 0010H
START:
LCALL SETUP
LCALL DEF_CHAR
MOV A,#80H
LCALL WRITE_COM
MOV R3,#8
TEST11:
MOV DPTR,#CGRAM1 ;CGRAM TEST
LCALL WRITE_CGRAM
DJNZ R3,TEST11
MOV A,#90H
LCALL WRITE_COM
MOV R3,#8
TEST12:
MOV DPTR,#CGRAM1
LCALL WRITE_CGRAM
DJNZ R3,TEST12
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
MOV A,#80H
LCALL WRITE_COM
MOV R3,#8
TEST21:
MOV DPTR,#CGRAM2
LCALL WRITE_CGRAM
DJNZ R3,TEST21
MOV A,#90H
LCALL WRITE_COM
MOV R3,#8
TEST22:
MOV DPTR,#CGRAM2
LCALL WRITE_CGRAM
DJNZ R3,TEST22
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
MOV A,#80H
LCALL WRITE_COM
MOV R3,#8
TEST31:
MOV DPTR,#CGRAM3
LCALL WRITE_CGRAM
DJNZ R3,TEST31
MOV A,#90H
LCALL WRITE_COM
MOV R3,#8
TEST32:
MOV DPTR,#CGRAM3
LCALL WRITE_CGRAM
DJNZ R3,TEST32
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
MOV A,#80H
LCALL WRITE_COM
MOV R3,#8
TEST41:
MOV DPTR,#CGRAM4
LCALL WRITE_CGRAM
DJNZ R3,TEST41
MOV A,#90H
LCALL WRITE_COM
MOV R3,#8
TEST42:
MOV DPTR,#CGRAM4
LCALL WRITE_CGRAM
DJNZ R3,TEST42
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
MOV A,#80H ;WORD TEST
LCALL WRITE_COM
MOV DPTR,#CHINESE
LCALL WRITE_Hz
MOV A,#90H
LCALL WRITE_COM
MOV DPTR,#TABLE1
LCALL WRITE_ASCII
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
MOV A,#80H
LCALL WRITE_COM
MOV DPTR,#table1
LCALL WRITE_ascii
MOV A,#90H
LCALL WRITE_COM
MOV DPTR,#chinese
LCALL WRITE_hz
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
AAA: LJMP START
SETUP:
LCALL DELAY
LCALL DELAY
LCALL DELAY
MOV A,#01H ;CLEAR DISPLAY
LCALL WRITE_COM
MOV A,#00110000B ;FUNCTION SETTING
LCALL WRITE_COM
MOV A,#00000010B ;DDRAM SET TO ’00H’
LCALL WRITE_COM
MOV A,#00000100B ;
LCALL WRITE_COM
MOV A,#00001100B ;DISPLAY ON
LCALL WRITE_COM
MOV A,#00000001B ;CLEARING
SCREEN
LCALL WRITE_COM
MOV A,#10000000B ;SET DDRAM ADDRESS
LCALL WRITE_COM
RET
WRITE_COM:
LCALL DELAY1 ;INSTEAD OF CHECKING BF STATE
SETB CS
PUSH ACC
MOV R0,#8
MOV A,#11111000B
COMM1:
CLR C
RLC A
MOV SID,C
CLR CLK
SETB CLK
DJNZ R0,COMM1
POP ACC
MOV R5,A
ANL A,#0F0H
MOV R0,#8
COMM2: CLR C
RLC A
MOV SID,C
CLR CLK
SETB CLK
DJNZ R0,COMM2
MOV A,R5
SWAP A
ANL A,#0F0H
MOV R0,#8
COMM3: CLR C
RLC A
MOV SID,C
CLR CLK
SETB CLK
DJNZ R0,COMM3
CLR CS
RET
WRITE_DAT:
LCALL DELAY1
SETB CS
PUSH ACC
MOV R0,#8
MOV A,#11111010B
DATA1: CLR C
RLC A
MOV SID,C
CLR CLK
SETB CLK
DJNZ R0,DATA1
POP ACC
MOV R5,A
ANL A,#0F0H
MOV R0,#8
DATA2: CLR C
RLC A
MOV SID,C
CLR CLK
SETB CLK
DJNZ R0,DATA2
MOV A,R5
SWAP A
ANL A,#0F0H
MOV R0,#8
DATA3: CLR C
RLC A
MOV SID,C
CLR CLK
SETB CLK
DJNZ R0,DATA3
CLR CS
RET
DELAY1:
MOV R7,#010H
D11:
MOV R6,#010H
DJNZ R6,$
DJNZ R7,D11
RET
DELAY:
MOV R1,#00H
D2:
MOV R2,#00H
DJNZ R2,$
DJNZ R1,D2
RET
DEF_CHAR: ;WRITE TO CGRAM
MOV A,#01000000B ;SET CGRAM ADDRESS
LCALL WRITE_COM
MOV R3,#8
DEF1:
MOV A,#000H
LCALL WRITE_DAT
LCALL WRITE_DAT
MOV A,#0FFH
LCALL WRITE_DAT
LCALL WRITE_DAT
DJNZ R3,DEF1
MOV R3,#8
DEF2:
MOV A,#0AAH
LCALL WRITE_DAT
LCALL WRITE_DAT
MOV A,#0AAH
LCALL WRITE_DAT
LCALL WRITE_DAT
DJNZ R3,DEF2
MOV R3,#8
DEF3:
MOV A,#055H
LCALL WRITE_DAT
LCALL WRITE_DAT
MOV A,#0AAH
LCALL WRITE_DAT
LCALL WRITE_DAT
DJNZ R3,DEF3
MOV R3,#8
DEF4:
MOV A,#0FFH
LCALL WRITE_DAT
LCALL WRITE_DAT
LCALL WRITE_DAT
LCALL WRITE_DAT
DJNZ R3,DEF4
RET
WRITE_ASCII:
MOV R4,#16
DDDD: CLR A
MOV C A,@A+DPTR
LCALL WRITE_DAT
INC DPTR
DJNZ R4,DDDD
RET
WRITE_HZ: ;WRITE 8 CHINESE TO LCD
MOV R4,#8
DD:
CLR A
MOV C A,@A+DPTR
INC DPTR
LCALL WRITE_DAT
CLR A
MOV C A,@A+DPTR
INC DPTR
LCALL WRITE_DAT
DJNZ R4,DD
RET
WRITE_CGRAM: ;CGRAM TESTING
CLR A
MOV C A,@A+DPTR
LCALL WRITE_DAT
INC DPTR
CLR A
MOV C A,@A+DPTR
LCALL WRITE_DAT
RET
TABLE1:
DB 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37
DB 0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F
;“这里是16*8 点阵的字符代码”
CGRAM1: DB 00H,00H ;这里是自造字符地址表
CGRAM2: DB 00H,02H
CGRAM3: DB 00H,04H
CGRAM4: DB 00H,06H
CHINESE:
DB 0B3H,0A7H,0B3H,0A8H,0B3H,0A9H,0B3H,0AAH,0B3H,0ABH,0B3H,0ACH
;“这里是16*16 点阵的汉字代码表”
END