⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 probe_rs232c.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    U0LCR     = DEF_BIT_07;                                     /* Set divisor access bit                                   */
    U0DLL     = divlo;                                          /* Load divisor                                             */
    U0DLM     = divhi;
    U0LCR     = 0x03;                                           /* Set line control register (Bit 8 is 0)                   */
    U0IER     = 0x00;                                           /* Disable both Rx and Tx interrupts                        */
    U0FCR     = 0x01;                                           /* Enable FIFO, flush Rx & Tx                               */

                                                                /* --------------- INITIALIZE VIC FOR UART0 --------------- */
    VICIntSelect           &= ~(1 << VIC_UART0);                        /* Enable interrupts                                */
    VICVectAddr(VIC_UART0)  = (CPU_INT32U)ProbeRS232_RxTxISRHandler;    /* Set the vector address                           */
    VICVectCntl(VIC_UART0)  =  14;
    VICIntEnable            =  (1 << VIC_UART0);                        /* Enable Interrupts                                */
#endif

#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_1)
    PCONP    |= PCUART1;                                        /* Enable UART1 peripheral.                                 */

                                                                /* --------------- COMPUTE DIVISOR BAUD RATE -------------- */
    pclk_freq =  BSP_CPU_PclkFreq(PCLK_UART1);                  /* Get the CPU clock frequency                              */
    div       = (CPU_INT16U)(((2 * pclk_freq / 16 / baud_rate) + 1) / 2);
    divlo     =  div & 0x00FF;                                  /* Split divisor into LOW and HIGH bytes                    */
    divhi     = (div >> 8) & 0x00FF;

                                                                /* ------------------- ENABLE UART1 I/Os ------------------ */
#ifdef  PROBE_RS232_LPC24XX_UART1_P3_16_17
                                                                /* (1) P3[16] = Function 11b                                */
                                                                /* (2) P3[17] = Function 11b                                */
    pinsel    = PINSEL7;
    pinsel   &= 0xFFFFFFF0;
    pinsel   |= 0x0000000F;
    PINSEL7   = pinsel;

#else
                                                                /* (1) P0[15] = Function 01b                                */
                                                                /* (2) P0[16] = Function 01b                                */
    pinsel    = PINSEL0;
    pinsel   &= 0x3FFFFFFF;
    pinsel   |= 0x40000000;
    PINSEL0   = pinsel;

    pinsel    = PINSEL1;
    pinsel   &= 0xFFFFFFFC;
    pinsel   |= 0x00000001;
    PINSEL1   = pinsel;
#endif


                                                                /* --------------------- SETUP UART1 ---------------------- */
    U1LCR     = DEF_BIT_07;                                     /* Set divisor access bit                                   */
    U1DLL     = divlo;                                          /* Load divisor                                             */
    U1DLM     = divhi;
    U1LCR     = 0x03;                                           /* 8 Bits, 1 Stop, No Parity                                */
    U1IER     = 0x00;                                           /* Disable both Rx and Tx interrupts                        */
    U1FCR     = 0x01;                                           /* Enable FIFO, flush Rx & Tx                               */

                                                                /* --------------- INITIALIZE VIC FOR UART1 --------------- */
    VICIntSelect           &= ~(1 << VIC_UART1);                        /* Enable interrupts                                */
    VICVectAddr(VIC_UART1)  = (CPU_INT32U)ProbeRS232_RxTxISRHandler;    /* Set the vector address                           */
    VICVectCntl(VIC_UART1)  =  14;
    VICIntEnable            =  (1 << VIC_UART1);                        /* Enable Interrupts                                */
#endif

#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_2)
    PCONP    |= PCUART2;                                        /* Enable UART2 peripheral.                                 */

                                                                /* --------------- COMPUTE DIVISOR BAUD RATE -------------- */
    pclk_freq =  BSP_CPU_PclkFreq(PCLK_UART2);                  /* Get the CPU clock frequency                              */
    div       = (CPU_INT16U)(((2 * pclk_freq / 16 / baud_rate) + 1) / 2);
    divlo     =  div & 0x00FF;                                  /* Split divisor into LOW and HIGH bytes                    */
    divhi     = (div >> 8) & 0x00FF;

                                                                /* ------------------- ENABLE UART2 I/Os ------------------ */
                                                                /* (1) P0[10] = Function 01b                                */
                                                                /* (2) P0[11] = Function 01b                                */
    pinsel    = PINSEL0;
    pinsel   &= 0xFF0FFFFF;
    pinsel   |= 0x00500000;
    PINSEL0   = pinsel;

                                                                /* --------------------- SETUP UART2 ---------------------- */
    U2LCR     = DEF_BIT_07;                                     /* Set divisor access bit                                   */
    U2DLL     = divlo;                                          /* Load divisor                                             */
    U2DLM     = divhi;
    U2LCR     = 0x03;                                           /* 8 Bits, 1 Stop, No Parity                                */
    U2IER     = 0x00;                                           /* Disable both Rx and Tx interrupts                        */
    U2FCR     = 0x01;                                           /* Enable FIFO, flush Rx & Tx                               */

                                                                /* --------------- INITIALIZE VIC FOR UART2 --------------- */
    VICIntSelect           &= ~(1 << VIC_UART2);                        /* Enable interrupts                                */
    VICVectAddr(VIC_UART2)  = (CPU_INT32U)ProbeRS232_RxTxISRHandler;    /* Set the vector address                           */
    VICVectCntl(VIC_UART2)  =  14;
    VICIntEnable            =  (1 << VIC_UART2);                        /* Enable Interrupts                                */
