在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 51 串口收發(fā)程序源代碼 環(huán)形緩沖區(qū)實(shí)現(xiàn)

            51 串口收發(fā)程序源代碼 環(huán)形緩沖區(qū)實(shí)現(xiàn)

            作者: 時(shí)間:2016-12-02 來(lái)源:網(wǎng)絡(luò) 收藏
            部分代碼:
            /***** 51 串口收發(fā) 環(huán)形緩沖區(qū)實(shí)現(xiàn) *****
            * 版本.........: 1.0
            * 目標(biāo).........: STC12C5A32AD
            * 文件名.......: uart.c
            * 編譯器.......: Keil C51 V9.02
            **************************************/
            #include "uart.h"
            #include "uart_config.h"
            #include "main_config.h"
            #include "STC_NEW_8051.H"

            volatileunsignedcharUART_TxBuf[UART_TXBUF_SIZE];
            volatileunsignedcharUART_TxBuf_Index=0;
            volatileunsignedcharUART_TxBuf_Length=0;

            volatileunsignedcharUART_RxBuf[UART_RXBUF_SIZE];
            volatileunsignedcharUART_RxBuf_Index=0;
            volatileunsignedcharUART_RxBuf_Length=0;

            volatilebitUART_RxBuf_IsFull=0;

            voidUART_Init(void)
            {
            PCON&=0x7f;//波特率不倍速
            SCON=0x50;//8位數(shù)據(jù),可變波特率
            AUXR|=0x40;//定時(shí)器1時(shí)鐘為Fosc,即1T
            AUXR&=0xfe;//串口1選擇定時(shí)器1為波特率發(fā)生器
            TMOD&=0x0f;//清除定時(shí)器1模式位
            TMOD|=0x20;//設(shè)定定時(shí)器1為8位自動(dòng)重裝方式
            TL1=256-(unsignedchar)(F_CPU/UART_BAUD/32+0.5);//設(shè)定定時(shí)初值
            TH1=256-(unsignedchar)(F_CPU/UART_BAUD/32+0.5);//設(shè)定定時(shí)器重裝值
            ET1=0;//禁止定時(shí)器1中斷
            TR1=1;//啟動(dòng)定時(shí)器1

            ES=1;
            TI=0;

            EA=1;// 使能總中斷
            }

            volatileunsignedcharUART_Sending=0;

            voidUART_TxByte(unsignedcharbyte)
            {
            EA=0;
            if(UART_Sending)
            {
            EA=1;
            while(UART_TxBuf_Length>=UART_TXBUF_SIZE);// 等待數(shù)據(jù)發(fā)送,不丟失
            EA=0;
            if(UART_TxBuf_Length{
            UART_TxBuf[UART_TxBuf_Index]=byte;
            UART_TxBuf_Length++;
            UART_TxBuf_Index++;
            if(UART_TxBuf_Index>=UART_TXBUF_SIZE)
            UART_TxBuf_Index=0;
            }
            }
            else
            {
            SBUF=byte;
            UART_Sending=1;
            }
            EA=1;
            }

            unsignedchartemp=0;
            voidUART_ISR(void)interrupt4
            {
            EA=0;
            if(TI)
            {
            TI=0;
            if(UART_TxBuf_Length==0)
            {
            UART_Sending=0;
            }
            else
            {
            if(UART_TxBuf_Index>=UART_TxBuf_Length)
            SBUF=UART_TxBuf[UART_TxBuf_Index-UART_TxBuf_Length];
            else
            SBUF=UART_TxBuf[UART_TXBUF_SIZE+UART_TxBuf_Index-UART_TxBuf_Length];
            UART_TxBuf_Length--;
            }
            }
            if(RI)
            {
            RI=0;
            temp=SBUF;
            if(UART_RxBuf_Length{
            UART_RxBuf[UART_RxBuf_Index]=temp;
            UART_RxBuf_Length++;
            UART_RxBuf_Index++;
            if(UART_RxBuf_Index>=UART_RXBUF_SIZE)
            UART_RxBuf_Index=0;
            }
            else
            {
            UART_RxBuf_IsFull=1;
            }
            }
            EA=1;
            }


            評(píng)論


            技術(shù)專區(qū)

            關(guān)閉