kevlar129bp
- 2nd September 2007, 02:35
Hello all,
I am a newbie when it comes to picbasic, which brings me to my question. If I post my present code I am entertaining, will one of you fine programmers scrutinize it for me? It should be pretty straight-forward. I am looking at controlling relays with a pic. I don't need advice on what controller to use, and so forth...moreover, am I using the correct code or is there a more efficient way.
Anyhow, here goes:
\\CODE START//
INCLUDE "bs2defs.bas"
DEFINE OSC 20
SerialInput var PORTA.0 'serial input pin
board var byte
relay var byte
stat var byte
trisa = %00000001
trisb = %11111111
trisc = %00000000
trisd = %00000000
trise = %00000000
boardAddr = PORTB '<<<<<<<8 bit address set via dip switches
Start :
' Wait until the character “B” AND board address is received serially on porta.0
serin2 serialinput,84,[WAIT ("B",board)]
if board <> boardAddr then goto start
' Wait until the character “R” is received serially on porta.0 and put next character into B1
SERIN SerialInput,N9600,["R"],relay
' Wait until the character “S” is received serially on porta.0 and put next character into B2
SERIN SerialInput,N9600,["S"],stat
'****Send serial from pc like so?: MSComm1.Output = "B??" + Chr$(13) + "R??" + Chr$(13) + "S??" + Chr$(13)
'****Send serial from pc like so?: MSComm1.Output = "B??R??S??" + Chr$(13)
SELECT CASE relay
CASE 1
IF stat = 1 THEN HIGH PORTA.4
LOW PORTA.3
CASE 2
IF stat = 1 THEN HIGH PORTA.3
LOW PORTA.4
CASE 3
IF stat = 1 THEN HIGH PORTA.5
LOW PORTA.2
CASE 4
IF stat = 1 THEN HIGH PORTA.2
LOW PORTA.5
CASE 5
IF stat = 1 THEN HIGH PORTE.0
LOW PORTA.1
CASE 6..........
END SELECT
goto Start
\\CODE END//
I sure hope one of you fine people can assist me. If my application is unclear, please let me know. Thank you much.
Chris
I am a newbie when it comes to picbasic, which brings me to my question. If I post my present code I am entertaining, will one of you fine programmers scrutinize it for me? It should be pretty straight-forward. I am looking at controlling relays with a pic. I don't need advice on what controller to use, and so forth...moreover, am I using the correct code or is there a more efficient way.
Anyhow, here goes:
\\CODE START//
INCLUDE "bs2defs.bas"
DEFINE OSC 20
SerialInput var PORTA.0 'serial input pin
board var byte
relay var byte
stat var byte
trisa = %00000001
trisb = %11111111
trisc = %00000000
trisd = %00000000
trise = %00000000
boardAddr = PORTB '<<<<<<<8 bit address set via dip switches
Start :
' Wait until the character “B” AND board address is received serially on porta.0
serin2 serialinput,84,[WAIT ("B",board)]
if board <> boardAddr then goto start
' Wait until the character “R” is received serially on porta.0 and put next character into B1
SERIN SerialInput,N9600,["R"],relay
' Wait until the character “S” is received serially on porta.0 and put next character into B2
SERIN SerialInput,N9600,["S"],stat
'****Send serial from pc like so?: MSComm1.Output = "B??" + Chr$(13) + "R??" + Chr$(13) + "S??" + Chr$(13)
'****Send serial from pc like so?: MSComm1.Output = "B??R??S??" + Chr$(13)
SELECT CASE relay
CASE 1
IF stat = 1 THEN HIGH PORTA.4
LOW PORTA.3
CASE 2
IF stat = 1 THEN HIGH PORTA.3
LOW PORTA.4
CASE 3
IF stat = 1 THEN HIGH PORTA.5
LOW PORTA.2
CASE 4
IF stat = 1 THEN HIGH PORTA.2
LOW PORTA.5
CASE 5
IF stat = 1 THEN HIGH PORTE.0
LOW PORTA.1
CASE 6..........
END SELECT
goto Start
\\CODE END//
I sure hope one of you fine people can assist me. If my application is unclear, please let me know. Thank you much.
Chris