I am working with Keil for 80C51 and I use C51 for coding. However, I have some problem in my compiling. My code is like following:
#include <reg51.h>
#define uchar unsigned char
#define LED P2
sbit SH=P0^0;
sbit DATA=P3^0;
sbit CLK=P3^1;
void main()
{
SCON=0x10;
uchar a,i,j;
while(1){
a=0;
SH=0;
SH=1;
for (i=0;i<8;i++){
CLK=0;
for (j=0;j<500;j++);
DATA=0;
CLK=1;
for (j=0;j<500;j++);
a=a<<1;
a=a+(uchar)DATA;
}
LED=a;
}
}
But the compiler shows that lab7.c(13): error C141: syntax error near 'unsigned'. I have no idea why this would happen! Many Thanks!
Declare your variables before any other code at the start of a function:
void main()
{
uchar a,i,j;
SCON=0x10;
while(1){
/* ... */
This is an old C compiler limit that was never removed in Keil C51.