Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to check the use of volatile keyword in MPLAB?

Status
Not open for further replies.

agg_mayur

Member level 3
Joined
Feb 25, 2010
Messages
66
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
India
Activity points
1,715
Hi All,

Please tell me how to check the volatile keyword in simplest way so that i can clear. I have tubo C, VC++, and mplab c compiler. please tell me some easy example for understanding the volatile keyword.
 

functionality of volatile can be observed on a hardware, but simulation of variable changes of volatile is not done.
E.g Is real time clock RTC, which updates time, When the power is removed the time increments and when again powered on the system erads the latest value. You cant see these things or analyse in a simulator,
 

functionality of volatile can be observed on a hardware, but simulation of variable changes of volatile is not done.
E.g Is real time clock RTC, which updates time, When the power is removed the time increments and when again powered on the system erads the latest value. You cant see these things or analyse in a simulator,

You mean this volatile keyword work like in the same manner.
vuolatile keyword take the most updated value or what,, if that variable is used in different functions for differnet tasks the what will happen?
 

vuolatile keyword take the most updated value or what,, if that variable is used in different functions for differnet tasks the what will happen?

This is only a variable that stores the value. You use volatile to variables that are handled by ISR, PORTs, or async modules, as you dont know when they will be modified. Whenever they are accessed they give only the last updated value. If you use it in all function then your source code is modifying it. value of this Variable will change if you access from all fnctions and ISR.
These are designed for 3 purposes as i have told above
 

I don think u can simulate the use of volatile in a compiler.
Volatile comes into play whenever you talk to a hardware - like an external interrupt or pointer variable to an Interrupt Service Routine. -- And the keyword advices the compiler to re-read the variable every time it is accessed instead of fetching a latest value from cache or so -- and the main reason being the interrupt variables will not be changed by the actual code.
Also, it is used to avoid compiler optimization in many cases - eg : the delay loop in embedded systems just fills with NOPs to create a delay - but actually does nothing according to the compiler and it skips the code in the name of optimization -- Volatile keyword instructs the compiler not to skip/optimize this code.
If you would like to check the use of volatile variable, go for a simple interrupt program with a controller.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top