#define uchar unsigned char
#define uint unsigned int
#define LCM P0 //D0~D7
#define LED P1
sbit P_CS1=P2^3; //CS1 15
sbit P_CS2=P2^4; //CS2 16
sbit P_RST=P2^5; //RST 17
sbit P_DI=P2^0; //RS 4
sbit P_RW=P2^1; //RWL 5
sbit P_E=P2^2; //CE 6
//sbit LED = P1;
void delay(uint k);
void write(uchar dd,uchar di,uchar cs);
uchar read(uchar di,uchar cs);
void reset();
void wdata(uchar dd,uchar x,uchar y);
void set_line(uchar i);
void lcd_init(void);
void dison_off(uchar c);
uchar lcd_busy(void);
void main()
{
uchar i,dd;
dd = 0xff;
while (1)
{
LED = 0xff;
LCM = 0x00;
lcd_init();
delay(1000);
for(i=0;i<8;i++){
lcd_busy();
delay(1000);
wdata(dd,2,i);
delay(2000);
}
delay(5000);
}
}
uchar lcd_busy(void)
{
uchar c;
c = read(0,1);
LED = c;
return 0x80&&c;
}
void dison_off(uchar c)
{
uchar com;
com = 0x3e + c;
write(com,0,1);
write(com,0,0);
}
void lcd_init(void)
{
reset();
set_line(0);
dison_off(1);
}
void wdata(uchar dd,uchar x,uchar y)
{
uchar cs,com;
if (y>=64){
cs = 0;
y = y-64;
}else{
cs = 1;
}
com = 0xb8 + x%8;
write(com,0,cs); //set page
com = 0x40 + x%64;
write(com,0,cs); //set y
//com = 0x80 + (0x3F && y);
//write(com,0,cs); //set column
write(dd,1,cs);
}
void write(uchar dd,uchar di,uchar cs)
{
P_E = 0;
P_RW = 0;
P_CS1 = cs;
P_CS2 = !P_CS1;
P_DI = di;
delay(1);
P_E = 1;
LCM = dd;
delay(1);
P_E = 0;
delay(1);
}
uchar read(uchar di,uchar cs)
{
uchar dd;
P_E = 0;
P_RW = 1;
P_CS1 = (cs && 0x01);
P_CS2 = (cs && 0x02);
P_DI = di;
delay(2);
P_E = 1;
dd = LCM;
P_E = 0;
return dd;
}
void reset()
{
P_RST=0;
delay(20);
P_RST=1;
delay(20);
}
//设定起始行
void set_line(uchar i)
{
i = 0xc0+i;
write(i,0,1);
}
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
} |