The PIC single-chip machine decodes EV1527 instancesThe PIC single-chip machine decodes EV1527 instances
The PIC single-chip machine decodes EV1527 instances / / EV1527 decoding program: single-chip PIC16F630, internal 4MHz, EV1527 transmission frequency 433MHz, oscillation resistance 270K, remote control volt...
The PIC single-chip machine decodes EV1527 instances
The PIC single-chip machine decodes EV1527 instances / / EV1527 decoding program: single-chip PIC16F630, internal 4MHz, EV1527 transmission frequency 433MHz, oscillation resistance 270K, remote control voltage DC12V, period 1.2 ms.
/ / in the 3S clock, press the boot key, the program learns the remote control identification number, only one time to learn a remote control. Press the shutdown key program to erase all remote control identifiers.
/ / this program can learn up to 42 remote controls, and the 43rd will cover the first when the number of remote controls is 42.
# include < PIC. H >
__CONFIG x34 (0);
__EEPROM_DATA (0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
# define uchar unsigned char
# define uint unsigned int
# define rfin RC3
# define SLED RA5
# define LED RC1
/ / = = = = = = = = = = = = = = = =
Bit learnf;
Bit fun_out;
Bit fun_ok;
= = = = = = = = = = = = = = = = = = = = = = = = =
/ / remember the time variable
Uint temp0 = 0;
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = =
/ / RF receiver variable
Uchar rec_count;
Uchar lo_buf;
Uchar hi_buf;
Uchar cs2.
Uchar cs1;
Uchar cs0.
/ / RF reception mark
Bit rfstart1;
Bit rfstart;
Bit rfok;
Bit rf_er; / / receive failure
/ / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- delay -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / /
Delay (uchar ms)
{
Uint I, j;
For (I = 0; I < ms; I + +)
(j = 0; j < 30; j + +);
}
/ / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- LED flashing -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / /
LED_FLASH (void)
{
Uchar I;
For (I = 0; I < 6; I + +)
{
LED = 1;
Delay (30);
LED = 0;
}
}
/ / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- interrupt service --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- / /
Void interrupt all ()
{
Govemment = 0;
Temp0 + +;
If (TMR1IF = = 1)
{
TMR1IF = 0; / / clear the flag bit
TMR1H = 0 XFF;
TMR1L = 0 xaa;
/ / RF reception
If (rfin = = 1)
{
If (rfstart1 = = 1)/do you find the sync head? If the synchronization header is found, it is received from low to high
{/ / A
If (lo_buf > hi_buf) / / determine if the level is low
{
If (lo_buf > = 8 & & lo_buf < = 12 & & hi_buf < = 4)
{
Rec_count + +; / / it's low level
Cs0 < < = 1; / / move one to the left
}
Else rf_er = 1; / / receive failure
}
Else if (lo_buf < hi_buf) / / determine whether the level is
high
{If (lo_buf > = 3 &&lo_buf < = 4 &&hi_buf > = 8 && hi_buf < =
12) / / determine whether the high level is greater than 900us
and the low level is greater than 200us
{
Rec_count + +; / / it's high level
Cs0 < < = 1; / / move one
Cs0 + +;
}
The else rf_er = 1;
}
Else if (lo_buf = = hi_buf). The / / low level cycle is the same,
receiving the error
If (rf_er = = 1)
{
Rfstart = 0; / / receive failure
Rec_count = 0;
Rfok = 0;
}
The else
{
If (rec_count = = 8) {cs2 = cs0; }
Else if (rec_count = = 16) {cs1 = cs0; }
}
If (rec_count = = 24) rfok = 1; / / the reception was successful
Hi_buf = 0;
} / / if (rfstart1 = = 1)
Else if (lo_buf > = 30 & & lo_buf < = 120) / / determine synchronization headers
{
Rfstart = 1; / / detect the correct synchronization headers
Rec_count = 0; / / receive digits, clear 0
}
Hi_buf + +;
Lo_buf = 0;
Rfstart1 = 0;
Rf_er = 0; / / receive failed flags
}
The else
{/ / the input port is low power
Lo_buf + +;
If (rfstart = 1) rfstart1 = 1; / / start receiving flags
The else hi_buf = 0;
}
}
Govemment = 1;
} / / TMR1IF = = 1 function
/ / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- block erase EEPROM -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / /
C_EEPROM (void)
{
Uchar I, b = 0 XFF.
For (I = 0; I < = 127; I + +) {EEPROM_WRITE (I = I, b); }
EEPROM_WRITE (0, 2);
LED_FLASH ();
}
/ / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- save user code -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- / /
Void save_learn (void)
{
Uchar I, j;
TMR1IE = 0;
I = EEPROM_READ (0);
EEPROM_WRITE (I, cs2);
I++;
EEPROM_WRITE (I, cs1);
I++;
J = (cs0 & 0 xf0);
EEPROM_WRITE (I, j);
If (I = = 127) I = 1;I++;
EEPROM_WRITE (0, I);
Delay (2);
TMR1IE = 1;
}
/ / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the initialization -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / /
Void init (void) / / initialization function
{
CMCON = 0 x07; / / close the comparator
TRISA = 0 x18; / / RA4 MRLC
PORTA = 0 x00;
TRISC = 0 x08;
PORTC = 0 x00;
Govemment = 0; / / total interruption
TMR1IF = 0;
PEIE = 1;
TMR1IE = 1; / / open the scheduled interrupt 1
TMR1ON = 1; / / use timer 1
TMR1H = 0 XFF;
TMR1L = 0 xaa; / / define 100uS interrupt once
Govemment = 1;
}
/ / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the main function -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / /
The main ()
{
The init ();
While (temp0 < 20,000) / / learn or erase
{
If (rfok)
{
If (cs0 & 0x01) / / learn
{
Save_learn ();
LED_FLASH ();
Break;
}
Else if (cs0 & 0x02) / / erase
{
C_EEPROM ();
LED_FLASH ();
}
}
}
While (1)
{
If (rfok = = 1) / / receive completion, the received user code
is started to compare with the user code stored in the EEPROM
{
Uchar I = 2, j, k, l, m, sw;
For (m = 0; m < 42; m + +) / / looping 42 times
{
J = EEPROM_READ (I);
I++;
K = EEPROM_READ (I);
I++;
L = EEPROM_READ (I);
I++;
If (j = = cs2 & & k = = = cs1 & & = (cs0 & 0xf0)) Break; } /
/ the result is the same
The else sw = 0; / / the comparison is different
}
If (sw = = 1)
{
If (cs0 & 0 x04)
LED = 1;
If (cs0 & 0 x08)
LED = 0;
If (cs0 & 0 x01)
SLED = 1;
If (cs0 & 0 x02)
SLED = 0;
}
}
}
}/ / * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * end * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * / /
本文档为【The PIC single-chip machine decodes EV1527 instances】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。