英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流

 找回密码
 立即注册
搜索
电子烟方案单片机单片机开发深圳单片机开发
单片机方案国产单片机8位单片机电子烟方案开发
查看: 2605|回复: 0
打印 上一主题 下一主题

曼彻斯特编码的接收

[复制链接]
跳转到指定楼层
1#
发表于 2009-5-5 15:54:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
接收程序,给大家分享: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 下一条

小黑屋|公司首页|Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 ( 粤ICP备09008620号 )

GMT+8, 2024-4-28 05:22 , Processed in 0.051991 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表