This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to use using "x"

Who can tell me the main usage of "using x" in interrupt service?

Parents
  • There will be no conflict since neither the array nor the index are in registers. They are outside function scope and thus have static duration.

    You will however need to tell the C compiler that the variables may change without notice (that is, the background function will see the values change magically after the serial ISR occurs). Use volatile for this.

    Be sure to type every variable with data, idata, xdata, code, etc. That way you don't get any surprises if you change memory models. Try to use the SMALL model always.

    #define SER_BUF_SIZE 64
    volatile char xdata s_serBuf[SER_BUF_SIZE];
    volatile char data  bufIdx;
    
    void main(void)
    {
        while (strchr(s_serBuf, 'E'));
        ...
    }
    
    void isrUart(void) interrupt UART_VEC using 1
    {
        if (RI)
        {
            RI = 0;
            s_serBuf[serIdx] = SBUF;
            serIdx = (serIdx + 1) % sizeof s_serBuf;
        }
    }
    

    Note that post incr/decr takes more instructions than using the index and then incr/decr on the next line.

    - Mark

Reply
  • There will be no conflict since neither the array nor the index are in registers. They are outside function scope and thus have static duration.

    You will however need to tell the C compiler that the variables may change without notice (that is, the background function will see the values change magically after the serial ISR occurs). Use volatile for this.

    Be sure to type every variable with data, idata, xdata, code, etc. That way you don't get any surprises if you change memory models. Try to use the SMALL model always.

    #define SER_BUF_SIZE 64
    volatile char xdata s_serBuf[SER_BUF_SIZE];
    volatile char data  bufIdx;
    
    void main(void)
    {
        while (strchr(s_serBuf, 'E'));
        ...
    }
    
    void isrUart(void) interrupt UART_VEC using 1
    {
        if (RI)
        {
            RI = 0;
            s_serBuf[serIdx] = SBUF;
            serIdx = (serIdx + 1) % sizeof s_serBuf;
        }
    }
    

    Note that post incr/decr takes more instructions than using the index and then incr/decr on the next line.

    - Mark

Children
No data