#include <reg51.h>
#define uchar unsigned char
#define unit unsigned int
sbit rs=P2^6;
sbit rw=P2^5;
sbit e=P2^7;
uchar table1[]= "welcome!" ;
uchar table2[]= "1234567890123456";
//************************************
void delay (unit t)
{
uchar j;
for(t>0;t--)
for(j=125;j>0;j--);
}
//write com***************************
void write_com(uchar com)
{
e=0;
rs=0;
rw=0;
P0=com;
delay(1);
e=1;
delay(1);
e=0;
}
//write dat***************************
void write_dat(uchar dat)
{
e=0;
rs=1;
rw=0;
P0=dat;
delay(1);
e=1;
delay(1);
e=0;
}
void main();
{
uchar j;
init();
write_com(0x80);
for(j=0;j<16;j++);
{
write_dat(table1[j]);
delay(1);
}
write_com(0x80+0x40);
for(j=0;j<16;j++);
{
write_dat(table2[j]);
delay(1);
}
}
//LCD初始化***************************
void init()
{
delay (15);
write_com(0x38);
delay(5);
write_com(0x38);
delay(5);
write_com(0x38);
write_com(0x38);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
}
编译出现
LCD.C(17): error C141: syntax error near ')'
LCD.C(49): error C141: syntax error near '{'
LCD.C(52): error C141: syntax error near '0x80'
LCD.C(52): error C231: '_write_com': redefinition
LCD.C(53): error C141: syntax error near 'for'
LCD.C(53): error C141: syntax error near '=', expected ')'
LCD.C(53): error C129: missing ';' before '<'
此帖出自
小平头技术问答
1、下面第一个for语句错误
//************************************
void delay (unit t)
{
uchar j;
for(t>0;t--)
for(j=125;j>0;j--);
}
2、main后面不用分号
void main();
{
uchar j;
init();
……
3、函数顺序错误,如果前面没有声明函数,要按照函数调用次序来写,main一般在最后。init()应放置在main前。
#define uchar unsigned char
#define unit unsigned int
sbit rs=P2^6;
sbit rw=P2^5;
sbit e=P2^7;
uchar table1[]= "welcome!" ;
uchar table2[]= "1234567890123456";
//************************************
void delay (unit t)
{
uchar j;
for(;t>0;t--)
for(j=125;j>0;j--);
}
//write com***************************
void write_com(uchar com)
{
e=0;
rs=0;
rw=0;
P0=com;
delay(1);
e=1;
delay(1);
e=0;
}
//write dat***************************
void write_dat(uchar dat)
{
e=0;
rs=1;
rw=0;
P0=dat;
delay(1);
e=1;
delay(1);
e=0;
}
void LcmInit(void)
{
delay (15);
write_com(0x38);
delay(5);
write_com(0x38);
delay(5);
write_com(0x38);
write_com(0x38);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
}
void Main( void )
{
uchar j;
LcmInit();
write_com(0x80);
for(j=0;j<16;j++);
{
write_dat(table1[j]);
delay(1);
}
write_com(0x80+0x40);
for(j=0;j<16;j++);
{
write_dat(table2[j]);
delay(1);
}
}
呵呵,哥们还是刚上大学吧。。。。。。似乎c语言不过关啊。。。。。。。
一周热门 更多>