cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

Anonymous
Not applicable

Alright, this is going to make me look really stupid, but I have searched for this error message and got zero results. I like to add an obvious indication to my code so that I know that the code loaded and at least this simple function is working, if not the others. For the following code:

   

#include <project.h>

   

int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    uint8 LED_On = 0;

   

        /* Place your initialization/startup code here (e.g. MyInst_Start()) */

   

    for(;;)
    {
        /* Place your application code here. */
        LED_Write(LED_On);
        CyDelay(500);
        LED_On = !LED_On;

   

    }
}

   

I get the following errors:

   

Build error: syntax error near 'uint8' (I assume that "uint8" is a valid type)

   

Build error: 'LED_On': undefined identifier (one per line that LED_On appears in).

   

I can't figure out how something so basic is a problem except that I need to include another library and I find nothing that tells me what to include. What resource tells me how to write C for Creator? 

0 Likes
1 Solution
RaAl_264636
Contributor II

Hi Jeffery,

   

 

   

move the variable definition of 'LED_On' at the first position in main() function (above interrupt enable) and try again.

   

If I remember correctly the Keil compiler doesn't allow definitions/declarations 'in the middle of the code'.

   

 

   

Regards,

   

 

   

Ralf

View solution in original post

0 Likes
8 Replies
JoMe_264151
Expert II

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Here it is. I just tried building again after boot, in the event that the problem was due to some machine state, and got the same results, errors.

0 Likes
RaAl_264636
Contributor II

Hi Jeffery,

   

 

   

move the variable definition of 'LED_On' at the first position in main() function (above interrupt enable) and try again.

   

If I remember correctly the Keil compiler doesn't allow definitions/declarations 'in the middle of the code'.

   

 

   

Regards,

   

 

   

Ralf

View solution in original post

0 Likes
Anonymous
Not applicable

Ralf,

   

You are amazing! That was it. I moved it to above the interrupt enable and it compiled fine. I have never seen anything about that. I am still looking for something from Cypress that presents just such issues and haven't been successful yet.

   

Thanks, Jeff

0 Likes
HeLi_263931
Honored Contributor II

This is nothing special about Cypress, or even Keil. It depends on the C-language level that supported by the Keil compiler - older version just don't allow variable declaration anywhere but on the top of the function. Probably the Keil documentation states this somewhere.

Anonymous
Not applicable

hli,

   

OK. I haven't run across that issue before this, I am training in C and C++ using CodeBlocks and have experimented with adding declarations everywhere with no problems. Prior to this I have written everything in assembler for embedded systems, due to comfort. I tried to find some information about the rules in the Keil help system but haven't found it yet.

   

I'm glad to have the community to help with stuff like this, so thanks for your reply, it's appreciated. Now I know something that I didn't. There's a lot to learn.

0 Likes
HeLi_263931
Honored Contributor II

A search for "Keil C51" (which is the compiler used) leads to http://www.keil.com/c51/ , which leads then to http://www.keil.com/support/man/docs/c51/c51_intro.htm which proudly states:

   

The Cx51 Optimizing C Compiler is a complete implementation of the American National Standards Institute (ANSI) standard for the C language.

   

If you look a little bit further you find http://www.keil.com/support/man/docs/c51/c51_xa.htm which states:

   

The Cx51 Compiler is based on ISO/IEC 9899:1990 standard (which is also known as ANSI C Standard C90).

   

When you look at Wikipedia pages for ANSI C, you find that intermingled declarations and code got introduced only with C99. Its quite a new feature...

0 Likes
RaAl_264636
Contributor II

Hi Jeffery,

   

 

   

glad that I can help 😃

   

 

   

Regards,

   

 

   

Ralf

0 Likes