/* // 16F628 PIC // Antenna Switch 1.1, pinout changes since v1.0 // Antenna Switch Function Description // Loop forever, sleep most of the time // Look at inputs upon change/interrupt // use input pattern to set Relays and LEDs // sleep for awhile // As1 As2 As3 As4 // (no bits set) Input 1 default antenna // x Input 2 N6GN AA // x Input 3 LZ1AQ dipole // x Input 3 LZ1AQ loop // x Input 4 Converter/other/only // 16F628 PIC I/O Register bits // RA7 RA6 RA5 RA4 RA3 RA2 RA1 RA0 // I/O I/O I I/OD I/O I/O I/O I/O // LED4 LED3 - XTRA S2+ S2- S1+ S1- // All RB can have weak pull-ups // RRB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 // I/O I/O I/O I/O I/O I/O I/O I/O // A4 A3 A2 A1 C2 C1 LED2 LED1 */ // CONFIG #pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTRC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config MCLRE = OFF // RA5/MCLR pin function select (RA5/MCLR pin function is digital input, MCLR internally tied to VDD) #pragma config BOREN = ON // Brown-out Reset Enable bit (BOD Reset disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming) #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection off) #pragma config CP = OFF // Code Protection bits (Program memory code protection off) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include #include #include #define LED4 0b10000000 #define LED3 0b01000000 #define LED2 0b00000010 #define LED1 0b00000001 #define LpB 0b00001000 //High asserts LoopB #define LpA 0b00000100 //High asserts LoopA #define nVert 0b00010000 //Low asserts vertical #define SMB1 0b00001001 #define SMB2 0b00001010 #define SMB3 0b00000101 #define SMB4 0b00000110 #define INPUTS 0b11110000 #define _XTAL_FREQ = 37000 // value used by __delay_ms() char Input_State; // global in case we want to use in ISR int main() { unsigned int t; PCON = 0x03; // b3 selects 37kHz oscillator TRISA = 0x20; // <7,6>LED<4,3>,4 XTRA, <3:2>S2,<1:0>S1 OUTPUTs TRISB = 0xF0; // <7:4>,As4:As1 inputs,<3:2> C2,C1,<1:0>,LED<2,1> output OPTION_REG = 0x7F; // enable weak pull-ups on PORTB // b7 b6 b5 b4 b3 b2 b1 b0 // PORTA == LED4 LED3 x XTRA S2+ S2- S1+ S1- // PORTB == As4 As3 As2 As1 C2 C1 LED2 LED1 // flag clearing should already have happened from RESET, INTCONbits.RBIF= 0; //make sure RB flag is cleared INTCONbits.RBIE= 1; //unmask RB interrupt while(1) { Input_State = (~(PORTB>>4) & 0x0F ); INTCONbits.RBIF= 0; // clear flag set by state change switch(Input_State) { case (1): //Input "As1", SMB1 LED1, C=0b00 PORTA = SMB1; PORTB = LED1; break; case (2): //Input "As2" SMB2, LED2 LZ1AQ Dipole, ~XTRA PORTA = SMB2; //vertical (no loops) PORTB = LED2; break; case (4): //Input "As3" SMB2, LED2 LZ1AQ Loop A&B, XTRA C=0b00 PORTA = nVert |SMB2; // non-vertical PORTB = LpA | LpB | LED2; // both loops break; case (8): //Input "As4" SMB3, LED3 Converter C=0b00 PORTA = (LED3 | SMB3); PORTB = 0; break; case (0): // no-As "PWON&ANTENNA5",SMB4 LED4, C=0b00 PORTA = (LED4 | SMB4); PORTB = 0; break; //ELSE MIXTURE default : //MIXTURE Input 4 XTRA,SMB4 C=0 all LEDs PORTA = (LED4 | LED3 | nVert | SMB4); PORTB = LED2 | LED1; } for (t=60;t>1;t--){}; // give relays time to latch PORTA = (PORTA & 0xF0); // then turn off relay power if (INTCONbits.RBIF== 0) // sleep if no new interrupts SLEEP(); // Any PortB<7:4> change should set flag, wake-up // and we should continue // otherwise go around again and service the state change } // end while(1) return 0; } // end main