KEIL for C51 and have some problems with error like syntax error near unsigned

5.7k Views Asked by At

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!

2

There are 2 best solutions below

0
On BEST ANSWER

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.

2
On

we need to put this code

uchar a,i,j;

to the first place of your whole codes, because the Keil's C compiler is so old that it was a little bit dummy. That's why we have to declare our variables before any other code at the start of a function