新手求助,一个简单的显示数码管程序
# include <reg51.h>
# include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code dis[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay(uint);
void main()
{
uchar*p;
p=dis;
uchar k;
uchar wei=0x8f;
while(1)
{
for(k=0;k<10;++k)
{
P0=*p++;
wei=_crol_(wei,1);
P2=wei;
delay(10);
}
}
}
void delay(uint x)
{
uint i;
while (x--)
{
for (i=0;i<200;++i);
}
}
尽然报错,好像没有错啊
compiling 8seg.c...
8SEG.C(12): error C141: syntax error near 'unsigned'
8SEG.C(12): error C202: 'k': undefined identifier
8SEG.C(13): error C141: syntax error near 'unsigned'
8SEG.C(13): error C202: 'wei': undefined identifier
8SEG.C(16): error C202: 'k': undefined identifier
8SEG.C(19): error C202: 'wei': undefined identifier
8SEG.C(20): error C202: 'wei': undefined identifier
8seg.c - 7 Error(s), 0 Warning(s).
[解决办法]
void main() { uchar*p; p=dis;//把这行移到here下面那行去,变量声明不能在非声明的语句后面 uchar k; uchar wei=0x8f;//here while(1)
[解决办法]
这不是缺陷,是C89的语法,C89要求变量必须定义在"{"的后面,不能定义在代码中间;C99和C++是支持将变量定义在代码中间的。