1 LCD点阵字符型液晶显示器C51编程实例
#define IOWR XBYTE[OXF800]
#define IORD XBYTE[OXF801]
#define IORS XBYTE[OXF802]
# include< stdio. h>
#include<absacc. h>
#include <intrins. h>
#define IOWR XBYTE[0XF800]
#define IORD XBYTE[0XF8011
#define IORS XBYTE[0XF802]
void c_send(unsigned char a);
void d_send(unsigned char b);
delay()
{
int i;
for(i=0;i<2000;i-1-+);
}
main()
{
delay();
c_send(0x38);
q _send(0x01);
c_Send(0x06);
c_Send(0x0c);
c_send(0x85);
d_send(0x2d);
d_send(0x35);
d_send(0x31);
c_send(0xc4);
d_send(0x4d);
d_send(0x43);
d_send(0x55);
while(1);
}
void cm-send(unsigned char a)
{
IORS=0x00;
IOWR=a;
delay();
}
void d_send(unsigned char b)
{
IORS=0x01;
IOWR=b;
delay();
}
void c_send(unsigned char y)
{
IORS=0x00;
IOWR=y;
delay();
l
void d_send(unsigned char x)
{
IORS=0x01;
IOWR=x;
delay();
}
void lcd rst(void)
{
c_send(0x38);
c_send(0x01);
c_send(0x06);
c_send(0x0c);
}
2 LCD点阵字符型液晶显示器在汇编语言编程实例
IOWR EQU 0F800H
IORD EQU 0F801H
IORS EQU 0F802H
;完整的汇编测试程序
IOWR EQU 0F800H
IORD EQU 0F801 H
IORS EQU 0F802H
ORG 4000H
LJMP MAIN
ORG 4100H
MAIN:
MOV SP,#60H
ACALL DELAY
ACALL FIRST
ACALL WRCGRAM
MOV A,#85H
ACALL WRCLCD
MOV R5,#6
MOV DPTR,#TB1
DP:
CLR A
MOVC A,@A+DPTR
ACALL WRDLCD
INC DPTR
DJNZ R5,DP
MOV A,# OC2H
ACALL WRCLCD
MOV R5,#12
MOV DPTR,#TB2
ZLG:
CLR A
MOVC A,@A+DPTR
ACALL WRDLCD
INC DPTR
DJNZ R5,ZLG
AJMP $
END
WRCLCD:
PUSH ACC
MOV A,#00H
MOV DPTR,#IORS
MOVX @DPTR,A
MOV A,R
MOV DPTR,#IOWR
MOV . DPTR,A
ACALL DELAY
POP ACC
RET
;写数据子程序
WRDLCD:
PUSH ACC
MOV DPTR,#IORS
MOV A,#01 H
MOVX DPTR,A
MOV A,R2
MOV DPTR,#IOWR
MOVX @DPTR,A
ACALL DELAY
POP ACC
RET
WRCGRAM:
MOV R2,#40H
ACALL WRCLCD
MOV R4,#24
MOV DPTR,#TBZI
CGRAMl:
CLR A
MOW A,@A+ DPTR
MOV R2,A
ACALL WRDLCD
INC DPTR
DJNZ R4,CGRAM1
ACALL DELAY
RET
FIRST:
MOV A,#38H
ACALL WRCLCD
MOV A,#01H
ACALL WRCLCD
MOV A,#06H
ACALL WRCLCD
MOV A,#0CH
ACALL WRCLCD
RET
DELAY:
MOV R7,#20H
DELAYO:
MOV R6,#20H
DELAY1:
DJNZ R6,DELAYl
DJNZ R7,DELAYO
RET