///////////////////////////////////////////////////////////////////////// //// LDG DTS-6 RELAY BOX CONTROLLER -CONTROL- //// //// V2 //// ///////////////////////////////////////////////////////////////////////// /* -----\ /----- SW1 A2 <01> <28> A1 SW4 SW2 A3 <02> <27> A0 SW5 LED1 A4 <03> 1 <26> A7 SW6 SW3 A5 <04> 6 <25> A6 LED4 VSS <05> F <24> VDD B0 <06> 8 <23> SENSE LED2 B1 <07> 8 <22> B6 LED5 RX <08> <21> TX LED3 B3 <09> <20> B4 LED6 ------------- */ #include <16F88.h> #device adc=8 #FUSES NOWDT //No Watch Dog Timer #FUSES INTRC_IO //Internal RC Osc, no CLKOUT #FUSES NOPUT //No Power Up Timer #FUSES NOMCLR //Master Clear pin used for I/O #FUSES NOBROWNOUT //No brownout reset #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O #FUSES NOCPD //No EE protection #FUSES NOWRT //Program memory not write protected #FUSES NODEBUG //No Debug mode for ICD #FUSES NOPROTECT //Code not protected from reading #FUSES NOFCMEN //Fail-safe clock monitor disabled #FUSES NOIESO //Internal External Switch Over mode disabled #define PIN_LED1 PIN_A4 #define PIN_LED2 PIN_B1 #define PIN_LED3 PIN_B3 #define PIN_LED4 PIN_A6 #define PIN_LED5 PIN_B6 #define PIN_LED6 PIN_B4 #define PIN_SW1 PIN_A2 #define PIN_SW2 PIN_A3 #define PIN_SW3 PIN_A5 #define PIN_SW4 PIN_A1 #define PIN_SW5 PIN_A0 #define PIN_SW6 PIN_A7 #define PIN_RX PIN_B2 #define PIN_TX PIN_B5 #define PIN_SENSE PIN_B7 #use delay(clock=4000000) #use rs232(baud=1200,parity=E,xmit=PIN_TX,rcv=PIN_RX,bits=8) char CH,SWBYTE; #int_rda rs232_handler(){ CH=getc(); if ((CH&0b10000000)!=0) output_high(PIN_LED1); else output_low(PIN_LED1); // CHECK INDIVIDUAL BITS if ((CH&0b01000000)!=0) output_high(PIN_LED2); else output_low(PIN_LED2); // AND TURN ON LEDS if ((CH&0b00100000)!=0) output_high(PIN_LED3); else output_low(PIN_LED3); if ((CH&0b00010000)!=0) output_high(PIN_LED4); else output_low(PIN_LED4); if ((CH&0b00001000)!=0) output_high(PIN_LED5); else output_low(PIN_LED5); if ((CH&0b00000100)!=0) output_high(PIN_LED6); else output_low(PIN_LED6); while(kbhit())// EMPTY RECEIVE BUFFER CH=getc(); } void LedsON(){ output_high(PIN_LED1); output_high(PIN_LED2); output_high(PIN_LED3); output_high(PIN_LED4); output_high(PIN_LED5); output_high(PIN_LED6); } void LedsOFF(){ output_low(PIN_LED1); output_low(PIN_LED2); output_low(PIN_LED3); output_low(PIN_LED4); output_low(PIN_LED5); output_low(PIN_LED6); } void FlashALL(){ int i; for(i=0;i<3;i++){ LedsON(); delay_ms(100); LedsOFF(); delay_ms(100); }; } void main() { //setup_adc_ports(NO_ANALOGS|VSS_VDD); // Compiler generated. Locks up. /*setup_adc(ADC_OFF); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_oscillator(OSC_4MHZ|OSC_INTRC);*/ output_high(PIN_LED1); delay_ms(50); // SHIFTED LEDS FLASH output_high(PIN_LED2); delay_ms(50); output_high(PIN_LED3); delay_ms(50); output_low (PIN_LED1); delay_ms(50); output_high(PIN_LED4); delay_ms(50); output_low (PIN_LED2); delay_ms(50); output_high(PIN_LED5); delay_ms(50); output_low (PIN_LED3); delay_ms(50); output_high(PIN_LED6); delay_ms(50); output_low (PIN_LED4); delay_ms(50); output_low (PIN_LED5); delay_ms(50); output_low (PIN_LED6); delay_ms(50); delay_ms(2000); //GIVE MAIN UNIT TIME TO SWITCH RELAYS AT TURN-ON enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); putc(0b00000010); // ASK FOR RELAY BYTE while(TRUE){ delay_ms(25); // DEBOUNCING while (!input(PIN_SW1)); // MAKE SURE ALL BUTTONS HAVE BEEN RELEASED while (!input(PIN_SW2)); while (!input(PIN_SW3)); while (!input(PIN_SW4)); while (!input(PIN_SW5)); while (!input(PIN_SW6)); delay_ms(25); // DEBOUNCING SWBYTE=0; while (SWBYTE==0){ if (!input(PIN_SW1)) SWBYTE=0b10000000; if (!input(PIN_SW2)) SWBYTE=0b01000000; if (!input(PIN_SW3)) SWBYTE=0b00100000; if (!input(PIN_SW4)) SWBYTE=0b00010000; if (!input(PIN_SW5)) { delay_ms(100); // GIVE THE USER TIME TO PRESS SW6 if (!input(PIN_SW6)) {SWBYTE=0b00001100; FlashALL();} else SWBYTE=0b00001000; }; if ((SWBYTE==0)&&(!input(PIN_SW6))) { delay_ms(100); // GIVE THE USER TIME TO PRESS SW5 if (!input(PIN_SW5)) {SWBYTE=0b00001100; FlashALL();} else SWBYTE=0b00000100; }; }; putc(SWBYTE); } }