日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]//--------------------------------------------------------------------// Interrupt based receive routine//// Compiled using HiTech PIC C compiler v.7.93//**********************************************

//--------------------------------------------------------------------
// 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 state
static sbyte RFcount; // timer counter
static byte Bptr; // receive buffer pointer
static byte BitCount; // received bits counter
word XTMR; // 16 bit extended timer

volatile bit RFFull; // buffer full
volatile 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;//合適的長(zhǎng)低電平信號(hào)出現(xiàn)
}
}
else
{ // still low
RFcount++;
}
break;

case TRFreset://初始狀態(tài)
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

}


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