#include <16F628A.h> #FUSES WDT //Watch Dog Timer #FUSES INTRC_IO //Internal RC Osc, no CLKOUT #FUSES NOPUT //No Power Up Timer #FUSES PROTECT //Code protected from reading #FUSES BROWNOUT //Brownout reset #FUSES NOMCLR //Master Clear pin used for I/O #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O #FUSES CPD //EE protection #use delay(clock=4000000) //#use rs232(baud=9600,parity=N,xmit=PIN_A3,rcv=PIN_A2,bits=8) #define DTMFD3 PIN_B4 #define DTMFD2 PIN_B5 #define DTMFD1 PIN_B6 #define DTMFD0 PIN_B7 #define PTT PIN_A6 #define COR PIN_A7 //rx status #define CHPIN1 PIN_A2 #define CHPIN2 PIN_A1 #define CHPIN3 PIN_A4 #define LED PIN_B2 #define BL 12 //Password Lenght #define YELLOW 0 #define RED 1 //DTMF DATA: 0=10, *=11, #=12, A=13, B=14, C=15, D=0 //fill below arrays with your tone sequences //ie. const unsigned int8 pon[BL] ={1,2,3,4,5,6,7,8,9,10,11,12}; //power on // const unsigned int8 poff[BL] ={1,2,3,4,5,6,7,8,9,10,12,11}; //power off const unsigned int8 pon[BL] ={}; //power on const unsigned int8 poff[BL] ={}; //power off const unsigned int8 f1[BL] ={}; //channels const unsigned int8 f2[BL] ={}; const unsigned int8 f3[BL] ={}; const unsigned int8 f4[BL] ={}; const unsigned int8 f5[BL] ={}; const unsigned int8 f6[BL] ={}; const unsigned int8 f7[BL] ={}; const unsigned int8 f8[BL] ={}; const unsigned int8 mon[BL] ={}; //master on const unsigned int8 moff[BL] ={}; //master off unsigned int8 buffer[BL]={255}; int btype=1; void check_password(); int8 relay=1,ch=1,master=1; void ledset(int1 c) {if(c) {output_high(PIN_B2); output_low(PIN_B1); } else {output_high(PIN_B1); output_low(PIN_B2); } } void ledoff() {output_low(PIN_B2); output_low(PIN_B1); } void chset() {switch(ch) {case 1: output_float(CHPIN1);output_float(CHPIN2);output_float(CHPIN3); break; case 2: output_low(CHPIN1); output_float(CHPIN2);output_float(CHPIN3); break; case 3: output_float(CHPIN1);output_low(CHPIN2); output_float(CHPIN3); break; case 4: output_low(CHPIN1); output_low(CHPIN2); output_float(CHPIN3); break; case 5: output_float(CHPIN1);output_float(CHPIN2);output_low(CHPIN3); break; case 6: output_low(CHPIN1); output_float(CHPIN2);output_low(CHPIN3); break; case 7: output_float(CHPIN1);output_low(CHPIN2); output_low(CHPIN3); break; case 8: output_low(CHPIN1); output_low(CHPIN2); output_low(CHPIN3); break; } } void init() { ledset(1); delay_ms(250); //delay for radio turn-on ledset(0); delay_ms(250); ledset(1); delay_ms(250); ledset(0); delay_ms(250); ledset(1); delay_ms(250); ledset(0); delay_ms(250); ledset(1); delay_ms(250); ledset(0); delay_ms(250); restart_wdt(); ledset(1); delay_ms(250); ledset(0); delay_ms(250); ledset(1); delay_ms(250); ledset(0); delay_ms(230); ch=read_eeprom(4); //read initial state relay=read_eeprom(2); master=read_eeprom(3); restart_wdt(); chset(); //set radio channel } void push(int8 data) //received tone que {int i; for(i=0;i no true password 1->freq1 2->freq2 3->freq3 4->freq4 5->freq5 6->freq6 7->freq7 8->freq8 9->pon 10->poff 11->mon 12->moff */ unsigned int8 check_buffer() {int1 flag=1; int8 i=0; flag=1;i=0; while(i0&&i<9) if(master) {write_eeprom(4,i); ch=i; chset(); btype=2; } else btype=3; else if(i==9) if(master) //power on {write_eeprom(2,1); relay=1; btype=2; } else btype=3; else if(i==10) if(master) //power off {write_eeprom(2,0); relay=0; btype=2; } else btype=3; else if(i==11) {write_eeprom(3,1); //master on master=1; btype=2; } else if(i==12) {write_eeprom(3,0); //master off master=0; btype=2; } } //1:normal //2:accepted //3:denied void beep(int type) { delay_ms(250); if(type==1) {set_pwm1_duty(512); delay_ms(75); set_pwm1_duty(0); } else if(type==2) {set_pwm1_duty(512); delay_ms(50); set_pwm1_duty(0); delay_ms(50); set_pwm1_duty(512); delay_ms(50); set_pwm1_duty(0); delay_ms(50); set_pwm1_duty(512); delay_ms(50); set_pwm1_duty(0); } else {set_pwm1_duty(512); delay_ms(1000); set_pwm1_duty(0); } } void main() { int8 t=0; port_b_pullups(TRUE); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DIV_BY_4,207,1); setup_ccp1(CCP_PWM); set_pwm1_duty(0); setup_comparator(NC_NC_NC_NC); setup_vref(VREF_LOW|8); enable_interrupts(INT_EXT); enable_interrupts(GLOBAL); init(); //chtest while(true) //for debug purpose {for(t=1;t<9;t++) {ch=t; chset(); delay_ms(1000); restart_wdt(); } } while(TRUE) {restart_wdt(); if(relay&&master) ledset(YELLOW); else ledoff(); if(!input(COR)&&master&&relay) //below part is designed for low rx signal conditions. {output_low(PTT); t=0; while(!input(COR)) {restart_wdt(); delay_ms(2); t++; if(t>127)ledoff(); //blink led during tx else ledset(RED); } delay_ms(100); if(input(COR)) { beep(btype); //roger tone btype=1; output_float(PTT); } } } }