433和315无线模块的软件编解码遥控程序Word文档下载推荐.docx
《433和315无线模块的软件编解码遥控程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《433和315无线模块的软件编解码遥控程序Word文档下载推荐.docx(20页珍藏版)》请在冰点文库上搜索。
![433和315无线模块的软件编解码遥控程序Word文档下载推荐.docx](https://file1.bingdoc.com/fileroot1/2023-4/28/6a9b9014-204c-4950-b377-b7c89cbb5d90/6a9b9014-204c-4950-b377-b7c89cbb5d901.gif)
{
intTIMER1_REG;
unsignedcharREG[2];
}
unionBIT_32
unsignedlongdata_temp_long;
unsignedchardata_temp_byte[4];
staticunionBIT_16TIMER1_TEMP;
//16位定时器1
staticunionBIT_32data_temp;
staticvolatileunsignedcharrec_status@97;
staticunsignedchardata_cout;
//接收的遥控器码位数
staticunsignedchardata;
//接收的4位数据
staticunsignedinth_pulse;
//高电平宽度
staticunsignedintl_pulse;
//低电平宽度
staticunsignedcharremote_cout;
//遥控器数量
staticunsignedcharremote_numb;
//遥控器编号
staticunsignedcharTIMER15S1;
//清除学习码按键长按时间
staticunsignedcharTIMER15S2;
//学习等待时间
staticunsignedcharTIMER15S3;
//遥控器数据缓冲时间
staticunsignedcharTIMER15S4;
//LED显示时间
staticunsignedcharTIMER15S5;
//
staticunsignedcharTIMER15S6;
staticunsignedcharTIMER15S7;
staticunsignedcharTIMER15S8;
staticbithead@((unsigned)(&
rec_status)*8+(0));
//同步头标志位
staticbitlearn@((unsigned)(&
rec_status)*8+
(1));
//学习标志位
staticbitrecieved@((unsigned)(&
rec_status)*8+
(2));
//接收完成标志位
staticbitremote_button_status@((unsigned)(&
rec_status)*8+(3));
//遥控器按键标志位
staticbitfirst_click_status@((unsigned)(&
rec_status)*8+(4));
//遥控器按键单击标志位
/**********************************数据接收**********************************/
unsignedchardata_read(void)
if(h_pulse>
l_pulse)
if((l_pulse>
200)&
&
(l_pulse<
1000))
if(h_pulse<
<
2))return1;
//数据为1
return2;
//无效的数据
elseif(h_pulse<
if((h_pulse>
(h_pulse<
if(l_pulse<
2))return0;
//数据为0
voidclr_head(void)//清除寄存器
data_cout=0;
head=0;
#pragmainterrupt_level1
voidcheck_data(void)//检测数据是否正确
if(head)
switch(data_read())
case0:
(data_temp.data_temp_long)<
=1;
;
data_cout++;
break;
case1:
(data_temp.data_temp_long)++;
default:
clr_head();
if(data_cout>
23)
INTE=0;
recieved=1;
clr_head();
voidcheck_head(void)
if((!
head)&
(!
recieved))//
if((h_pulse>
300)&
h_pulse*27)&
h_pulse*35)){
head=1;
}//end******************>
>
voidinterruptlevel_h_l(void)
/*if(RAIF)//如果是电平中断
{PORTA=PORTA;
RAIF=0;
TIMER1_TEMP.REG[0]=TMR1L;
TIMER1_TEMP.REG[1]=TMR1H;
TMR1H=0;
TMR1L=0;
if(RA4)//如果是低电平中断
{l_pulse=TIMER1_TEMP.TIMER1_REG;
check_data();
check_head();
else//如果是高电平中断
h_pulse=TIMER1_TEMP.TIMER1_REG;
}
}*/
if(INTF)
INTF=0;
if(INTEDG)//低电平宽度
INTEDG=0;
l_pulse=TIMER1_TEMP.TIMER1_REG;
else
INTEDG=1;
if(T0IF)//
T0IF=0;
TIMER15S1++;
TIMER15S2++;
TIMER15S3++;
TIMER15S4++;
TIMER15S5++;
TIMER15S6++;
TIMER15S7++;
TIMER15S8++;
}}
/*********************************遥控器学习**********************************/
voidclr_learn_reg(void)
unsignedcharn;
di();
for(n=1;
n==remote_cout*4;
n++)
eeprom_write(n,0);
eeprom_write(70,0);
eeprom_write(71,0);
ei();
unsignedcharcompare_data(unsignedchareep_addr)
unionBIT_32addr_data;
for(n=0;
n<
4;
addr_data.data_temp_byte[n]=eeprom_read(eep_addr+n);
}if((data_temp.data_temp_long&
0x00fffff0)==(addr_data.data_temp_long&
0x00fffff0)){
return1;
//地址匹配返回1
return0;
//地址不匹配返回0}
unsignedcharcompare_all_data(void)
for(n=0;
remote_cout;
n++)//在已经学习好的遥控器地址里比较有没有相同的
if(compare_data(n*4+1))//如果有相同的遥控器{
//没有一个地址是相同的}
//读遥控器的数量
voidread_remote_cout(void)
remote_cout=eeprom_read(71);
//读出已经学习的遥控器总数量
if(remote_cout>
20)remote_cout=0;
//如果EEPROM是空的则为0}
voidcheck_learn_pro(void)
if(learn)
learn=0;
remote_numb=eeprom_read(70);
//读出现在可以覆盖掉哪个遥控器的编号
read_remote_cout();
////读遥控器的数量
if(remote_numb>
(remote_geshu-1))remote_numb=0;
//如果遥控器的编号已经是最大的了则从小开始
if((remote_cout==0)||!
compare_all_data())//如果还没有遥控器学习或没有相同地址的遥控器学习
eeprom_write(remote_numb*4+n+1,data_temp.data_temp_byte[n]);
}remote_numb++;
if(remote_cout<
remote_geshu+1)remote_cout++;
//已经学习好的遥控器数量
eeprom_write(71,remote_cout);
//保存已经学习好的遥控器总数量eeprom_write
(70,remote_numb);
//保存已学习的遥控起编号
voidcheck_out_pro(void)
read_remote_cout();
if(compare_all_data())
{data=data_temp.data_temp_byte[0]&
0x0f;
TIMER15S3=0;
TIMER15S4=0;
RC4=1;
voiddecode_init(void)//接收初始化
OPTION=0x87;
RBPU=0;
TMR0=0;
T0IE=1;
//使能定时器0中断INTE=1;
TMR1ON=1;
PORTC=0x00;
TRISC=0x00;
//开放全局中断}
voidcheck_remote_recieved(void)//检测有无新的数据
if(!
RB1)//
if(TIMER15S1>
30)//是否长按了3秒
clr_learn_reg();
RC4=0;
{learn=1;
TIMER15S2=0;
{TIMER15S1=0;
if(TIMER15S2>
60)
if(TIMER15S3>
2)//数据保持时间
data=0;
if(TIMER15S4>
3)//LED显示时间
if(recieved)
recieved=0;
check_learn_pro();
check_out_pro();
INTE=1;
/*********************************控制部分程序*******************************/
voidcontrol_init(void)
;
/******************************************************************************//*********
************************声音部分程序*********************************/
unsignedchardelay(unsignedintnus)
for(;
nus>
0;
nus--)
if(recieved==1)return0;
asm("
nop"
);
unsignedcharsoud_one_fre(unsignedintcout,unsignedintdelay_time)//发音程序
if(recieved==1)return0;
for(;
cout>
cout--)
RC6=!
RC6;
delay(delay_time);
}RC6=0;
/*********************************急促的声音***********************************/
unsignedcharsoud_one_fre0(unsignedinttime,unsignedintdelay_time)
time>
time--)
soud_one_fre(1000,10);
/*********************************救护的声音***********************************/
unsignedcharsoud_tow_fre0(unsignedinttime)//
soud_one_fre(900,10);
soud_one_fre(800,30);
***************************低-高音***********************************/
unsignedcharsoud_many_fre0(unsignedinttime,unsignedintcout)
unsignedintdelay_time;
for(delay_time=50;
delay_time>
10;
delay_time--)
soud_one_fre(cout,delay_time);
/****************************************************