AT89S52程序错误,望指教!
本人写AT89S52单片机1602显示程序出现问题,始终找不到症结,向大家请教!先行谢过!!!!
#include<reg52.h>
sbit RS=P3^4;
sbit LCDCS=P1^5;
#define uchar unsigned char;
uchar mydata;
uchar command;
uchar a;
uchar code table[]={"i love you"};
uchar code table1[15]={"my motherland"};
void delay();
void write_data();
void write_command();
void delay(uchar a)
{
unsigned int i,j;
for(i=0;i<200;i++)
for(j=0;j<a;j++);
}
void write_data(uchar mydata)
{
RS=1;
P2=mydata;
delay(5);
LCDCS=1;
delay(5);
LCDCS=0;
}
void write_command(uchar command)
{
RS=0;
P2=command;
delay(5);
LCDCS=0;
delay(5);
LCDCS=1;
}
void init()
{
LCDCS=1;
write_command(0x38);
write_command(0x0e);
write_command(0x06);
write_command(0x01);
write_command(0x80+0x10);
}
void main()
{ int num;
init();
for( num=0;num<11;num++)
{
write_dat(table[num]);
delay(20);
}
wtite_command(1);
write_command(0x80+0x53);
for( num=0;num<15;num++)
{
write_command(table1[num]);
delay(20);
}
while(1);
}
****************************************************************
编译提示:
compiling xian.c...
XIAN.C(8): error C247: non-address/-constant initializer
XIAN.C(13): error C141: syntax error near ';'
XIAN.C(19): error C141: syntax error near ';'
XIAN.C(28): error C141: syntax error near ';'
xian.c - 4 Error(s), 0 Warning(s).
[解决办法]
问题如下.
1 #define uchar unsigned char; 多了个分号,这种定义,不应该用 #define 而应该是
typedef unsigned char U16,BYTE,ucahr; 这种写法.
2 void delay(uchar a);
void write_data(uchar);
void write_command(uchar);
这几个函数的定义没有写清楚参数表.
3 有个函数有拼写错误
[解决办法]
只需要把第四行的分号去掉即可
[解决办法]
使用#define 宏定义 没有分号呢 因为不是一个语句