| ??? 09/09/02 05:47 Read: times |
#28869 - RE: Making Global variables interrupt safe? |
I would assume they are asking how you can make global variables "safe" when those global variables are used both by interrupts and the main program.
If you have such a variable and the main program was executing something like VAR = VAR * 1234 + X and, in the middle of that operation, an interrupt was triggered that set VAR=0, you'd have a problem. The value of VAR would be modified midway through the expression evaluation. The way to protect against such errors is to disable any interrupt that can modify VAR before the main program modifies VAR. Then re-enable it after the modification is complete. This is also a perfect use for CLR EA and SETB EA which lets you quickly disable/enable all interrupts. So just execute the CLR EA before modifying the global variable and SETB EA after you're done. This should only be necessary if the global variable is modified both in the "main" program as well as interrupt(s). Regards, Craig Steiner |
| Topic | Author | Date |
| Making Global variables interrupt safe? | 01/01/70 00:00 | |
| RE: Making Global variables interrupt safe? | 01/01/70 00:00 | |
| RE: Making Global variables interrupt safe? | 01/01/70 00:00 | |
| RE: Making Global variables interrupt safe? | 01/01/70 00:00 | |
| RE: Making Global variables interrupt sa | 01/01/70 00:00 | |
| RE: Using/Avoiding Global variables | 01/01/70 00:00 | |
| RE: Making Global variables interrupt safe? | 01/01/70 00:00 | |
| RE: Making Global variables interrupt sa | 01/01/70 00:00 | |
| RE: Making Global variables interrupt sa | 01/01/70 00:00 | |
| RE: Making Global variables interrupt sa | 01/01/70 00:00 | |
| RE: Making Global variables interrupt safe? | 01/01/70 00:00 | |
| RE: Making Global variables interrupt safe? | 01/01/70 00:00 | |
| RE: Making Global variables interrupt #2 | 01/01/70 00:00 | |
| RE: Making Global variables interrupt #2 | 01/01/70 00:00 | |
RE: Franc | 01/01/70 00:00 |



