??? 01/08/08 09:47 Read: times |
#149123 - Some advice Responding to: ???'s previous message |
1. Depending on the compiler you are using, there might be some differences in how pointers are handled. Keil C51, for example, distinguishes between generic and memory-specific pointers, and you usually want to use the latter if you know beforehand that your pointer is only going to point to one type of memory (i.e. code space, xdata space or idata space). This should be explained in detail in the compiler's manual.
2. You are modifying PtrRx in your interrupt service routine, and you are using PtrRx in comparisons in your main loop. This has a chance of causing atomicity issues, which means that the comparison in your main loop may consist of comparing several bytes (if the pointer is longer than 1 byte) that may be interrupted by the ISR. The result is usually undefined and therefore unwanted behavior. A small example: Suppose you have a 16 bit variable called a_example, which is incremented in an ISR and compared to some value in the main loop. unsigned int a_example; int main(void) { ... if(a_example == 0x01FF) { // this should never happen } ... } void some_isr(void) { a_example++; if(a_example > 0x0101) { a_example = 0; } } a_example should never become 0x01FF in this code, but there is a chance that the comparison in the main loop wil be true if the code first checks the low byte when it is 0xFF, is interrupted by some_isr which increments a_example to 0x0100, and then compares the high byte to 0x01 (which is true). You will need to analyze your code for potential atomicity problems and deal with them in some way (the most simple, but also the most disruptive way being disabling the interrupts temporarily when dealing with the variable in the main loop). |