romel_emperado
Advanced Member level 2
- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
every time variable is accessed? even we do not call this function?if we use volatile modifier, this disables optimisation, forcing the program to fetch a new value from the variable every time variable is accessed.
void update(void)
{
time =time+1;
}
volatile is suitable for functions like ISR because these ISR are never called but the interrupt is generated. So when ever you enter the ISR routine the value will be updated automatically and will not be visible to other functions.
volatine variable;
void interrupt sample()
{
if(variable==5)
variable = 0;
}
I wish to know more things as
Volatile is used for variables whose value keeps changing frequently without the control of the program flow... in your case i dont see the variable value getting changed ..
you are just taking a variable and comparing it with 5. but somewhere the variable has to change to meet the condition
if (variable == 5)
where is this incremented and does it increment in the program or it is incremented only when ISR routine executes...
when would variable be equal to 5 in your case....
remember volatile should be global variable...
volatine variable;
void interrupt sample()
{
variable = variable; //Im thinking by calling just like this will increment the value
if(variable==5)
variable = 0;
}
When we use the word Optimise, we mean that the variable in the memory can be changed only by the compiler whenever the code is executed.
Volatile modifiers cannot be optimised by the compiler, During linking process the code is allocated physical memory in the internal memory. so during the link process( generation of .lnk file during compilation) these variables are placed in the heap instead of main memory. Compiler cannot modify the variable until unless a copy is copied to RAM for execution. So the compiler allocates a different memory location for the variable. These are called un-optimised location. the variables in this location are not dependent on the compiler to change the value. instead interrupt, ports, serial, hardware are given permission to access these variables when ever they raise a request.
the variables in this location are not dependent on the compiler to change the value. instead interrupt, ports, serial, hardware are given permission to access these variables when ever they raise a request
It will not increment the value in that case, volatile variables do not change by itself as i said.. like there should be some statement that should change the value, or there should be some hadrware like ports or some hardware to change the value... volatile will just store the last updated value and would give the user only the last updated value.
it prevents any optimization that might re-order the evaluation of volatile variables relative to other volatile variables.
So volatile is just a variable who work is to store the content of the data of the last modification.
take eg of rtc. (real time clock)... Power failure is an interrupt, but even then the time gets incremented. and when power is restored it gives only last updated value and not the history of changes done during the power failure time...
Can i compile Embedded C programs in normal C compilers.
Can i compile Embedded C programs in normal C compilers.
I guess, you meant a regular ANSI-C compiler used for application programs, and without any proprietary extensions.
Such a compiler would compile Embedded-C programs for as long as it is a proper subset of ANSI-C, and doesn't use any unusual or invalid pragmas.
Also it should find the header files required, but then your Embedded-C program may bring with itself several target-specific, non-standard header files, which your ANSI-C compiler might not find. Finally, modern C compilers invoke the linker automatically and any target specific libraries that are shipped with Embedded-C toolchain, might not be found by ANSI-C linker.
TURBO C++ we used it in school for studying C++.
If we are writing a program for AVR can i compile it in PC (x86). How are the ports mentioned?
Which compiler software do you recommend.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?