// R/C switch //This file was generated by the C2G Code Generator 1.1 asm __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC //If necessary insert your global variables declaration here char Continue; //This is used to break out of the loops if no pulse is active char Armed; //This indicates the unit is armed char Armed_Count; //These three counters are used to get several pulses before activating a channel char Drogue_Count; char Main_Count; char tmr_00_cntr; //Variable for counter #define tmr_rate 1 //Counter rate #pragma CLOCK_FREQ 4000000 //Buzz the buzzer void Buzz(char times) { asm:label_buzzloop set_bit( PORTA, 3 ); //Turn on buzzer delay_ms(500); clear_bit( PORTA, 3 ); //Turn off buzzer delay_ms(500); asm decfsz param00_Buzz, 1 asm goto label_buzzloop asm nop } void Delay(void) { delay_ms(1); delay_us(250); delay_us(250); delay_us(200); } //This is the interupt handler void interrupt( void ) { //Interrupt processing //TMR0 Overflow processing if( INTCON & 4 ) { clear_bit( INTCON, 2 ); tmr_00_cntr--; if( tmr_00_cntr == 0 ) { tmr_00_cntr = tmr_rate; Continue = 0; } } } //This is the main function which is called //after processor power-up or reset void main( void ) { //Initialize timer counters tmr_00_cntr = tmr_rate; //Initialize variables here //Hardware Initialization clear_bit( STATUS, RP0 ); //Select the Register bank 0 PORTA = 0; PORTB = 0; set_bit( STATUS, RP0 ); //Select the Register bank 1 set_tris_a( 23 ); //Configure the Port A set_tris_b( 248 ); //Configure the Port B OPTION_REG = 197; //Configure the OPTION register clear_bit( STATUS, RP0 ); //Select the Register bank 0 INTCON = 0; //Configure the INTCON register //Don't forget to insert your code here!!! //(As there is no "return" from the main code //an endless loop may be a good idea) delay_s(2); //Test continuity if(PORTB & 8) {Buzz(1);} if(PORTB & 16) {Buzz(2);} delay_s( 5 ); //Test input 0 and set output //Must first be low(before pulse) so test for low asm: label_in0Low asm btfsc PORTA, 0 asm goto label_in0Low //Test for start of bit Continue=1; while(Continue) { OPTION_REG = 7; //Configure the OPTION register TMR0 = 0; INTCON = 160; //Configure the INTCON register to enable tmr0 asm btfsc PORTA, 0 asm clrf _Continue asm nop } INTCON = 0; //Disable Interupts //Delay for bit length 1.7ms Delay(); //Test bit and set or clear if(PORTA & 1) { Armed_Count = Armed_Count +1; if(Armed_Count >4) { Armed=1; asm bsf PORTB, 0 //Turn on buzzer asm bsf PORTA, 3 } } else { Armed = 0; Armed_Count = 0; asm bcf PORTB, 0 //Turn off buzzer asm bcf PORTA, 3 } //Test input 1 and set output //Must first be low(before pulse) so test for low asm: label_in1Low asm btfsc PORTA, 1 asm goto label_in1Low //Test for start of bit Continue=1; while(Continue) { OPTION_REG = 7; //Configure the OPTION register TMR0 = 0; INTCON = 160; //Configure the INTCON register to enable tmr0 asm btfsc PORTA, 1 asm clrf _Continue asm nop } INTCON = 0; //Disable Interupts //Delay for bit length 1.7ms Delay(); //Test bit and set or clear if(PORTA & 2) { Drogue_Count = Drogue_Count +1; if(Drogue_Count >4) { if(Armed==1) { asm bsf PORTB, 1 } } } else { Drogue_Count = 0; asm bcf PORTB, 1 } //Test input 2 and set output //Must first be low(before pulse) so test for low asm: label_in2Low asm btfsc PORTA, 2 asm goto label_in2Low //Test for start of bit Continue=1; while(Continue) { OPTION_REG = 7; //Configure the OPTION register TMR0 = 0; INTCON = 160; //Configure the INTCON register to enable tmr0 asm btfsc PORTA, 2 asm clrf _Continue asm nop } INTCON = 0; //Disable Interupts //Delay for bit length 1.7ms Delay(); //Test bit and set or clear if(PORTA & 4) { Main_Count = Main_Count +1; if(Main_Count >4) { if(Armed==1) { asm bsf PORTB, 2 } } } else { Main_Count = 0; asm bcf PORTB, 2 } //Start over asm nop asm goto label_in0Low }