新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > LPC1114 UART收發實驗

        LPC1114 UART收發實驗

        作者: 時間:2016-11-10 來源:網絡 收藏
        串口是很多實驗的基礎,可以作為其他實驗運行的驗證。在做LPC1114 UART實驗時,發現的例程只有發送函數,而且是發送字符串的,所以本人完善了一些,添加了一個發送字符串的函數UARTSendByte(),一個接受字符的函數UARTReceiveByte(),一個接受字符串函數UARTReceive()。具體的代碼如下:

        // 發送字符函數

        本文引用地址:http://www.104case.com/article/201611/317367.htm

        /*****************************************************************************
        ** Function name:UARTSendByte
        **
        ** Descriptions:Send a block of data to the UART 0 port based
        **on the data Byte
        **
        ** parameters:send data
        ** Returned value:None
        **
        *****************************************************************************/
        void UARTSendByte(uint8_t dat)
        {
        while ( !(LPC_UART->LSR & LSR_THRE) )
        {
        ; // 等待數據發送完畢
        }

        LPC_UART->THR = dat;
        }

        // 接受字符函數

        /*****************************************************************************
        ** Function name:UARTReceiveByte
        **
        ** Descriptions:Receive a block of data to the UART 0 port based
        **on the data Byte
        **
        ** parameters:None
        ** Returned value:Byte
        **
        *****************************************************************************/
        uint8_t UARTReceiveByte(void)
        {
        uint8_t rcvData;

        while (!(LPC_UART->LSR & LSR_RDR))
        {
        ; // 查詢數據是否接收完畢
        }

        rcvData = LPC_UART->RBR; // 接收數據
        return (rcvData);
        }

        // 接收字符串函數

        /*****************************************************************************
        ** Function name:UARTReceive
        **
        ** Descriptions:Receive a block of data to the UART 0 port based
        **on the data Length
        **
        ** parameters:buffer pointer, and data length
        ** Returned value:Note
        **
        *****************************************************************************/
        void UARTReceive(uint8_t *BufferPtr, uint32_t Length)
        {
        while (Length--)
        {
        *BufferPtr++ = UARTReceiveByte(); // 把數據放入緩沖
        }
        }

        // 主函數

        int main(void) {

        // TODO: insert code here
        uint8_t ch = 0;

        UARTInit(9600);
        LPC_UART->IER = IER_THRE | IER_RLS; // 設置中斷使能寄存器

        UARTSend((uint8_t *)Buffer, 10);

        while (1)
        {
        ch = UARTReceiveByte(); // 接收字符
        if (ch != 0x00)
        {
        UARTSendByte(ch); // 發送接收數據
        }
        }

        // Enter an infinite loop, just incrementing a counter
        volatile static int i = 0 ;
        while(1) {
        i++ ;
        }
        return 0 ;
        }

        實驗圖片如下:

        c510d9abb6b297dd281662e4c8c&t=1274344745¬humb=yes" rel="nofollow" target="_blank">IMG_3380.JPG(70.52 KB)

        2010-5-14 06:54

        IMG_3381.JPG(76.79 KB)

        2010-5-14 06:54

        IMG_3382.JPG(72.08 KB)

        2010-5-14 06:54

        串口我用的是USB轉串口進行調試的,如果先打開串口進行,再連接實驗板時會提示如下:

        此時如果點擊"OK",將提示如下錯誤:

        此時應該點擊如下圖紅圈的地方,LPC-Link,然后點擊“OK”即可正常連接。

        2010-5-14 07:10




        關鍵詞: LPC1114UART收發實

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 恭城| 崇文区| 金山区| 南宁市| 白城市| 织金县| 巴楚县| 天门市| 广水市| 邻水| 赫章县| 西乡县| 大名县| 原阳县| 六枝特区| 汉中市| 调兵山市| 临朐县| 建德市| 保亭| 临泽县| 防城港市| 滕州市| 阜新市| 澎湖县| 江陵县| 和静县| 丹阳市| 同仁县| 濉溪县| 合水县| 樟树市| 玛纳斯县| 新宁县| 九龙县| 长顺县| 石嘴山市| 赞皇县| 上虞市| 合川市| 大英县|