收藏 分销(赏)

433和315无线模块的软件编解码遥控程序教学文案.doc

上传人:丰**** 文档编号:3820028 上传时间:2024-07-21 格式:DOC 页数:14 大小:51.50KB
下载 相关 举报
433和315无线模块的软件编解码遥控程序教学文案.doc_第1页
第1页 / 共14页
433和315无线模块的软件编解码遥控程序教学文案.doc_第2页
第2页 / 共14页
433和315无线模块的软件编解码遥控程序教学文案.doc_第3页
第3页 / 共14页
433和315无线模块的软件编解码遥控程序教学文案.doc_第4页
第4页 / 共14页
433和315无线模块的软件编解码遥控程序教学文案.doc_第5页
第5页 / 共14页
点击查看更多>>
资源描述

1、433和315无线模块的软件编解码遥控程序精品资料 433和315无线模块的软件编解码遥控程序1:单片机软件解码PT22402:选用PIC16F877A作为软件解码芯片3:单片机时钟频率选用外部4MHZ晶振4:选用外部中断脚作为编码信号脚输入脚5:可解PT2240芯片(8脚的学习型编码芯片 编码地址位:2的20次方 重复几率100万分之一)6:功能有:遥控器学习(DEMO上的S9作为学习按纽) 清除记忆(长按DEMO上的S9即可清除遥控器地址的记忆)7:学习遥控器数量可以设定(可根据EEPROM的大小 随便设定)8:输出功能(有三路是 单击遥控器双稳,可以通过PORTC上的LED可以看到结果还

2、有一路是 双击遥控器双稳)9:可选用315MHZ433MHZ的超再生超外差接收模块/*/* 遥控器接收程序 */*/#include #include #define remote_geshu 10/*/union BIT_16 int TIMER1_REG; unsigned char REG2; union BIT_32 unsigned long data_temp_long; unsigned char data_temp_byte4; /*/static union BIT_16 TIMER1_TEMP;/16位定时器1static union BIT_32 data_temp;/*

3、/static volatile unsigned char rec_status 97;static unsigned char data_cout;/接收的遥控器码位数static unsigned char data;/接收的4位数据static unsigned int h_pulse;/高电平宽度static unsigned int l_pulse;/低电平宽度static unsigned char remote_cout;/遥控器数量static unsigned char remote_numb;/遥控器编号/*/static unsigned char TIMER15S1;

4、/清除学习码按键长按时间static unsigned char TIMER15S2;/学习等待时间static unsigned char TIMER15S3;/遥控器数据缓冲时间static unsigned char TIMER15S4;/LED显示时间static unsigned char TIMER15S5;/static unsigned char TIMER15S6;/static unsigned char TIMER15S7;/static unsigned char TIMER15S8;/*/static bit head (unsigned)(&rec_status)*

5、8+(0);/同步头标志位static bit learn (unsigned)(&rec_status)*8+(1);/学习标志位static bit recieved (unsigned)(&rec_status)*8+(2);/接收完成标志位static bit remote_button_status (unsigned)(&rec_status)*8+(3);/遥控器按键标志位static bit first_click_status (unsigned)(&rec_status)*8+(4);/遥控器按键单击标志位/*/* 数据接收 */*/unsigned char data_r

