Phatline Posted January 27, 2016 Report Share Posted January 27, 2016 (edited) 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? Edited January 27, 2016 by Phatline Quote Link to comment Share on other sites More sharing options...
Hawkeye Posted January 28, 2016 Report Share Posted January 28, 2016 Ok, here is a simple example: 1) define the variable in exactly one module (e.g. in this case "hardware.c") file u8 led_startstop = 14; 2) 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 Quote Link to comment Share on other sites More sharing options...
kpete Posted January 29, 2016 Report Share Posted January 29, 2016 (edited) 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. Edited January 29, 2016 by kpete 1 Quote Link to comment Share on other sites More sharing options...
Phatline Posted January 29, 2016 Author Report Share Posted January 29, 2016 thx guys its clear and working now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.