• <nav id="uys44"></nav>
  • <menu id="uys44"><nav id="uys44"></nav></menu>
  • 專注電子技術學習與研究
    當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

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

    作者:佚名   來源:本站原創   點擊數:  更新時間:2012年01月18日   【字體:
    曼碼接收程序,常用在無線信號的編碼與解碼中,給大家分享:
    
    rxi()
    {
        // this routine gets called every time TMR0 overflows
        if(T0IF)  //定時器中斷程序
        {
            TMR0 = PERIOD;             // 裝計時器初值
            T0IF = 0;     // 清定時器溢出標志
            XTMR++;                     // 外部的系統時鐘計時器加1
            RFcount++;     // 脈沖寬度計數器加1
      return;
        }
        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 cases
                RFcount = 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 counter
                      RFstate= TRFDATAUP;
          PORTA = PORTA;//啟動端口電平中斷
                  }
              }
              else
              { // still low
                  RFcount=0;
         PORTA = PORTA;//啟動端口電平中斷
              }
              break;
    
         case TRFreset:
         default:
             RFstate = TRFSYNC;        // reset state machine in all other cases
             RFcount = 0;
             Bptr = 0;
             BitCount = 0;
          PORTA = PORTA;//啟動端口電平中斷
             break;
             
         } // switch
        } //電平中斷   
    } // rxi 
    
    
    void InitReceiver()
    {
    IOCA = 2;
        T0IF = 0;
        T0IE = 1;                   // TMR0 overflow interrupt
    RAIE = 1;     //使能端口電平變化中斷
        GIE = 1;                    // enable interrupts
        RFstate = TRFreset;         // reset state machine in all other cases
        RFFull = 0;                 // start with buffer empty
        XTMR = 0;                   // start extended timer
        TMR0 = PERIOD;             // 裝計時器初值
        PORTA = PORTA;//啟動端口電平中斷
    }
    關閉窗口

    相關文章

    小米的日记家庭宴会1-12有声,日本三级理论人妻中文字电影,国产学生情侣偷吃禁果在线,下面一进一出好爽视频
  • <nav id="uys44"></nav>
  • <menu id="uys44"><nav id="uys44"></nav></menu>