在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 通信波特率115.2K的串行通信C語言示例

            通信波特率115.2K的串行通信C語言示例

            作者: 時間:2012-02-19 來源:網(wǎng)絡(luò) 收藏

            //115.2k程序,校驗方式為簡單雙向校驗,
            //而且是必要的,因為任何采用中斷、crc等的方法
            //均很難保證速度和避免錯誤.
            //總體速度5KB/秒

            本文引用地址:http://www.biyoush.com/article/172057.htm

            //單片機程序
            //使用22.1184晶振
            unsigned char time,b_break,b_break_3;
            //35.555ms
            void int_t0(void) interrupt 1 {
            TH0=0;
            if ((++b_break_3)>2) b_break=1;
            time++;
            }

            //

            unsigned char rec(void) {
            TH0=0;b_break_3=0;b_break=0;
            while (RI==0) {
            if (b_break) return(1); //等待pc發(fā)送100ms超時
            }
            RI=0;
            SBUF=SBUF;
            return(SBUF);
            }
            /*返回1表示失敗*/
            bit sen(unsigned char d) {
            SBUF=d;
            TH0=0;b_break_3=0;b_break=0;
            while (RI==0) {
            if (b_break) return(1); //等待pc送回相同字節(jié)數(shù)據(jù),100ms超時
            }
            RI=0;
            if (SBUF!=d) return(1);
            return(0);
            }

            void main(void) {
            unsigned int i;
            unsigned char d;
            EA=1;
            SCON=0xd8;PCON=0x80;
            TMOD=0x21;
            TL1=TH1=0xff;TR1=1;
            TH0=0;ET0=TR0=1;
            while (1) {
            d=rec();
            if ((!b_break)(d==0x55)) {
            d=rec();
            if (!b_break) {
            if (d==0xaa) {
            //接收到pc送來的要求發(fā)送指令0xaa55
            for (i=0;i1000;i++) {
            if (sen(i)) {
            //發(fā)送錯誤
            break;
            }
            }
            } else if (dd==0xaa) {
            //接收到pc送來的要求接收指令0xaaaa
            for (i=0;i1000;i++) {
            d=rec();
            if (!b_break) {
            //正確接收處理
            } else {
            //接收錯誤處理
            break;
            }
            }
            }
            }
            }
            }
            }

            //電腦程序tc2.0
            #i nclude stdio.h
            #i nclude dos.h
            #i nclude process.h
            #i nclude string.h
            #i nclude conio.h
            #i nclude dir.h>


            上一頁 1 2 下一頁

            關(guān)鍵詞: 通信 示例 語言 115.2K 波特 串行

            評論


            相關(guān)推薦

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

            關(guān)閉