×
嵌入式开发 > 详情

曼彻斯特编码的接收C51程序

发布时间:2020-07-02 发布时间:
|
曼码接收程序,常用在无线信号编码与解码中,给大家分享:
rxi(){// this routine gets called every time TMR0 overflowsif(T0IF)  //定时器中断程序
{TMR0 = PERIOD;             // 装计时器初值
T0IF = 0;     // 清定时器溢出标志
XTMR++;                     // 外部的系统时钟计时器加
1RFcount++;     // 脉冲宽度计数器加1return;}if(RAIF)  //端口电平变化中断程序
{if (RFFull)                 // 如果接收位满就退出
return;RFBit = RFIn;               // 取样信号接收的值
RAIF = 0;switch (RFstate)            // 当前状态
{case TRFDATAUP:switch (RFcount){ case 4:case 5:  case 6:case 7:
PORTA = PORTA;//启动端口电平中断break;case 8:case 9:case 10:case 11:case 12:B[Bptr] = 1;              // rotate if ( RFBit==0)  //如是有效的下跳变则该位的数据值为1,上跳变为0{ 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; //重新记时PORTA = PORTA;//启动端口电平中断break;default:  //超时或不足则退出接收RFstate = TRFSYNC;        // reset state machine in all other casesRFcount = 0;Bptr = 0;BitCount = 0;PORTA = PORTA;//启动端口电平中断}break;case TRFSYNC:if ( RFBit){ // rising edge detected  +---+                +---..//                       |   |  -Theader->   |   //                           +----------------+if ( ( RFcount  SHORT_HEAD) || ( RFcount >= LONG_HEAD)){RFstate = TRFreset;PORTA = PORTA;//启动端口电平中断break;                  // too short/long, no header}else{RFcount =0;             // restart counterRFstate= TRFDATAUP;PORTA = PORTA;//启动端口电平中断}}else{ // still lowRFcount=0;PORTA = PORTA;//启动端口电平中断}break;case TRFreset:default:RFstate = TRFSYNC;        // reset state machine in all other casesRFcount = 0;Bptr = 0;BitCount = 0;PORTA = PORTA;//启动端口电平中断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;             // 装计时器初值PORTA = PORTA;//启动端口电平中断}


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
CC-Link现场总线及应用实例