




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
433和315无线模块的软件编解码遥控程序1:单片机软件解码PT22402:选用PIC16F877A作为软件解码芯片3:单片机时钟频率选用外部4MHZ晶振4:选用外部中断脚作为编码信号脚输入脚5:可解PT2240芯片(8脚的学习型编码芯片 编码地址位:2的20次方 重复几率100万分之一)6:功能有:遥控器学习(DEMO上的S9作为学习按纽) 清除记忆(长按DEMO上的S9即可清除遥控器地址的记忆)7:学习遥控器数量可以设定(可根据EEPROM的大小 随便设定)8:输出功能(有三路是 单击遥控器双稳,可以通过PORTC上的LED可以看到结果还有一路是 双击遥控器双稳)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;/*/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;/清除学习码按键长按时间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)*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_read(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)/检测数据是否正确 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_level 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.REG0=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+; /*/* 遥控器学习*/*/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_read(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; remote_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(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(); check_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-) 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(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*/*/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;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 remote_button_status=1; return data;/遥控器数据有效 else remote_button_status=0; return 0; /*/void check_remote_c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- “五城联创”基本知识题库及答案
- 酒店2025年工作计划怎么写(5篇)
- 专利技术转让协议书
- 环境监测行业智能化设备数据采集与质量控制技术报告
- 2025年排泄护理灌肠题目及答案
- 用电安全题目及答案
- 《物联网安装调试员技能培训》课件-项目一 物联网基础组件与通信协议
- CN120095608B 一种刀库用刀具同步的清洁装置 (昆山北钜机械有限公司)
- CN120084478B 一种汽车车灯测试设备及其测试方法 (常州市永光车业有限公司)
- T淋巴细胞检测课件
- 化工厂产品品质管理制度
- 新生儿外科伤口护理
- 教堂12项管理制度
- 2025年高考英语全国一卷试题真题及答案详解(精校打印)
- 踝关节骨折护理
- 华为视觉识别规范手册中文版
- 三氧注射治疗技术规范与应用
- “临床营养科建设与管理指南”实施细则-I级标准化临床营养科建设示范基地
- 咖啡合作合同协议书
- 排水管网工程运营管理与维护方案
- 2025至2030中国煤炭贸易行业营销战略分析及未来发展机遇可行性报告
评论
0/150
提交评论