| ??? 12/30/03 12:47 Read: times |
#61577 - Atomic 16bit read |
I'm going to count cycles from rotary encoder using interrupts in my program, while main loop compiles data packets to be send over serial to PC. The problem is the values will be 16 bit. So, say, I have the buffer space pointed by @R0 and issue (with some EQU label assignments earlier)
MOV @R0,ENC0L INC R0 MOV @R0,ENC0H Now if a new signal arrives between the two MOV, I get junk sent, because previous value might have been 01FFh, new value: 0200h, and what I'd send is 02FFh. The obvious solution here would be putting CLR IE before and SETB IE after the sequence, but then if an interrupt request arrives during that time, it will be lost. The interrupts are going on high priority already (to override serial and timer interrupts) so I don't think I can perform the read in "artificially triggered" high level interrupt. Any advice to solve this problem? |



