(原文件名:0001.jpg)
(原文件名:0002.jpg)
(原文件名:0003.jpg)
(原文件名:0004.jpg)
#include "TYPEDEF.H"
#include "STC89C5X.H"
#include "INTRINS.H"
sfr P1M1 = 0x92;
#define ONSwitch() P1M1 |= 0x10; P1_4 = 1
#define OFFSwitch() P1M1 &= 0xEF; P1_4 = 0
INT8U RFLevel0;
INT8U RFLevel1;
INT8U RFStep;
INT8U RFBuf[25];
//
INT8U KeyAge;
INT8U KeyFlag;
INT8U SwitchState;
INT16U TimeOut;
//void Soft_Rst(void);
void SystemInit(void);
//INT8U Read_Flash_Byte(INT16U addr);
//void Write_Flash_Byte(INT8U byte, INT16U addr);
//void Erase_Flash_Sector(INT16U addr);
/*
* Main function
*/
int main(void)
{
SystemInit();
while(1) {
if(TF1) {
TF1 = 0;
RFLevel1 = RFLevel0;
RFLevel0 = P3 & 0x80;
if(RFStep == 0) {
if(RFLevel0 == 0) {
RFBuf[0]++;
} else {
if(RFBuf[0] >= 60) {
RFBuf[++RFStep] = 1;
} else {
RFBuf[0] = 0;
}
}
} else {
if(RFLevel0 != 0) {
if(++RFBuf[RFStep] == 0) {
RFStep = 0;
RFBuf[0] = 0;
}
} else if(RFLevel1 != 0) {
if(++RFStep > 24) {
RFLevel0 = RFBuf[0] / 15;
RFLevel1 = 0;
if(RFBuf[1] < RFLevel0) RFLevel1++;
if(RFBuf[2] > RFLevel0) RFLevel1++;
if(RFBuf[3] < RFLevel0) RFLevel1++;
if(RFBuf[4] > RFLevel0) RFLevel1++;
if(RFBuf[5] < RFLevel0) RFLevel1++;
if(RFBuf[6] > RFLevel0) RFLevel1++;
if(RFBuf[7] < RFLevel0) RFLevel1++;
if(RFBuf[8] > RFLevel0) RFLevel1++;
if(RFBuf[9] < RFLevel0) RFLevel1++;
if(RFBuf[10] > RFLevel0) RFLevel1++;
if(RFBuf[11] < RFLevel0) RFLevel1++;
if(RFBuf[12] > RFLevel0) RFLevel1++;
if(RFBuf[13] < RFLevel0) RFLevel1++;
if(RFBuf[14] > RFLevel0) RFLevel1++;
if(RFBuf[15] < RFLevel0) RFLevel1++;
if(RFBuf[16] > RFLevel0) RFLevel1++;
if(RFBuf[17] < RFLevel0) RFLevel1++;
if(RFBuf[18] < RFLevel0) RFLevel1++;
if(RFBuf[19] < RFLevel0) RFLevel1++;
if(RFBuf[20] < RFLevel0) RFLevel1++;
if(RFBuf[21] < RFLevel0) RFLevel1++;
if(RFBuf[22] < RFLevel0) RFLevel1++;
if(RFBuf[23] > RFLevel0) RFLevel1++;
if(RFBuf[24] > RFLevel0) RFLevel1++;
if(RFLevel1 >= 24) {
KeyAge++;
TimeOut = 0;
RFStep = 0;
RFBuf[0] = 0;
if((KeyFlag == 0) && (KeyAge >= 1)) {
KeyFlag = 1;
if(SwitchState == 0) {
SwitchState = 1;
ONSwitch();
} else {
SwitchState = 0;
OFFSwitch();
}
}
}
} else {
RFBuf[RFStep] = 0;
}
}
}
if(++TimeOut > 6000) {
TimeOut = 0;
KeyAge = 0;
KeyFlag = 0;
}
}
}
}
/*
* Initializtion System
*/
void SystemInit(void)
{
IE = 0x00;
TMOD = 0x21;
TH1 = 0xEC;
TR1 = 1;
}
-----------------------------------------------------------------------
我用中断,结果上电工作几分钟就死机了,后来只好放在main函数了,你说的多种遥控应该是指数据速率不一样的吧?要兼容,采集速率要做成动态的,根据同步头的长度动态调整采集速率。我用的是内部时钟,精度很差,1L的代码就是动态决定采集速率的
-----------------------------------------------------------------------
有个产品,串口中断很频繁(最快时大概1MS中断一次),用89C54,从未发现过问题,换成11F16,非常容易死机,原因至今没找到,晶体用的是32.768M的
一周热门 更多>