(原文件名:晶振实际为24M,J3接315M接收模块.JPG)
代码如下:
#include<AT89X52.h>
sbit PIN=P3^3;
sbit LockLED1=P0^0;
sbit LockLED2=P0^1;
sbit PortLED1=P0^2;
sbit PortLED2=P0^3;
#define SPort P2
const RMax=3000;
idata unsigned int RData[48];
unsigned char DP=0;
unsigned int T0Value=0;
const unsigned char CAdr[8]="F0FF0100";
bit PortLockBit;
void LockPort(void){
PortLockBit=1;
LockLED1=0;
LockLED2=0;
}
void UnlockPort(void){
PortLockBit=0;
LockLED1=1;
LockLED2=1;
}
void OpenPort(void){
if(PortLockBit==0){
PortLED1=0;
PortLED1=0;
SPort=0x00;
}
}
void ClosePort(void){
if(PortLockBit==0){
PortLED1=1;
PortLED1=1;
SPort=0xFF;
}
}
bit CheckAdr(void){
unsigned char i;
bit j=1;
for(i=0;i<8;i++){if(CAdr
!=RData)j=0;}
return j;
}
int MaxValue(void){
unsigned char i;
unsigned int a=0x0000;
for(i=0;i<48;i++){if(RData>a)a=RData;}
return a;
}
int MinValue(void){
unsigned char i;
unsigned int a=0xFFFF;
for(i=0;i<48;i++){if(RData<a)a=RData;}
return a;
}
void Decode(void){
unsigned int MaxVal,MinVal,AverAge;
unsigned char i;
bit IsVaild=1;
MaxVal=MaxValue();MinVal=MinValue();
if((MaxVal-MinVal)>=40){
AverAge=(MaxVal+MinVal)/2;
for(i=0;i<24;i++){if((RData>AverAge)!=(RData[i+24]>AverAge))IsVaild=0;}
if(IsVaild){
for(i=0;i<12;i++){
if(RData[i*2]>AverAge&&RData[i*2+1]>AverAge){RData='0';}
else if(RData[i*2]>AverAge&&RData[i*2+1]<AverAge){RData='F';}
else if(RData[i*2]<AverAge&&RData[i*2+1]>AverAge){RData='E';}//ERROR
else if(RData[i*2]<AverAge&&RData[i*2+1]<AverAge){RData='1';}
}
if(CheckAdr()){
if(RData[8]=='1')LockPort();
if(RData[9]=='1')ClosePort();
if(RData[10]=='1')OpenPort();
if(RData[11]=='1')UnlockPort();
}
}
}
}
//---------
void InitINT1(void){
EA=1;
EX1=1;
IT1=1;
}
void INT1Interrupt(void) interrupt 2{
T0Value=0;
TH0=0;TL0=0;
while(PIN==0);
if(T0Value==0){T0Value=TH0*0x100+TL0;}
EA=0;
if(T0Value>RMax&&DP!=24){DP=0;}
else if(T0Value<=RMax)RData[DP++]=T0Value;
if(DP==48){
Decode();
DP=0;
}
EA=1;
}
void InitTimer0(void)
{
TMOD |= 0x01;
TH0 = 0x00;
TL0 = 0x00;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void Timer0Interrupt(void) interrupt 1
{
T0Value=0xFFFF;
}
void main(){
UnlockPort();
ClosePort();
LockPort();
InitTimer0();
InitINT1();
while(1);
}
有人发过了,看了还是要顶一下。lz是软件仿真还是实战操作,和2272解码哪个更远?
-----------------------------------------------------------------------
另外问一下,能找到那个帖子吗,我想看看别人是怎么实现的
有很多解码2262的例程中内嵌汇编,看不懂,所以自己写了个纯c的
一周热门 更多>