6、ead(void) if(h_pulsel_pulse) if(l_pulse200)&(l_pulse1000) if(h_pulse(l_pulse2) return 1;/数据为1 return 2;/无效的数据 else if(h_pulse200)&(h_pulse1000) if(l_pulse(h_pulse2) return 0;/数据为0 return 2;/无效的数据 /*/void clr_head(void)/清除寄存器 data_cout=0; head=0; /*/#pragma interrupt_level 1void check_data(void)/检测数据

7、是否正确 if(head) switch (data_read() case 0:(data_temp.data_temp_long)=1;data_cout+;break; case 1:(data_temp.data_temp_long)23) INTE=0; recieved=1; clr_head();/ /*/#pragma interrupt_level 1void check_head(void) if(!head)&(!recieved)/ if (h_pulse300)&(h_pulseh_pulse*27)&(l_pulse/*/#pragma interrupt_leve

8、l 1void interrupt level_h_l(void) /* if(RAIF)/如果是电平中断 PORTA=PORTA; RAIF=0;/ TIMER1_TEMP.REG0=TMR1L; TIMER1_TEMP.REG1=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; TIMER1_TEMP.REG

9、0=TMR1L; TIMER1_TEMP.REG1=TMR1H; TMR1H=0; TMR1L=0; if(INTEDG)/低电平宽度 INTEDG=0; l_pulse=TIMER1_TEMP.TIMER1_REG; check_data(); check_head(); else INTEDG=1; h_pulse=TIMER1_TEMP.TIMER1_REG; if(T0IF)/ T0IF=0; TIMER15S1+; TIMER15S2+; TIMER15S3+; TIMER15S4+; TIMER15S5+; TIMER15S6+; TIMER15S7+; TIMER15S8+; /

10、*/* 遥控器学习*/*/void clr_learn_reg(void) unsigned char n; di(); for (n=1;n=remote_cout*4;n+) eeprom_write(n,0); eeprom_write(70,0); eeprom_write(71,0); ei(); /*/unsigned char compare_data(unsigned char eep_addr) unsigned char n; union BIT_32 addr_data; for(n=0;n4;n+) addr_data.data_temp_byten=eeprom_re

11、ad(eep_addr+n); if(data_temp.data_temp_long&0x00fffff0)=(addr_data.data_temp_long&0x00fffff0) return 1;/地址匹配返回1 return 0;/地址不匹配返回0 /*/unsigned char compare_all_data(void) unsigned char n; for (n=0;n20)remote_cout=0; /如果EEPROM是空的则为0 /*/void check_learn_pro(void) unsigned char n; if(learn) learn=0; re

12、mote_numb=eeprom_read(70);/读出现在可以覆盖掉哪个遥控器的编号 read_remote_cout();/读遥控器的数量 if(remote_numb(remote_geshu-1)remote_numb=0;/如果遥控器的编号已经是最大的了 则从小开始 if(remote_cout=0)|!compare_all_data()/如果还没有遥控器学习或没有相同地址的遥控器学习 di(); for(n=0;n4;n+) eeprom_write (remote_numb*4+n+1,data_temp.data_temp_byten); remote_numb+; if(

13、remote_cout30)/是否长按了3秒 learn=0;/ clr_learn_reg(); RC4=0; else learn=1;/ TIMER15S2=0; TIMER15S4=0; RC4=1; else TIMER15S1=0; if(TIMER15S260) learn=0;/ if(TIMER15S32)/数据保持时间 data=0; TIMER15S3=0; if(TIMER15S43)/LED显示时间 RC4=0; if(recieved) TIMER15S3=0; recieved=0; TIMER15S4=0; RC4=1; check_learn_pro(); c

14、heck_out_pro(); INTE=1; /*/* 控制部分程序 */*/void control_init(void) ; /*/*声音部分程序*/*/*/unsigned char delay(unsigned int nus) for(;nus0;nus-) if (recieved=1) return 0; asm(nop); /*/unsigned char soud_one_fre(unsigned int cout,unsigned int delay_time)/发音程序 if(recieved=1) return 0; INTE=0; for (;cout0;cout-

15、) RC6=!RC6; delay(delay_time); RC6=0; INTE=1; /*/*急促的声音*/*/unsigned char soud_one_fre0(unsigned int time,unsigned int delay_time) for (;time0;time-) if(recieved=1) return 0; soud_one_fre (1000,10); delay(delay_time); /*/*救护的声音*/*/unsigned char soud_tow_fre0(unsigned int time)/ for (;time0;time-) if(

16、recieved=1) return 0; soud_one_fre(900,10); soud_one_fre(800,30); /*/*低-高音*/*/unsigned char soud_many_fre0(unsigned int time,unsigned int cout) for (;time0;time-) unsigned int delay_time; for(delay_time=50;delay_time10;delay_time-) if(recieved=1) return 0; soud_one_fre(cout,delay_time); /*/*低-高音1*/*

17、/unsigned char soud_many_fre2(unsigned int time,unsigned int cout) for (;time0;time-) unsigned int delay_time; for(delay_time=30;delay_time20;delay_time-) if(recieved=1) return 0; soud_one_fre(cout,delay_time); /*/*高低音*/*/unsigned char soud_many_fre1(unsigned int time,unsigned int cout) for (;time0;

18、time-) unsigned int delay_time; for (delay_time=10;delay_time0;time-) unsigned int delay_time; for(delay_time=20;delay_time0;cout-) if(recieved=1) return 0; soud_many_fre0(1,10); soud_many_fre2(1,10); /*/unsigned char remote_check(void)/遥控器按键检测 if(data)/ if(remote_button_status) return 0; else remot

19、e_button_status=1; return data;/遥控器数据有效 else remote_button_status=0; return 0; /*/void check_remote_command(void) if(TIMER15S510) first_click_status=0;/ switch (remote_check() case 0x01: RC0=!RC0; / soud_one_fre0(1,6000); soud_tow_fre0(5); delay(10000); soud_many_fre0(5,40); delay(10000); soud_many_

20、fre2(10,100); delay(10000); soud_many_fre1(5,40); delay(10000); soud_many_fre3(10,150); delay(10000); soud_low_high_low(5); delay(10000); soud_one_fre0(2,10000); break; case 0x02:RC1=!RC1;break; case 0x04:RC2=!RC2;break; case 0x08: if(first_click_status=1) RC3=!RC3; first_click_status=0;/ break; else first_click_status=1; TIMER15S5=0; break; default:break; /*/void control_pro(void) check_remote_command(); 仅供学习与交流,如有侵权请联系网站删除 谢谢14

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服