CPU = 16F876 MHZ = 10 CONFIG 16186 ; Master.bas - Master switch controller ; Version 1.1 - 13 Oct 2007 ; Declarations LCDNib var PortB.nib0 ; Nibble for the LCD Data lines TestBit var PortB.bit4 ; Test Mode - Low = Normal, High = Test BrdSel con B5 ; Board Select - low = board 1, high = board 2 RegSel con B6 ; R/S of the LCD Clk con B7 ; E of the LCD rcode var byte RX con C7 ; RS-232 Receive line TX con C6 ; RS-232 Transmit line Baud con i19200 ; Baud rate init var byte OK var byte ant var byte ; Antenna number (1-6) stn var byte ; Station number (1-4) ant_state var byte ; Memory for antenna select msg var byte(18) CR var byte ; Initialize Variables init = 0 OK = 0 ant_state = 0 ; Initialize I/O Ports adcon1 = 0 trisa=%0000 porta.nib0=$00 trisc=%10000000 ; Initialize Relays and board gosub release LOW BrdSel ; Set up the serial port and initialize the LCD pause 500 LCDWrite RegSel\Clk, LCDNib, [INITLCD1,INITLCD2,TWOLINE,CLEAR, HOME, SCR] LCDWrite RegSel\Clk, LCDNib, [CLEAR] LCDWrite RegSel\Clk, LCDNib, ["The Antenna Farm"] LCDWrite RegSel\Clk, LCDNib, [SCRRAM+$40,"Master v1.1 W7IY"] ;msg = "Master Online" ;SEROUT TX,Baud,[STR msg\13,13] pause 1000 ; ; Main Program Loop ; main: If TestBit=0 then goto TestLoop ; If Test is high, go to test procedure SerIn RX,Baud,[HEX rcode] gosub parse_request if init = 1 then gosub send_init goto main endif ; antenna request if init = 2 then gosub invalid_rcode goto main endif gosub check_ant if OK then gosub select_ant gosub latch_ant gosub disp else gosub send_not_available endif goto main: ; Cycle Relays once TestLoop: FOR stn = 1 to 4 FOR ant = 1 to 6 gosub select_ant gosub latch_ant gosub disp pause 1000 NEXT ant = 0 gosub select_ant gosub latch_ant gosub disp NEXT gosub release goto main ; Release all the antennas release: portc.nib0 = $00 portc.bit4 = 0 portc.bit5 = 0 porta.nib0 = $0F gosub strobe return ; rCode Parser ; Check for INIT 0x(stn#F)h e.g. 1F = station 1, Init ; Check for Request 0x(stn#/ant#)h e.g. 24 = station 2, Antenna 4 ; should check for valid results parse_request: init = 0 stn = (rcode & $F0) >> 4 ant = rcode & $0F if (rcode & $0F) = $0F then init = 1 return endif if ant < 0 OR ant > 6 then init = 2 endif if stn < 0 OR stn > 4 then init = 2 endif return ; Send the Init Message to the remote send_init: init = 0 SerOut TX,Baud,["S",DEC stn,"RX: Select Ant ",13] LCDWrite RegSel\Clk, LCDNib, [CLEAR, HOME] pause 250 LCDWrite RegSel\Clk, LCDNib, ["Initial: ", DEC stn] return ; Is the antenna in use? check_ant: OK = 1 return ; Select the antenna select_ant: ; Make sure antenna select ports are low portc.nib0 = $00 portc.bit4 = 0 portc.bit5 = 0 Branch ant, [No_ANT,ANT1,ANT2,ANT3,ANT4,ANT5,ANT6] No_ANT: msg = "RX: None " return ANT1: msg = "RX: 80M/160M NE " high C0 return ANT2: msg = "RX: 40M NE " high C1 return ANT3: msg = "RX: West " high C2 return ANT4: msg = "RX: South West " high C3 return ANT5: msg = "RX: North West " high C4 return ANT6: msg = "RX: South East " high C5 return ; Latch the antenna selection, i.e. switch the relays latch_ant: OK = 0 Branch stn, [No_STN,STN1,STN2,STN3,STN4] No_STN: STN1: HIGH A0 goto Strobe STN2: HIGH A1 goto Strobe STN3: HIGH A2 goto Strobe STN4: HIGH A3 goto Strobe Strobe: pause 50 porta.nib0 = $00 return ; Send results to remote disp: SEROUT TX,Baud,["S",DEC stn,STR msg\16,13] ;HSEROUT [str msg\16,13] LCDWrite RegSel\Clk, LCDNib, [CLEAR, HOME] LCDWrite RegSel\Clk, LCDNib, ["Station: ", DEC stn] LCDWrite RegSel\Clk, LCDNib, [SCRRAM+$40, str MSG\16] return ; Send the In use message send_not_available: SerOut TX,Baud,["RX: In Use "] ;HSEROUT ["RX: In use ",13] LCDWrite RegSel\Clk, LCDNib, [CLEAR, HOME] LCDWrite RegSel\Clk, LCDNib, ["RX: In use "] return ; Wasn't able to parse the code invalid_rcode LCDWrite RegSel\Clk, LCDNib, [CLEAR, HOME] LCDWrite RegSel\Clk, LCDNib, ["Rcode: ", DEC rcode] init = 0 return ; Display a message (results) to the LCD display_results: LCDWrite RegSel\Clk, LCDNib, [CLEAR, HOME] LCDWrite RegSel\Clk, LCDNib, ["Rcode: ", DEC rcode] ;LCDWrite RegSel\Clk, LCDNib, [SCRRAM+$40, str MSG\16] return