digital i/o board communication problem
peleus21
Posts: 16
hey all
i am new to microcontrollers and programming. i am working hard to learn fast. i have studied the "what is a microcontroller" and "stamp works"
so here is my query or actually 2 of them
i have the Parallax Digital I/O Board connected to a BS2pe MOBO using serial connection
here is my code is basically the demo code
' {$STAMP BS2pe}
' {$PBASIC 2.5}
DataIO PIN 8 ' (AP8)DIN & DATA_RLY
Clock PIN 9 ' (AP9)DIGITAL I/O
HC595 PIN 11 ' (AA2)LAT_RLY Pin
HC165 PIN 12 ' (AA3)LOAD_IN Pin
' constants
Yes CON 1 ' Yes Constant
No CON 0 ' No Constant
' variables
rlout VAR Byte ' relay out Variable
optos VAR Byte ' Opto Status Byte
' program
DEBUG CLS
HIGH HC165 ' Make Output And HIGH
DO
GOSUB Out_595 ' Update 74HC595
GOSUB In_165 ' Read 74HC165
GOSUB door_Open
LOOP
STOP
' subroutines
Out_595:
SHIFTOUT DataIO, Clock, MSBFIRST, [rlout]
PULSOUT HC595, 5 ' Latch Outputs
RETURN
In_165:
PULSOUT HC165, 5 ' Load Inputs
SHIFTIN DataIO, Clock, MSBPRE, [optos]
RETURN
Door_Open:
DO
GOSUB Out_595
GOSUB In_165
IF optos = %00001111 THEN
rlout = %00000011
ELSEIF optos = %00001011 THEN
rlout = %00000011
ELSEIF optos = %00000111 THEN
rlout = %00000011
ELSEIF optos = %00000011 THEN
rlout = %00000011
ELSEIF optos = %00000010 THEN
rlout = %00000010
ELSEIF optos = %00000001 THEN
rlout = %00000001
ELSEIF optos = %00000000 THEN
rlout = %00000000
RETURN
ELSE
ENDIF
LOOP
relay 1 and 2 open the doors, inputs 1,2 and 3,4 define when it is all the way closed or open so motors do not burn out.
question one: is there a way to define only the info i want ie. make get and send data to relay and input 2 for instance without haveing to define all other input / output possibilities
second problem might not be anything if there is a better way but if i try to add "door_open" subroutine into another command ( i added a gas sensor program) or subroutine it will leave the 2 relays on and carry on. in fact nothing i do will turn them off. it must be something simple i am missing
i am new to microcontrollers and programming. i am working hard to learn fast. i have studied the "what is a microcontroller" and "stamp works"
so here is my query or actually 2 of them
i have the Parallax Digital I/O Board connected to a BS2pe MOBO using serial connection
here is my code is basically the demo code
' {$STAMP BS2pe}
' {$PBASIC 2.5}
DataIO PIN 8 ' (AP8)DIN & DATA_RLY
Clock PIN 9 ' (AP9)DIGITAL I/O
HC595 PIN 11 ' (AA2)LAT_RLY Pin
HC165 PIN 12 ' (AA3)LOAD_IN Pin
' constants
Yes CON 1 ' Yes Constant
No CON 0 ' No Constant
' variables
rlout VAR Byte ' relay out Variable
optos VAR Byte ' Opto Status Byte
' program
DEBUG CLS
HIGH HC165 ' Make Output And HIGH
DO
GOSUB Out_595 ' Update 74HC595
GOSUB In_165 ' Read 74HC165
GOSUB door_Open
LOOP
STOP
' subroutines
Out_595:
SHIFTOUT DataIO, Clock, MSBFIRST, [rlout]
PULSOUT HC595, 5 ' Latch Outputs
RETURN
In_165:
PULSOUT HC165, 5 ' Load Inputs
SHIFTIN DataIO, Clock, MSBPRE, [optos]
RETURN
Door_Open:
DO
GOSUB Out_595
GOSUB In_165
IF optos = %00001111 THEN
rlout = %00000011
ELSEIF optos = %00001011 THEN
rlout = %00000011
ELSEIF optos = %00000111 THEN
rlout = %00000011
ELSEIF optos = %00000011 THEN
rlout = %00000011
ELSEIF optos = %00000010 THEN
rlout = %00000010
ELSEIF optos = %00000001 THEN
rlout = %00000001
ELSEIF optos = %00000000 THEN
rlout = %00000000
RETURN
ELSE
ENDIF
LOOP
relay 1 and 2 open the doors, inputs 1,2 and 3,4 define when it is all the way closed or open so motors do not burn out.
question one: is there a way to define only the info i want ie. make get and send data to relay and input 2 for instance without haveing to define all other input / output possibilities
second problem might not be anything if there is a better way but if i try to add "door_open" subroutine into another command ( i added a gas sensor program) or subroutine it will leave the 2 relays on and carry on. in fact nothing i do will turn them off. it must be something simple i am missing
Comments
http://www.parallax.com/Portals/0/Downloads/docs/prod/boards/DIOBBASICStampCodeV1.0.zip
it is the Diob serial test bs2 file
i am trying to expand on it but have never programmed a serial communication code before
my application is as stated above
i want to control a set of motors to move a door. it has switches that tell controller when the door is all the way open or closed so that it does not keep on trying to open or close it after it is opened or closed all the way. i am having trouble with this part
[
GOSUB Out_595
GOSUB In_165
IF optos = %00001111 THEN
rlout = %00000011
ELSEIF optos = %00001011 THEN
rlout = %00000011
ELSEIF optos = %00000111 THEN
rlout = %00000011
ELSEIF optos = %00000011 THEN
rlout = %00000011
ELSEIF optos = %00000010 THEN
rlout = %00000010
ELSEIF optos = %00000001 THEN
rlout = %00000001
ELSEIF optos = %00000000 THEN
rlout = %00000000
RETURN
ELSE
ENDIF
LOOP
]
is there a better way to do this
say i want only to deal with the third and fourth digit in the binary string regardless what the other binary numbers were or better yet is there a way to get away from using the binary all together without using to much program space. would rather use less space regardless the method
Welcome to the forum!
-Phil
can anybody refer me to a refrence on how to write and or understand serial communication programming?