We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a global int variable, and it will be change in ISR
because 8051 is a 8-bit MCU
I have a code if(a == 0) it needs to check lowwer byte= 0 and higher byte =0
but interrupt a--; so if a=0x100 lowwer byte =0 interrupt happen a = 0x0ff higher byte = 0
It will have a wrong result
How ca I do?
The keyword here is "Atomicity" - it is well covered in The Literature
An Atomic operation is one that cannot be interrupted.
As you correctly observe, 16-bit operations are not Atomic on an 8051 - therefore you will need to disable the interrupt while you do the check.
Or maybe you could have your ISR provide a separate a_is_zero flag (then, maybe, the value of 'a' need not be public?)
Thanks your help! Does Keil C support "atomic" ?
"Does Keil C support 'atomic'"
Depends on what you mean by "support".
It doesn't have any keywords or extensions to specifically make things atomic.
But it does have everything that you require to make portions of your code atomic.
As I said before,
"16-bit operations are not Atomic on an 8051 - therefore you will need to disable the interrupt while you do the check.
"Or maybe you could have your ISR provide a separate a_is_zero flag (then, maybe, the value of 'a' need not be public?)"
Note that these are things that you need to do by suitable coding in your program - and C51 provides everything you need for them!