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

(Probably simple) syntax error

I've written my first program in Keil uVision2 just to toggle a led with my 8052 microcontroller.

Code looks like this:

#define P3 *(volatile unsigned int *)0x00B0;
//I/O pin to be toggled



void main (void)
{
//declarations
unsigned int toggle = 0x01;
unsigned long i;
//dummy variable to slow down led toggling

//main program
while (1)
{
for (i=0; i<=1000000; i++);
toggle ^= 0x01;
if (toggle == 0x00)
* P3 = 0x01;
* else
* P3 = 0x00;
}
}

The compiler complains about the lines in the if-else construction marked with an "*".
It says:
syntax error near '='
syntax error near 'elsi'
syntax error near '='

I have no clue what I'm doing wrong, maybe there's someone out here who has suggestions?

Parents
  • A few things pop out immediately.

    • Delete the semicolon (;) at the end of your P3 #define.
    • That define dereferences a constant pointer to location 0xB0 in the MCU's internal RAM, probably not the IO you want. If the IO is mapped as external memory, qualify the pointer as xdata. If it is an MCU port pin, you can't access it through a pointer, only via SFRs.
    • P3 is also a port name, so if you are including an 805x register header file, you'll probably want to change your define name to something else.

Reply
  • A few things pop out immediately.

    • Delete the semicolon (;) at the end of your P3 #define.
    • That define dereferences a constant pointer to location 0xB0 in the MCU's internal RAM, probably not the IO you want. If the IO is mapped as external memory, qualify the pointer as xdata. If it is an MCU port pin, you can't access it through a pointer, only via SFRs.
    • P3 is also a port name, so if you are including an 805x register header file, you'll probably want to change your define name to something else.

Children