We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello, when trying to compile an small C program with uVision3 v3.53 I'm coming across some unexpected - at least to me - compilation errors, following is the complete program:
#include <reg515c.h> #define H 1 /* H abk. von HIGH */ #define L 0 /* L abk. von LOW */ sbit P4_0 = P4^0; main() { P4 = 0xFF; /* Port 4 als Eingang eingerichtet */ /*Why on earth these lines cannot be compiled?*/ unsigned char zustand = H; unsigned int i; while(1) { for(i = 0; i <= 8; i++) { while(P4_0 == H) ; if(P4_0 == L && zustand == H) { zustand = L; P1 = i; } while(P4_0 == L) ; if(P4_0 == H && zustand == L) { zustand = H; } } } }
And the error the compiler reports are: Build target 'mM-515' assembling STARTUP.A51... compiling PinNummern.c... PINNUMMERN.C(11): error C141: syntax error near 'unsigned' PINNUMMERN.C(11): error C202: 'zustand': undefined identifier PINNUMMERN.C(12): error C141: syntax error near 'unsigned' PINNUMMERN.C(12): error C202: 'i': undefined identifier PINNUMMERN.C(13): error C202: 'zustand': undefined identifier PINNUMMERN.C(18): error C202: 'i': undefined identifier PINNUMMERN.C(22): error C202: 'zustand': undefined identifier PINNUMMERN.C(24): error C202: 'zustand': undefined identifier PINNUMMERN.C(25): error C202: 'i': undefined identifier PINNUMMERN.C(29): error C202: 'zustand': undefined identifier PINNUMMERN.C(31): error C202: 'zustand': undefined identifier Target not created
The offending lines are the ones in red, neither the variable zustand nor i have sfr or sbit type so it should be allowed to declare them inside a function. When taking those variables out of main's body this way:
#include <reg515c.h> #define H 1 /* H abk. von HIGH */ #define L 0 /* L abk. von LOW */ sbit P4_0 = P4^0; unsigned char zustand = H; unsigned int i; main() { P4 = 0xFF; /* Port 4 als Eingang eingerichtet */ /* etc */
The program compiles without errors.
Any help would be appreciated. Thanks.