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

C51 compiler interrupt routine instructions.

Hello all,
I have been PIC controller for a while, I am now looking forward to learn more about. I have downloaded the Eval kit of Keil (C51), but I don't seem to find informative instructions on Eval version. Does any know where can I get helpful document?
I want to look into stuff like interrupt routine creating and other software flexibility.

  • Interrupt routines are dead simple:

    //  Interrupt vectors (C51 won't allow these to be enum's). Vect# = (VectAddr - 3) / 8
    #   define EXTERNAL_INTERRUPT_0_VECTOR   0
    #   define TIMER_0_OVERFLOW_VECTOR       1
    #   define EXTERNAL_INTERRUPT_1_VECTOR   2
    #   define TIMER_1_OVERFLOW_VECTOR       3
    #   define UART_VECTOR                   4
    #   define TIMER_2_OVERFLOW_VECTOR       5 /* and EXTERNAL_INTERRUPT_2_VECTOR */
    #   define PCA_VECTOR                    6
    
    #   define REG_BANK_0                    0
    #   define REG_BANK_1                    1
    #   define REG_BANK_2                    2
    #   define REG_BANK_3                    3
    
    volatile static char s_inChar;
    volatile static char s_outChar;
    
    static void isrUart(void) interrupt UART_VECTOR using REG_BANK_1
    {
        if (RI) 
        {
            RI       = 0;
            s_inChar = SBUF;
        }
        if (TI)
        {
            TI = 0;
        }
    }
    

    Any time the hardware sets RI or TI (receive or transmit interrupt bits) you will end up in isrUart().

    Just write get and putchar() and Keil will do the rest. You might want to use ring buffers for send and recv otherwise the ISR actually slows you down.

    - Mark

  • All the documents are in PDF on the CD.

    The content is identical to the full printed manuals.

    The CD is free!