Jump to content

variable usage in app.c and seq.c


Phatline
 Share

Recommended Posts

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 by Phatline
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...