因为片子比较垃圾没下降沿中断;中断函数也放不下东西
程序如下:
tu08 b[4];
tu08 RFstate; // receiver state
tu08 RFcount; // timer counter
tu08 BitCount;
tu08 Bptr;
#define address b[0]
#define address_1 b[1]
#define command b[2]
#define command_1 b[3]
#define TRFreset 0
#define TRFSYNC 2
#define TRFSYNCO 1
#define TRFUNO 3
#define TRFZERO 4
#define LOW_TO 17 // longest low Te
#define SHORT_HEAD 70 //
#define LONG_HEAD 157 //
volatile bit RFFull; // buffer full
volatile bit RFBit; // sampled RF signal
volatile bit fall_down;
#define NBIT 32
__interrupt power_check(void)
{
if(FTC0IEN&&FTC0IRQ){
FTC0IRQ=0;
if (RFFull)return; // avoid overrun
if(RFBit != RFIn){ RFBit= RFIn;if(RFBit==0)fall_down=1;}
if(RFcount>200)RFcount=200;
else RFcount++;
}
}
void rtx(void)
{
fall_down=0;
if(RFstate==TRFUNO){ if ( RFcount >= LOW_TO) { RFstate = TRFSYNC; RFcount = 0;}
else{ b[Bptr] >>= 1;
if ( RFcount >= 10)b[Bptr]|=0x80;
RFcount = 0;
if ( ( ++BitCount & 7) == 0) Bptr++;
if (BitCount == NBIT){RFstate = TRFreset; RFFull = 1; }
}
}
else if(RFstate==TRFSYNC){
if ( ( RFcount < SHORT_HEAD) || ( RFcount >= LONG_HEAD)){ RFstate=TRFreset;RFcount = 0;}
else { RFcount =0; RFstate= TRFUNO;}
}
else {RFstate = TRFSYNC; RFcount = 0; Bptr = 0; BitCount = 0; }
}
定时器为1/3采样频率0.56MS
我的问题是红外接收一开始没问题接收正常
怎么反复按键反复搞后一会就像死机了不好使了
手动给复位才能用但实际没死机别的功能还能用
我找了一天了
没找到毛病在哪
波形在这http://hi.baidu.com/c51_mcu/blog/item/776fef2b7a2a26315343c1a5.html
谢谢了 |