4754 views|1 replies

3

Posts

0

Resources
The OP
 

Newbie help, how to use 51 MCU to do EV1527 433Mhz decoding?? [Copy link]

#define RF P00
unsigned char RF_code[3]; //Remote control code value
bit RF_SyncFlag; //Synchronization signal flag, 1 means the synchronization signal has been received

//unsigned char RF;
unsigned char decode_ok; //Decoding successfulunsigned
char hh_w;ll_w; //High and low level widthunsigned
char ma_x; //Received bit
codeunsigned char bma1,bma2,bma3,bma4; //Received codeunsigned
char mma1,mma2,mma3,mma4; //Used to store remote control code during receiving process, code comparison is twice, this is the first timeunsigned
char mmb1,mmb2,mmb3,mmb4; //Used to store remote control code during receiving process, this is the second time


unsigned char rf_ok1,rf_ok2,rf_ok; //temporary reception success coding flag during the decoding process, set to 1 after receiving a complete remote control command to notify the decoding program that decoding is possible
unsigned char last_state; //save the last queried level status

unsigned char RF_JudgeValidPulseTimer;
unsigned int LastTimVal;

//void ExInt2_init(void)
//{
// EP0CON = EPIE(1) | EPPL(1) | P00_INDEX;
// GPIO_Init(P00F,INPUT);
// INT2EN = 1; //INT2 interrupt enable
// PS0 = 1;
//}

void Timer1_init(void)
{
TMOD=(TMOD&0xCF)|0x10; //Initialize TIMER1, use TIMER1 to count remote control pulse width
TR1 = 1;
TH1=0xFF;
TL1=0x88;
ET1=1;
}

void Timer1_ISR (void) interrupt 3
{
// EPIF = BIT0;

if(!RF)
{
ll_w++; //Low level detected, low level time plus 1
last_state=0; //Record this level state

}
else //High level detected
{
hh_w++;
if(!last_state) //A transition from low to high is detected
{
if(((hh_w>=2)&&(hh_w<=5))&&((ll_w>=100)&&(ll_w<=130))) //Judge the synchronization code 2/5 100/130
{
RF_SyncFlag=1; //Synchronization code reception success flag, set to 1
ma_x=0;
bma1=0;bma2=0;bma3=0;bma4=0;
}
else if((RF_SyncFlag)&&((ll_w>=8)&&(ll_w<=14))) //8/14
{
ma_x++;
if(ma_x==24)
{
if(!rf_ok1) // First temporary coding
{
mma1=bma1;
mma2=bma2;
mma3=bma3;
mma4=bma4;

rf_ok1=1; //First temporary coding received successfully, set to 1
RF_SyncFlag=0; //Synchronization code reception flag, set to 0
}
else
{
mmb1=bma1;
mmb2=bma2;
mmb3=bma3;
mmb4=bma4;

rf_ok2=1; //Second temporary coding received successfully, set to 1
RF_SyncFlag=0; //Synchronization code reception flag, set to 0
}
}
}
else if((RF_SyncFlag)&&((ll_w>=2)&&(ll_w<=7)))
{
switch(ma_x)
{
case 0 : { bma1=bma1 | 0x80;
break; } //Remote control code first bit
case 1 : { bma1=bma1 | 0x40;
break; }
case 2 : { bma1=bma1 | 0x20;
break; }
case 3 : { bma1=bma1 | 0x10;
break; }
case 4 : { bma1=bma1 | 0x08;
break; }
case 5 : { bma1=bma1 | 0x04;
break; }
case 6 : { bma1=bma1 | 0x02;
break; }
case 7 : { bma1=bma1 | 0x01;
break; }
case 8 : { bma2=bma2 | 0x80;
break; }
case 9 : { bma2=bma2 | 0x40;
break; }
case 10: { bma2=bma2 | 0x20;
break; }
case 11: { bma2=bma2 | 0x10;
break; }
case 12: { bma2=bma2 | 0x08;
break; }
case 13: { bma2=bma2 | 0x04;
break; }
case 14: { bma2=bma2 | 0x02;
break; }
case 15: { bma2=bma2 | 0x01;
break; }
case 16: { bma3=bma3 | 0x80;
break; }
case 17: { bma3=bma3 | 0x40;
break; }
case 18: { bma3=bma3 | 0x20;
break; }
case 19: { bma3=bma3 | 0x10;
break; }
case 20: { bma3=bma3 | 0x08;
break; }// 按键状态第1位
case 21: { bma3=bma3 | 0x04;
break; }
case 22: { bma3=bma3 | 0x02;
break; }
case 23: { bma3=bma3 | 0x01;

if(!rf_ok1)
{
mma1=bma1;
mma2=bma2;
mma3=bma3;
// mma4=bma4; // 将接收到的编码复制到解码寄存器中
rf_ok1=1; // 通知解码子程序可以解码了
RF_SyncFlag=0;
break;
}
else
{
mmb1=bma1;
mmb2=bma2;
mmb3=bma3;
// mmb4=bma4; // Copy the received code to the decoding register
rf_ok2=1; // Notify the decoding subroutine that it can decode
RF_SyncFlag=0;
break;
}
}
}
ma_x++;
}
else
{
ma_x=0;RF_SyncFlag=0;bma1=0;bma2=0;bma3=0;hh_w=0;ll_w=0;
}
ll_w=0;ll_w=1;

last_state=1; //Record this level status
}
if((mma1=mmb1)&&(mma2=mmb2)&&(mma3=mmb3))
{
rf_ok=1;
rf_ok1=0;
rf_ok2=0;
}
else
{
rf_ok=0;
rf_ok1=0;
rf_ok2=0;
}
}

if(rf_ok) //Determine whether the reception is successful
{
rf_ok=0;
RF_code[0]=mma1;
RF_code[1]=mma2;
RF_code[2]=mma3;
decode_ok=1;
}
}
void RF_MainLoop(void)
{
// ExInt2_init();
Timer1_init();

if(decode_ok==1)
{
switch(RF_code[2])
{
case 0 xc8: slow_flash1();
case 0xc4: slow_flash2();
case 0xc2: quick_flash1();
case 0xc1: quick_flash2();
}

}



}

This post is from RF/Wirelessly
 

3

Posts

0

Resources
2
 

This is the decoding program I wrote according to the routine on the Internet. I don't know where the problem is.

This post is from RF/Wirelessly
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
快速回复 返回顶部 Return list