Code:
' MASTERBOARD.BAS
'TO DO: SET ALL REGISTERS AND DEFINES
' MAYBE AN INTERRUPT ROUTINE FOR SERIAL IN?
Include "modedefs.bas"
define OSC 20
'DEFINE HSER_RCSTA 18h ' Set receive register to receiver enabled
'DEFINE HSER_TXSTA 98h ' Set transmit register to transmitter enabled
TXSTA = %00100100
RCSTA = %10010000
ADCON1 = %00000110
TRISA = %00000000
TRISB = %10000000
TRISC = %00000000
TRISD = %00000000
INTCON = %01000000
PIE1.5 = 1 'USART RX INTERRUPT ENABLE
SerRxOK var PORTB.4
SerInPin var PORTC.7
SerOutPin var PORTC.6
ADRpin var PORTB.0
ProgLED var PORTB.7
HrtbtLED var PORTB.6
Address var byte
OutPin var byte
OutLevel var byte
BoardAdd var byte
UpdPinLvl var byte
low Progled
LOW HRTBTLED
Start:
if Adrpin then
serin SerInPin,t9600,["A"],boardadd
IF (boardadd > 0) and (boardadd < 256) THEN
write 0,boardadd
high Progled
pause 1000
low progled
serout seroutpin,t9600,["Board address set to ",boardadd,13,10]
else
serout seroutpin,t9600,["Error: Address ",boardadd," not valid! Please use 1 to 256.",13,10]
endif
goto Start
else
read 0,boardadd
IF (BOARDADD = 0) OR (BOARDADD > 256) THEN
serout seroutpin,t9600,["Board is not addressed. Please set address between 1 and 256.",13,10]
goto start
endif
serin SerInPin,t9600,["A"],address '1 - 256
IF ADDRESS <> boardadd THEN
goto start
endif
serin SerInPin,t9600,["O"],outpin '1 - 24
if (outpin = 0) or (outpin > 24) then
serout seroutpin,t9600,["Error: Output ",outpin," is not valid! Please use 1 to 24.",13,10]
goto start
endif
serin SerInPin,t9600,["L"],outlevel '0 = OFF, 5 = 5%, 10 = 10%, ...50 = 50%,...100 = 100% (by 5's)
if outlevel > 100 then
serout seroutpin,t9600,["Error: Level ",outlevel," is not valid! Please use 0 to 100 (By FIVES).",13,10]
goto start
endif
write outpin,outlevel 'Output will match EEPROM location
read outpin,UpdPinLvl
serout seroutpin,t9600,["Updated output ",outpin," to level ",UpdPinLvl * 5,13,10]
select case outpin
case 1
serout portA.3,n9600,[UpdPinLvl] 'CAT5 JACK 1, PIN 1
case 2
serout portB.1,n9600,[UpdPinLvl] 'CAT5 JACK 1, PIN 2
case 3
serout portA.2,n9600,[UpdPinLvl] 'CAT5 JACK 1, PIN 3
case 4
serout portB.2,n9600,[UpdPinLvl] 'CAT5 JACK 1, PIN 4
case 5
serout portA.1,n9600,[UpdPinLvl] 'CAT5 JACK 1, PIN 5
case 6
serout portB.3,n9600,[UpdPinLvl] 'CAT5 JACK 1, PIN 6
case 7
serout portE.0,n9600,[UpdPinLvl] 'CAT5 JACK 2, PIN 1
case 8
serout portA.5,n9600,[UpdPinLvl] 'CAT5 JACK 2, PIN 2
case 9
serout portE.1,n9600,[UpdPinLvl] 'CAT5 JACK 2, PIN 3
case 10
serout portA.4,n9600,[UpdPinLvl] 'CAT5 JACK 2, PIN 4
case 11
serout portE.2,n9600,[UpdPinLvl] 'CAT5 JACK 2, PIN 5
case 12
serout portA.4,n9600,[UpdPinLvl] 'CAT5 JACK 2, PIN 6
case 13
serout portC.3,n9600,[UpdPinLvl] 'CAT5 JACK 3, PIN 1
case 14
serout portC.2,n9600,[UpdPinLvl] 'CAT5 JACK 3, PIN 2
case 15
serout portD.0,n9600,[UpdPinLvl] 'CAT5 JACK 3, PIN 3
case 16
serout portC.1,n9600,[UpdPinLvl] 'CAT5 JACK 3, PIN 4
case 17
serout portD.1,n9600,[UpdPinLvl] 'CAT5 JACK 3, PIN 5
case 18
serout portC.0,n9600,[UpdPinLvl] 'CAT5 JACK 3, PIN 6
case 19
serout portD.4,n9600,[UpdPinLvl] 'CAT5 JACK 4, PIN 1
case 20
serout portD.5,n9600,[UpdPinLvl] 'CAT5 JACK 4, PIN 2
case 21
serout portC.5,n9600,[UpdPinLvl] 'CAT5 JACK 4, PIN 3
case 22
serout portD.6,n9600,[UpdPinLvl] 'CAT5 JACK 4, PIN 4
case 23
serout portC.4,n9600,[UpdPinLvl] 'CAT5 JACK 4, PIN 5
case 24
serout portD.7,n9600,[UpdPinLvl] 'CAT5 JACK 4, PIN 6
END SELECT
TOGGLE HRTBTLED 'Flashing pretty damn fast!
endif
goto Start
Bookmarks