滚动码解码PIC单片机C程序

来源:本站
导读:目前正在解读《滚动码解码PIC单片机C程序》的相关信息,《滚动码解码PIC单片机C程序》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《滚动码解码PIC单片机C程序》的详细说明。
简介:在这里为大家提供一个滚动码解码PIC单片机的C程序。

//-------------------------------------------------------------------- //  Interrupt based receive routine////  Compiled using HiTech PIC C compiler v.7.93//********************************************************************#define CLOCK          4      // MHz#define TE            400      // us#define OVERSAMPLING    3      #define PERIOD          TE/OVERSAMPLING*4/CLOCK#define NBIT            65      // number of bit to receive -1(HCS300 66-1=65)unsigned char B[9];            // receive buffer static byte  RFstate;          // receiver statestatic sbyte RFcount;          // timer counterstatic byte  Bptr;              // receive buffer pointerstatic byte  BitCount;          // received bits counterword  XTMR;                    // 16 bit extended timervolatile bit RFFull;            // buffer fullvolatile bit RFBit;            // sampled RF signal#define TRFreset    0#define TRFSYNC    1#define TRFUNO      2#define TRFZERO    3#define HIGH_TO    -10        // longest high Te#define LOW_TO      10        // longest low  Te#define SHORT_HEAD  20        // shortest Thead accepted 2,7ms#define LONG_HEAD    45        // longest Thead accepted 6,2ms//-----------------------------------------------------------------------------------#pragma int_rtcc      // install as interrupt handler (comment for HiTech!)void interrupt rxi(void)  //this routine gets called every time TMR0 overflows{    RFBit = RFIn;              // sampling RF pin verify!!!    TMR0 -= PERIOD;            // reload    T0IF = 0;    XTMR++;                    // extended 16 long timer update//-----------------------------------------------------------------    if (RFFull)                // avoid overrun    {    return;}    switch( RFstate)            // state machine main switch    {        case TRFUNO:        if ( RFBit)        { // while high             RFcount--;            if ( RFcount < HIGH_TO)                RFstate = TRFreset;      // reset if too long        }        else        { // falling edge detected  ----+          //                            |          //                            +----                RFstate= TRFZERO;        }                break;            case TRFZERO:        if ( RFBit)        { // rising edge detected    +----          //                          |          //                      ----+            RFstate= TRFUNO;            B[Bptr] >>= 1;              // rotate             if ( RFcount >= 0)            {    B[Bptr]+=0x80; }      // shift in bit            RFcount = 0;                // reset length counter                        if ( ( ++BitCount & 7) == 0)            {    Bptr++;    }          // advance one byte            if (BitCount == NBIT)              {                RFstate = TRFreset;    // finished receiving                 RFFull = TRUE;            }            }        else        { // still low            RFcount++;            if ( RFcount >= LOW_TO)    // too long low            {                RFstate = TRFSYNC;      // fall back into RFSYNC state                 Bptr = 0;              // reset pointers, while keep counting on                 BitCount = 0;            }        }        break;    case TRFSYNC:        if ( RFBit)        { // rising edge detected  +---+                +---..          //                      |  |  <-Theader->  |            //                          +----------------+            if ( ( RFcount < SHORT_HEAD) || ( RFcount >= LONG_HEAD))            {                RFstate = TRFreset;                break;                  // too short/long, no header            }            else            {                RFcount =0;            // restart counter                RFstate= TRFUNO;  //合适的长低电平信号出现            }        }        else        { // still low            RFcount++;        }        break;    case TRFreset:      //初始状态    default:        RFstate = TRFSYNC;          // reset state machine in all other cases        RFcount = 0;        Bptr = 0;        BitCount = 0;        break;            } // switch//-----------------------------------------------------------------} // rxi void InitReceiver(){    T0IF = 0;    T0IE = 1;                  // TMR0 overflow interrupt    GIE = 1;                    // enable interrupts    RFstate = TRFreset;        // reset state machine in all other cases    RFFull = 0;                // start with buffer empty    XTMR = 0;                  // start extende}

提醒:《滚动码解码PIC单片机C程序》最后刷新时间 2024-03-14 01:00:17,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《滚动码解码PIC单片机C程序》该内容的真实性请自行鉴别。