程序为:;外部RAM0000H---0017H存放24个字符 ;20H存放24个字符要显示的数字 ;3EH写显示LCD的命令 ;4DH4EH4FH写显示每个字符的地址和数据 ;5DH5EH暂存每个字符的地址 SCK EQU P1.7 ;SPI时钟信号线 CS EQU P3.3 ;/CS片选信号线(底电平有效) DATA EQU P1.5 ;写SPI线(即主机输出从机输入) ORG 0000H LJMP MAIN ORG 0003H RETI ORG 000BH RETI ORG 0013H RETI ORG 001BH RETI ORG 0023H RETI MAIN: MOV SP, #60H MOV PSW, #0 MOV IE, #0 MOV 4DH, #00H MOV 4EH, #00H MOV 4FH, #00H MOV 5DH, #00H MOV 5EH, #01H NOP TURNONLCD: MOV 3EH, #03H ;打开LCD显示器 NOP LCALL WRSPI NOP SYSEN: MOV 3EH, #01H ;打开系统晶振 NOP LCALL WRSPI NOP CLEARDISPLAY: MOV R7, #24 MOV A, #0 MOV DPTR, #0000H RECLR: MOVX @DPTR, A ;清24段显示 INC DPTR NOP NOP DJNZ R7, RECLR NOP NOP INPUTNUM: MOV 20H, #0 ;写LCD显示器的24段的字 RECYCLE: MOV 4DH, 5DH MOV 4EH, 5EH NOP MOV R7, #24 MOV A, 20H MOV DPTR, #0000H REINPUT: PUSH DPL PUSH DPH MOV DPTR, #TAB MOVC A, @A+DPTR POP DPH POP DPL MOVX @DPTR, A INC DPTR NOP NOP DJNZ R7, REINPUT ;24个字符全部出现相同的数字 NOP NOP DISPLAY: MOV DPTR, #0000H ;显示所有字符的内容 MOV R7, #24 REPLAY: MOVX A, @DPTR NOP MOV 4FH, A LCALL WRDATA ;调用写字符数据的子程序 NOP INC DPTR NOP NOP LCALL DELAY1S ;调用延时1S子程序 NOP NOP DJNZ R7, REPLAY NOP MOV A, 5DH ADD A, #2 MOV 5DH, A MOV A, 5EH ADD A, #2 MOV 5EH, A MOV A, 20H ADD A, #1 MOV 20H, A NOP NOP CJNE A, #16 RECYCLE NOP NOP HERE: LJMP HERE ;循环结束 WRSPI: NOP ;写SPI子程序(12位数据=9位命令+3位ID命令) CLR CS CLR C ;DATA先移入3位ID命令100 CLR SCK SETB SCK SETB DATA NOP NOP CLR SCK SETB SCK CLR DATA NOP NOP CLR SCK SETB SCK CLR DATA NOP NOP MOV A, 3EH CLR SCK MOV R6, #8 WRSPI1: SETB SCK ;上升沿移入8位命令 NOP RLC A MOV DATA, C CLR SCK NOP NOP DJNZ R6, WRSPI1 NOP CLR SCK SETB SCK SETB DATA ;DATA移入最后一位数据 NOP NOP SETB CS NOP NOP RET NOP NOP NOP WRDATA: CLR CS ;写模式为写连续的地址写字符的数据和地址(2个6位地址+一个8位数据+ID号) CLR C CLR SCK ;DATA先移入写ID号101 SETB SCK SETB DATA CLR SCK SETB SCK CLR DATA CLR SCK SETB SCK SETB DATA MOV A, 4DH MOV R6, #6 ;移入第一个6位的地址 CLR SCK NOP WRDATA0: SETB SCK RLC A MOV DATA C NOP CLR SCK NOP DJNZ R6, WRDATA0 NOP MOV R6, #4 ;移入数据的底4位 CLR SCK CLR C MOV A, 4FH NOP WRDATA1: SETB SCK RRC A MOV DATA C NOP CLR SCK DJNZ R6, WRDATA1 NOP CLR SCK ;DATA先移入写ID号101 SETB SCK SETB DATA NOP CLR SCK SETB SCK CLR DATA NOP CLR SCK SETB SCK SETB DATA NOP MOV R6, #6 ;移入第二个6位的地址 CLR C MOV A, 4EH NOP CLR SCK NOP WRDATA2: SETB SCK NOP RRC A MOV DATA, C CLR SCK NOP DJNZ R6, WRDATA2 NOP NOP CLR C ;移入数据的高4位 MOV A, 4FH MOV R6, #4 CLR SCK NOP WRDATA3: SETB SCK RRC A MOV DATA, C NOP CLR SCK NOP DJNZ R6, WRDATA3 NOP NOP SETB CS NOP NOP RET NOP NOP DELAY1S: NOP ;延时1S子程序 DEL0: MOV R5, #20 DEL1: MOV R6, #200 DEL2: MOV R7, #250 NOP DJNZ R7, DEL2 NOP DJNZ R6, DEL1 NOP NOP DJNZ R5, DEL0 NOP NOP RET NOP NOP TAB: DB 08H,12H,6BH,5BH,1FH,5DH,7DH,13H ;0-7的数码段的段码表 DB 7FH,5FH,3FH,7CH,65H,7AH,6DH,2DH ;8-F的数码段的段码表 LCD有关的文件在附件中 相关链接:https://bbs.21ic.com/upfiles/img/20077/20077189218628.pdf |