试试这个
void lcd_initial(void)
{
RS=0;
delay(300);
RW=0;
ENABLE=1;
delay(300);
P0=0x38;
delay(300);
ENABLE=0;
P0=0x06;
ENABLE=1;
delay(300);
ENABLE=0;
P0=0x0c; //////
ENABLE=1;
delay(300);
ENABLE=0;
P0=0x0c;
ENABLE=1;
delay(300);
ENABLE=0;
P0=0x01;
ENABLE=1;
delay(300);
ENABLE=0;
P0=0x80;
ENABLE=1;
delay(300);
ENABLE=0;
}
/////
void writecharxy(unsigned char x,unsigned char y,unsigned char c)
{
switch(x)
{
case 0x01:
{
RS=0;
delay(300);
RW=0;
delay(300);
ENABLE=1;
delay(300);
P0=0x80|y;
delay(300);
ENABLE=0;
RS=1;
delay(300);
RW=0;
delay(300);
ENABLE=1;
delay(300);
P0=c;
delay(300);
ENABLE=0;
}
break;
case 0x02:
{
RS=0;
delay(300);
RW=0;
delay(300);
ENABLE=1;
delay(300);
P0=0xc0|y;
delay(300);
ENABLE=0;
RS=1;
delay(300);
RW=0;
delay(300);
ENABLE=1;
delay(300);
P0=c;
delay(300);
ENABLE=0;
}
break;
default:break;
}
}
//////
void delay(unsigned int t)
{
for(;t>0;t--);
} |