void pulse()
{
e=1;e=0;
}
void busy_check(char right)
{
P0=0xff;
if (right==1)
{
P2=0x13;
//
P2=0x13;
while(!busy);
}
if(right==0)
{
P2=0x0b;
//0b
while(!busy);
}
}
void cmd_w(char cmd,char right)
{
busy_check(right);
if (right==1)
P2=0x10;
if (right==0)
{
P2=0x08;
P2=0x08;
}
P0=cmd;
pulse();
}
void data_w(char dat,char right)
{
busy_check(right);
if(right==1)
P2=0x14;
//0x14
if(right==0)
P2=0x0c;
//0c
P0=dat;
pulse();
}
void lcd_init()
{
uint i;
cmd_w(0x3e+1,0);//显示开关
cmd_w(0xc0+0,0);//修改显示起始行
cmd_w(0xb8+0,0);//修改页地址
cmd_w(0x40+0,0);//修改列地址
cmd_w(0x3e+1,1);
cmd_w(0xc0+0,1);
cmd_w(0xb8+0,1);
cmd_w(0x40+0,1);
for(i=0;i<256;i++)
data_w(0x00,0);
cmd_w(0xb8+4,0);
cmd_w(0x40+8,0);
for(i=0;i<256;i++)
data_w(0x00,0);
for(i=0;i<256;i++)
data_w(0x00,1);
cmd_w(0xb8+4,1);
cmd_w(0x40+8,1);
for(i=0;i<256;i++)
data_w(0x00,1);
}
char chang(char a)
{
char temp,i;
for(i=0;i<8;i++)
{
temp<<=1;
temp|=(a&0x01);
a>>=1;
}
return(temp);
}