一个简单的程序,但用keil编译时出现这样的错误提示:
Build target 'Target 1'
assembling STARTUP.A51...
compiling main.c...
MAIN.C(28): error C141: syntax error near 'else'
Target not created
程序如下:
#include"reg52.h"
#include"intrins.h"
#define uint unsigned int
#define uchar unsigned char
uint times=0;
void timer0() interrupt 1
{
TL0=(65526-50000)%256;
TH0=(65536-50000)/256;
times++;
}
void main()
{
uchar temp;
TMOD=0x0;
TL0=(65526-50000)%256;
TH0=(65536-50000)/256;
EA=1;
ET0=1;
TR0=1;
temp=0xfe;
P2=0xfe;
while(1)
{
if(times==20)
temp=_crol_(temp,1);
P2=temp;
else if(times==30)
{
P2=0xff;
times=0;
}
}
}
#include"reg52.h"
#include"intrins.h"
#define uint unsigned int
#define uchar unsigned char
uint times=0;
void timer0() interrupt 1
{
TL0=(65526-50000)%256;
TH0=(65536-50000)/256;
times++;
}
void main()
{
uchar temp;
TMOD=0x0;
TL0=(65526-50000)%256;
TH0=(65536-50000)/256;
EA=1;
ET0=1;
TR0=1;
temp=0xfe;
P2=0xfe;
while(1)
{
if(times==20)
temp=_crol_(temp,1);
P2=temp;
else if(times==30)
{
P2=0xff;
times=0;
}
}
}
请问高手们,这else附近有什么错误?不知是水平有限还是思维定势,我怎么看都看不出有什么错误来。
谢谢指教!
改了TMOD=0x01,但还是不行。
这是语法错误,不是逻辑错误啊。