hello, i have to fight with some basic things…
I want to work with shared variables in booth Functions…seq.c and app.c
as example:
u8 PageFirst = 50;
so what i found out:
declare it in app.c > seq.c will not recognize it. (as extern u8, or only u8 > don’t matter)
declare it in seq.c > app.c will not recognize it. (as exetrn u8, or only u8 > don’t matter)
declare and initialize it in app.h as u8 PageFirst = 50; wont work
declare it in app.h as u8 PageFirst; works
but i have to initialize it anywhere separate like:
void APP_Init(void){PageFirst = 50;}
and that i dont like… is there a other way?
Ok, here is a simple example:
-
define the variable in exactly one module (e.g. in this case “hardware.c”) file
u8 led_startstop = 14;
-
declare the variable as “extern” for use in the corresponding header (e.g. in this case “hardware.h”) included by other modules (other .c files)
extern u8 led_startstop;
Now you can use the variable in the original c file, as well as in all other .c files, that include the header.
Good luck and many greets!
Peter
kpete
3
And your " u8 led_startstop = 14; " must be outside of any function. If it was inside a function then it can only be found and used by that function.
1 Like
thx guys
its clear and working now.