#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit rs=P3^5;
sbit rw=P3^6;
sbit e=P3^7;
uchar table;
sbit K1=P2^0;
sbit K2=P2^1;
sbit K3=P2^2;
sbit K4=P2^3;
uchar num;
uchar code table1[]="Huan Ying Cheng Zuo";
uchar code table2[]="Li Gong Nan Yuan Dao Le ";
uchar code table3[]="Li Gong Xue Yuan Dao Le ";
uchar code table4[]="Hua ban Qiao Dao Le";
uchar code table5[]="Xie Xie Cheng Zuo";
/*uchar code table1[]="LCD1206 check ok";
uchar code table2[]="study up"; */
void delay(uint n)
{
uint x,y;
for(x=n;x>0;x--)
for(y=110;y>0;y--);
}
void lcd_wcom(uchar com)
{
rs=0;
rw=0;
P0=com;
delay(5);
e=1;
e=0;
}
void lcd_wdat(uchar dat)
{
rs=1;
rw=0;
P0=dat;
delay(5);
e=1;
e=0;
}
void lcd_init()
{
lcd_wcom(0x38);
lcd_wcom(0x0c);
lcd_wcom(0x06);
lcd_wcom(0x01);
}
void write(uchar com1)
{
uchar j;
if(com1==0)
{ lcd_wcom(0x80);
for(j=0;j<9;j++)
{
lcd_wdat(table1[j]);
delay(5);
}
lcd_wcom(0x80+0x40+0x03);
for(j=9;j<19;j++)
{
lcd_wdat(table1[j]);
delay(5);
}
}
if(com1=1)
{
lcd_wcom(0x80);
for(j=0;j<12;j++)
{
lcd_wdat(table2[j]);
delay(5);
}
lcd_wcom(0x80+0x40+0x03);
for(j=12;j<19;j++)
{
lcd_wdat(table2[j]);
delay(5);
}
}
if(com1=2)
{ lcd_wcom(0x80);
for(j=0;j<13;j++)
{
lcd_wdat(table3[j]);
delay(5);
}
lcd_wcom(0x80+0x40+0x03);
for(j=13;j<20;j++)
{
lcd_wdat(table3[j]);
delay(5);
}
}
if(com1=3)
{
lcd_wcom(0x80);
for(j=0;j<12;j++)
{
lcd_wdat(table4[j]);
delay(5);
}
lcd_wcom(0x80+0x40+0x03);
for(j=12;j<19;j++)
{
lcd_wdat(table4[j]);
delay(5);
}
}
if(com1=4)
{
lcd_wcom(0x80);
for(j=0;j<13;j++)
{
lcd_wdat(table5[j]);
delay(5);
}
lcd_wcom(0x80+0x40+0x03);
for(j=13;j<20;j++)
{
lcd_wdat(table5[j]);
delay(5);
}
}
}
void key()
{
if(K1==0)
{
delay(2);
if(K1==0)
num=1;
while(!K1);
}
lcd_wcom(1);
}
if(K2==0)
{
delay(5);
if(K2==0&&num!=0)
num--;
while(!K2);
lcd_wcom(1);
}
if(K3==0)
{
delay(5);
if(K3==0&&num!=6)
num++;
while(!K3);
lcd_wcom(1);
}
void main()
{
uchar n;
lcd_init();
lcd_wcom(0x80);
while(1)
{
void key();
if(num==1) write(0);
else if(num==2) write(1);
else if(num==3) write(2);
else if(num==4) write(3);
else if(num==5)write(4);
else write_com(1);
}
}
总是显示:lcd1.c(151): error C141: syntax error near '5'
lcd1.c(151): error C231: '_delay': redefinition
lcd1.c(152): error C141: syntax error near 'if'
lcd1.c(152): error C141: syntax error near '==', expected ')'
lcd1.c(152): error C129: missing ';' before '!='
Target not created
|