ovy_pas Postat Ianuarie 18, 2012 Autor Partajează Postat Ianuarie 18, 2012 cum, cand pot fi folosite variabilele volatile? Link spre comentariu
Liviu M Postat Ianuarie 18, 2012 Partajează Postat Ianuarie 18, 2012 Citat din manualul Hi-Tech picc: 3.4.6.2 VOLATILE TYPE QUALIFIERThe volatile type qualifier is used to tell the compiler that an object cannot be guaranteedto retain its value between successive accesses. This prevents the optimizerfrom eliminating apparently redundant references to objects declared volatilebecause it may alter the behavior of the program to do so.Any SFR which can be modified by hardware or which drives hardware is qualified asvolatile, and any variables which may be modified by interrupt routines should usethis qualifier as well. For example:volatile static unsigned int TACTL @ 0x160;The volatile qualifier does not guarantee that any access will be atomic, which isoften not the case with the PIC10/12/16 architecture, which can only access a maximumof 1 byte of data per instruction.The code produced by the compiler to access volatile objects may be different tothat to access ordinary variables, and typically the code will be longer and slower forvolatile objects, so only use this qualifier if it is necessary. However failure to usethis qualifier when it is required may lead to code failure.Another use of the volatile keyword is to prevent variables being removed if theyare not used in the C source. If a non-volatile variable is never used, or used in away that has no effect on the program’s function, then it may be removed before codeis generated by the compiler.A C statement that consists only of a volatile variable’s name will produce code thatreads the variable’s memory location and discards the result. For example the entirestatement:PORTB;will produce assembly code the reads PORTB, but does nothing with this value. This isuseful for some peripheral registers that require reading to reset the state of interruptflags. Normally such a statement is not encoded as it has no effect.Some variables are treated as being volatile even though they may not be qualifiedin the source code. See Section 3.13.4.2 “Undefined Symbols” if you have assemblycode in your project. Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum