求指点错误
程序如下:
#include
#include
#define DA P3 //
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
void Delay(unsigned int x);
void write(unsigned char i,bit j)
{
DA=i; //其中j=0,写指令;j=1,写数据;
RS=j;
RW=0;
EN=1;
EN=0;
}
void lcd_init()
{
write(0x0c,0);
Delay(1);
write(0x38,0);
Delay(1);
write(0x06,0);
Delay(1);
}
void write_display(bit hang,unsigned char weizhi,unsigned char data1)
{
if(hang==0)
write(0x80+weizhi,0);
if(hang==1)
write(0xC0+weizhi,0); //1000 0000+0100 0000+weizhi
Delay(5);
write(data1,1);
Delay(5);
}
void main()
{
int i;
unsigned char xingming[]="xing mi ng";
unsigned char xuehao[]={2,0,1,5,0,3,0,8,5,6};
lcd_init();
while(1)
{
for(i=0;i<10;i++)
write_display(0,3+i,xingming[i]);
for(i=0;i<10;i++)
write_display(1,3+i,xuehao[i]+0x30);
}
}
void Delay(unsigned int x)
{
unsigned char a,b,c;
for(c=x;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}