This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

89C51 programming

Hi,

A real silly problem. I am currently learning how to program this guy, ATMEL 89C51. I had a LED on Port 1 pin 0. 4MHz crystal with 30pF caps to ground, resent to ground, grounded the uC, 5v to Vcc. And the my program can't compile.
==========
#include <AT89X51.H>
#include <stdio.h>
int main()
{
int x,led;
sbit led = P1 ^ 0;
while(1)
{ led = 1;
for (x=0;x<10000;x++);
;
led = 0;
for (x=0;x<10000;x++);
}
return(0);
}

/*
..\test.C(7): error C141: syntax error near 'sbit'
Target not created
*/

Someone tell me wats wrong? Do I have to configure the Ports ie. CWR? Like wat I have to do programming a 8255 PPI chip?

Thank you,

hengkc.geo@yahoo.com

Parents
  • Heng,

    Since you already have a led sbit declaration you don't need other variable with the same name. Your sbit declaration shoud be in a global area.

    #include <reg51.h>
    #include <stdio.h>
    
    sbit led = P1 ^ 0; //compilation time definition, 
                       //it must be in the global area
    
    int main(void)
    {
    int x;
    
    while(1)
    { 
    
    led = 1;
    for (x=0;x<10000;x++);
    
    led = 0;
    for (x=0;x<10000;x++);
    }
    return(0);
    }

    This should work...

Reply
  • Heng,

    Since you already have a led sbit declaration you don't need other variable with the same name. Your sbit declaration shoud be in a global area.

    #include <reg51.h>
    #include <stdio.h>
    
    sbit led = P1 ^ 0; //compilation time definition, 
                       //it must be in the global area
    
    int main(void)
    {
    int x;
    
    while(1)
    { 
    
    led = 1;
    for (x=0;x<10000;x++);
    
    led = 0;
    for (x=0;x<10000;x++);
    }
    return(0);
    }

    This should work...

Children