|
1:?jiǎn)纹瑱C(jī)軟件解碼PT2240 2:選用PIC16F877A作為軟件解碼芯片 3:?jiǎn)纹瑱C(jī)時(shí)鐘頻率選用外部4MHZ晶振 4:選用外部中斷腳作為編碼信號(hào)腳輸入腳 5:可解PT2240芯片(8腳的學(xué)習(xí)型編碼芯片 編碼地址位:2的20次方 重復(fù)幾率100萬(wàn)分之一) 6:功能有:遙控器學(xué)習(xí)(DEMO上的S9作為學(xué)習(xí)按紐) 清除記憶(長(zhǎng)按DEMO上的S9即可清除遙控器地址的記憶) 7:學(xué)習(xí)遙控器數(shù)量可以設(shè)定(可根據(jù)EEPROM的大小 隨便設(shè)定) 8:輸出功能(有三路是 單擊遙控器雙穩(wěn),可以通過(guò)PORTC上的LED可以看到結(jié)果.還有一路是 雙擊遙控器雙穩(wěn)) 9:可選用315MHZ/433MHZ的餓超再生/超外差接收模塊 /******************************************************************************/ /****************************** 遙控器接收程序 ********************************/ /******************************************************************************/ #i nclude <pic.h> #i nclude <pic1687x.h> #define remote_geshu 10 /******************************************************************************/ union BIT_16 { int TIMER1_REG; unsigned char REG[2]; } union BIT_32 { unsigned long data_temp_long; unsigned char data_temp_byte[4]; } /******************************************************************************/ static union BIT_16 TIMER1_TEMP;//16位定時(shí)器1 static union BIT_32 data_temp; /******************************************************************************/ static volatile unsigned char rec_status @ 97; static unsigned char data_cout;//接收的遙控器碼位數(shù) static unsigned char data;//接收的4位數(shù)據(jù) static unsigned int h_pulse;//高電平寬度 static unsigned int l_pulse;//低電平寬度 static unsigned char remote_cout;//遙控器數(shù)量 static unsigned char remote_numb;//遙控器編號(hào) /******************************************************************************/ static unsigned char TIMER15S1;//清除學(xué)習(xí)碼按鍵長(zhǎng)按時(shí)間 static unsigned char TIMER15S2;//學(xué)習(xí)等待時(shí)間 static unsigned char TIMER15S3;//遙控器數(shù)據(jù)緩沖時(shí)間 static unsigned char TIMER15S4;//LED顯示時(shí)間 static unsigned char TIMER15S5;// static unsigned char TIMER15S6;// static unsigned char TIMER15S7;// static unsigned char TIMER15S8;// /******************************************************************************/ static bit head @ ((unsigned)(&rec_status)*8+(0));//同步頭標(biāo)志位 static bit learn @((unsigned)(&rec_status)*8+(1));//學(xué)習(xí)標(biāo)志位 static bit recieved @((unsigned)(&rec_status)*8+(2));//接收完成標(biāo)志位 static bit remote_button_status @((unsigned)(&rec_status)*8+(3));//遙控器按鍵標(biāo)志位 static bit first_click_status @((unsigned)(&rec_status)*8+(4));//遙控器按鍵單擊標(biāo)志位
/******************************************************************************/ /********************************** 數(shù)據(jù)接收 **********************************/ /******************************************************************************/ unsigned char data_read(void) { if(h_pulse>l_pulse) { if((l_pulse>200)&&(l_pulse<1000)) { if(h_pulse<(l_pulse<<2))return 1;//數(shù)據(jù)為1 } return 2;//無(wú)效的數(shù)據(jù) } else if(h_pulse<l_pulse) { if((h_pulse>200)&&(h_pulse<1000)) { if(l_pulse<(h_pulse<<2))return 0;//數(shù)據(jù)為0 } return 2;//無(wú)效的數(shù)據(jù) } } /******************************************************************************/ void clr_head(void)//清除寄存器 { data_cout=0; head=0; } /******************************************************************************/ #pragma interrupt_level 1 void check_data(void)//檢測(cè)數(shù)據(jù)是否正確 { if(head) { switch(data_read()) { case 0:(data_temp.data_temp_long)<<=1;;data_cout++;break; case 1:(data_temp.data_temp_long)<<=1;(data_temp.data_temp_long)++;;data_cout++;break; default:clr_head();break; } if(data_cout>23) { INTE=0; recieved=1; clr_head();// } } } /******************************************************************************/ #pragma interrupt_level 1 void check_head(void) { if((!head)&&(!recieved))// { if((h_pulse>300)&&(h_pulse<1000)) { if((l_pulse>h_pulse*27)&&(l_pulse<h_pulse*35)) { head=1; } } } } |