///////////////////////////////////////////////////////////////////////// //// LDG DTS-6 RELAY BOX CONTROLLER -RELAY- //// //// V2 //// ///////////////////////////////////////////////////////////////////////// /* -----\ /----- PIN_RX A2 <01> <28> A1 PIN_TX A3 <02> <27> A0 A4 <03> 1 <26> OSC1 _MCLR <04> 6 <25> OSC2 VSS <05> F <24> VDD B0 <06> 8 <23> B7 PIN_RL6 B1 <07> 4 <22> B6 PIN_RL1 PIN_RL5 B2 <08> <21> B5 PIN_RL2 PIN_RL4 B3 <09> <20> B4 PIN_RL3 ------------- */ #include <16F84A.h> #FUSES NOWDT //No Watch Dog Timer #FUSES HS //High speed Osc (> 4mhz) #FUSES NOPUT //No Power Up Timer #FUSES NOPROTECT //Code not protected from reading #define PIN_RL6 PIN_B1 #define PIN_RL5 PIN_B2 #define PIN_RL4 PIN_B3 #define PIN_RL3 PIN_B4 #define PIN_RL2 PIN_B5 #define PIN_RL1 PIN_B6 #define PIN_RX PIN_A2 #define PIN_TX PIN_A3 #use delay(clock=4000000) #use rs232(baud=1200,parity=E,xmit=PIN_TX,rcv=PIN_RX,bits=8) char CH,RLBYTE,DELAY,CODE; void TestRelays(){ output_high(PIN_RL1); delay_ms(250); output_low(PIN_RL1); delay_ms(250); output_high(PIN_RL2); delay_ms(250); output_low(PIN_RL2); delay_ms(250); output_high(PIN_RL3); delay_ms(250); output_low(PIN_RL3); delay_ms(250); output_high(PIN_RL4); delay_ms(250); output_low(PIN_RL4); delay_ms(250); output_high(PIN_RL5); delay_ms(250); output_low(PIN_RL5); delay_ms(250); output_high(PIN_RL6); delay_ms(250); output_low(PIN_RL6); delay_ms(250); } Decode(CH){ switch (CH){ case 0b10000000: CODE=1; break; // button 1 message case 0b01000000: CODE=2; break; // button 2 message case 0b00100000: CODE=3; break; // button 3 message case 0b00010000: CODE=4; break; // button 4 message case 0b00001000: CODE=5; break; // button 5 message case 0b00000100: CODE=6; break; // button 6 message case 0b00001100: CODE=7; break; // buttons 5&6 message case 0b00000010: CODE=8; break; // status request message default: CODE=0; break; } } UpdateRelays(RLBYTE,DELAY){ if ((RLBYTE&0b10000000)!=0) output_high(PIN_RL1); else output_low(PIN_RL1); delay_ms(DELAY); if ((RLBYTE&0b01000000)!=0) output_high(PIN_RL2); else output_low(PIN_RL2); delay_ms(DELAY); if ((RLBYTE&0b00100000)!=0) output_high(PIN_RL3); else output_low(PIN_RL3); delay_ms(DELAY); if ((RLBYTE&0b00010000)!=0) output_high(PIN_RL4); else output_low(PIN_RL4); delay_ms(DELAY); if ((RLBYTE&0b00001000)!=0) output_high(PIN_RL5); else output_low(PIN_RL5); delay_ms(DELAY); if ((RLBYTE&0b00000100)!=0) output_high(PIN_RL6); else output_low(PIN_RL6); delay_ms(DELAY); } void main(){ RLBYTE=read_eeprom(0); // Byte stored as {RL1,RL2,RL3,RL4,RL5,RL6,0,0} delay_ms(250); UpdateRelays(RLBYTE,250); while (TRUE){ // M A I N L O O P CODE=0; while (CODE==0){ CH=getc(); Decode(CH); } switch (CODE){ case 7: write_eeprom(0,RLBYTE); break; case 8: ; break; default: RLBYTE=RLBYTE^CH; break; } UpdateRelays(RLBYTE,0); putc(RLBYTE); } }