Problems controlling multiple pics
I am currently in the process of designing a servo controller. I have already been able to make a pic that can take a message from a pc serial port and command 11 servos position, and speed.
Now I am having a very hard time taking the messages from a computer, and distributing them to multiple controllers.
For now I am attempting to just control one servo controller, with one master pic interfaced to the pc.
master pic
Code:
define OSC 8
OSCCON = %1111110 ' sets internal osc to run at 8MHZ
'----------turn analog on porta off, and use as digital input/output '----------this is used to allow serial input on the A bus.
CMCON = 7 'Comparators OFF
ANSEL = 0 'A/D OFF -- Port pins all digital
'----------
'---**Pins
rsoutpin var porta.0
rsinpin var porta.1
picinpin var portb.4
picoutpin var portb.5
'---vars
'-------- transfer vars
message var byte
'--------
'---main program
main:
gosub pcin
gosub picout
goto main
'----- retrieve next set of commands from pc.
pcin:
'----send serial request, and get user input, timeout 70 ms
serout2 rsoutpin, 16468, ["ready set go!"] 'call for data
'----
serin2 rsinpin, 16468, 70, main, [message]
'-----end serial request
return
'---- picout procedure waits for high on picinpin and then transmits data
picout:
input picinpin
'--- wait until pic is ready to recieve
while picinpin = 0
pause 1
wend
'-transmit message to pic.
serout2 picoutpin, 16468, [donecommanding]
return
slave pic
Code:
define OSC 8
OSCCON = %1111110 ' sets internal osc to run at 8MHZ
'----------turn analog on porta off, and use as digital input/output '----------this is used to allow serial input on the A bus.
CMCON = 7 'Comparators OFF
ANSEL = 0 'A/D OFF -- Port pins all digital
'----------
'---**Pins
picinpin var porta.1
picoutpin var porta.0
ledpin var portb.4
'---**Variables
'---processing vars
ledstat var byte
'------**main program
main:
gosub recieve
gosub driveled
goto main 'loop forever
recieve:
'----send ready signal and wait for message with timeout 150.
high picoutpin ' ready to recieve
'----
serin2 picinpin, 16468, 150, driveled,[ledstat]
low picoutpin 'not ready to recieve data.
'-----end serial request
return 'return to main routine
driveled:
low picoutpin 'not ready to recieve data.
if ledstat = "O" then
high ledpin 'turn on led
else
low ledpin 'turn off led
endif
return
end
Now this code actually works when I send "O" the light turns on, when I send something else it turns off.
My problem is I have to be able to transfer data that looks like this "03|005|225|y".
DEC2 servonumber "|" DEC3 rate "|" DEC3 position "|" finalcommand (single byte "y"/"n")
I have been unable to transmit this kind of data, and in addition to that I will need to have the master look at the servonumber and send the message to the appropriate slave with the correct servonumber (as all the slaves will be numbered the same internally)
Please let me know if you have any suggestions, or insight into how to achieve this. I have made multiple attempts, but apparently my brain is not working.