新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 曼徹斯特編碼的接收C51程序

曼徹斯特編碼的接收C51程序

作者: 時(shí)間:2012-08-06 來源:網(wǎng)絡(luò) 收藏
曼碼接收程序,常用在中,給大家分享:rxi(){// this routine gets called every time TMR0 overflowsif(T0IF)  //定時(shí)器中斷程序{TMR0 = PERIOD;             // 裝計(jì)時(shí)器初值T0IF = 0;     // 清定時(shí)器溢出標(biāo)志XTMR++;                     // 外部的系統(tǒng)時(shí)鐘計(jì)時(shí)器加1RFcount++;     // 脈沖寬度計(jì)數(shù)器加1return;}if(RAIF)  //端口電平變化中斷程序{if (RFFull)                 // 如果接收位滿就退出return;RFBit = RFIn;               // 取樣信號(hào)接收的值RAIF = 0;switch (RFstate)            // 當(dāng)前狀態(tài){case TRFDATAUP:switch (RFcount){ case 4:case 5:  case 6:case 7:PORTA = PORTA;//啟動(dòng)端口電平中斷break;case 8:case 9:case 10:case 11:case 12:B[Bptr] = 1;              // rotate if ( RFBit==0)  //如是有效的下跳變則該位的數(shù)據(jù)值為1,上跳變?yōu)?{ B[Bptr]+=1;          // shift in bit}if ( ( ++BitCount  7) == 0)Bptr++;                 // advance one byte if (BitCount == NBIT){RFstate = TRFreset;     // finished receiving RFFull = 1;} RFcount=0; //重新記時(shí)PORTA = PORTA;//啟動(dòng)端口電平中斷break;default:  //超時(shí)或不足則退出接收RFstate = TRFSYNC;        // reset state machine in all other casesRFcount = 0;Bptr = 0;BitCount = 0;PORTA = PORTA;//啟動(dòng)端口電平中斷}break;case TRFSYNC:if ( RFBit){ // rising edge detected  +---+                +---..//                       |   |  -Theader->   |   //                           +----------------+if ( ( RFcount  SHORT_HEAD) || ( RFcount >= LONG_HEAD)){RFstate = TRFreset;PORTA = PORTA;//啟動(dòng)端口電平中斷break;                  // too short/long, no header}else{RFcount =0;             // restart counterRFstate= TRFDATAUP;PORTA = PORTA;//啟動(dòng)端口電平中斷}}else{ // still lowRFcount=0;PORTA = PORTA;//啟動(dòng)端口電平中斷}break;case TRFreset:default:RFstate = TRFSYNC;        // reset state machine in all other casesRFcount = 0;Bptr = 0;BitCount = 0;PORTA = PORTA;//啟動(dòng)端口電平中斷break;} // switch} //電平中斷   } // rxi void InitReceiver(){IOCA = 2;T0IF = 0;T0IE = 1;                   // TMR0 overflow interruptRAIE = 1;     //使能端口電平變化中斷GIE = 1;                    // enable interruptsRFstate = TRFreset;         // reset state machine in all other casesRFFull = 0;                 // start with buffer emptyXTMR = 0;                   // start extended timerTMR0 = PERIOD;             // 裝計(jì)時(shí)器初值PORTA = PORTA;//啟動(dòng)端口電平中斷}


評(píng)論


相關(guān)推薦

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

關(guān)閉