#endif

#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_3)
    PCONP    |= PCUART3;                                        /* Enable UART3 peripheral.                                 */

                                                                /* --------------- COMPUTE DIVISOR BAUD RATE -------------- */
    pclk_freq =  BSP_CPU_PclkFreq(PCLK_UART3);                  /* Get the CPU clock frequency                              */
    div       = (CPU_INT16U)(((2 * pclk_freq / 16 / baud_rate) + 1) / 2);
    divlo     =  div & 0x00FF;                                  /* Split divisor into LOW and HIGH bytes                    */
    divhi     = (div >> 8) & 0x00FF;

                                                                /* ------------------- ENABLE UART3 I/Os ------------------ */
                                                                /* (1) P0[0]  = Function 11b                                */
                                                                /* (2) P0[1]  = Function 11b                                */
    pinsel    = PINSEL0;
    pinsel   &= 0xFFFFFFF0;
    pinsel   |= 0x0000000F;
    PINSEL0   = pinsel;

                                                                /* --------------------- SETUP UART3 ---------------------- */
    U3LCR     = DEF_BIT_07;                                     /* Set divisor access bit                                   */
    U3DLL     = divlo;                                          /* Load divisor                                             */
    U3DLM     = divhi;
    U3LCR     = 0x03;                                           /* 8 Bits, 1 Stop, No Parity                                */
    U3IER     = 0x00;                                           /* Disable both Rx and Tx interrupts                        */
    U3FCR     = 0x01;                                           /* Enable FIFO, flush Rx & Tx                               */

                                                                /* --------------- INITIALIZE VIC FOR UART3 --------------- */
    VICIntSelect           &= ~(1 << VIC_UART3);                        /* Enable interrupts                                */
    VICVectAddr(VIC_UART3)  = (CPU_INT32U)ProbeRS232_RxTxISRHandler;    /* Set the vector address                           */
    VICVectCntl(VIC_UART3)  =  14;
    VICIntEnable            =  (1 << VIC_UART3);                        /* Enable Interrupts                                */
#endif
}


/*
*********************************************************************************************************
*                                     ProbeRS232_RxTxISRHandler()
*
* Description : Handle receive and transmit interrupts.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : This is an ISR.
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  ProbeRS232_RxTxISRHandler (void)
{
    volatile  CPU_INT08U  rx_data;
    volatile  CPU_INT08U  lsr;
    volatile  CPU_INT08U  iir;



#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_0)                /* ------------------------- UART0 ------------------------ */
    iir = U0IIR & 0x0F;
    while (iir != 1) {
        switch (iir) {
            case  2:                                            /* Transmitted character?                                   */
                 ProbeRS232_TxHandler();
                 break;

            case  4:                                            /* Received a character?                                    */
                 lsr     = U0LSR;
                 rx_data = U0RBR;
                 ProbeRS232_RxHandler(rx_data);                 /* Call the generic Rx handler                              */
                 break;

            default:
                 break;
        }
        iir = U0IIR & 0x0F;
    }
#endif

#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_1)                /* ------------------------- UART1 ------------------------ */
    iir = U1IIR & 0x0F;
    while (iir != 1) {
        switch (iir) {
            case  2:                                            /* Transmitted character?                                   */
                 ProbeRS232_TxHandler();
                 break;

            case  4:                                            /* Received a character?                                    */
                 lsr     = U1LSR;
                 rx_data = U1RBR;
                 ProbeRS232_RxHandler(rx_data);                 /* Call the generic Rx handler                              */
                 break;

            default:
                 break;
        }
        iir = U1IIR & 0x0F;
    }
#endif

#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_2)                /* ------------------------- UART2 ------------------------ */
    iir = U2IIR & 0x0F;
    while (iir != 1) {
        switch (iir) {
            case  2:                                            /* Transmitted character?                                   */
                 ProbeRS232_TxHandler();
                 break;

            case  4:                                            /* Received a character?                                    */
                 lsr     = U2LSR;
                 rx_data = U2RBR;
                 ProbeRS232_RxHandler(rx_data);                 /* Call the generic Rx handler                              */
                 break;

            default:
                 break;
        }
        iir = U2IIR & 0x0F;
    }
#endif

#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_3)                /* ------------------------- UART3 ------------------------ */
    iir = U3IIR & 0x0F;
    while (iir != 1) {
        switch (iir) {
            case  2:                                            /* Transmitted character?                                   */
                 ProbeRS232_TxHandler();
                 break;

            case  4:                                            /* Received a character?                                    */
                 lsr     = U3LSR;
                 rx_data = U3RBR;
                 ProbeRS232_RxHandler(rx_data);                 /* Call the generic Rx handler                              */
                 break;

            default:
                 break;
        }
        iir = U3IIR & 0x0F;
    }
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -