Strings......and how to join them
Hello all. So, I have learned more off this forum than I ever imagined (I now have a fully functional temperature/humidity controller, which I can send via FM RF about 100 metres using serin2/serout2, switch on humidifiers, switch on de-humidifiers, switch on heaters, coolers)...so now I need to know how to make a string of several different variables, I.E. out= A joined with B and joined with C. Am I making sense?
well, it goes like this........
Really, all I want to do is take a constant i(2 bits) add a variable in t(3 bits) add another variable in h(3bits) and make it all one long(ish) variable of 8 bits, so I end up with string = iittthhh. I guess I could "join" them in the serout2 command (serout2,portpin,mode,i,t,h) but that didn't seem to work very well for me
well, the thing is............
That problem has gone. For future reference, I am using version 2.47. The problem I'm having now is this. I have perfect radio communications between 2 16F877A's, at both short and long range, but I'm not having much success transmitting and then receiving variables.
My TX line is :
SEROUT2 PORTc.2,16780,[((id<<6)+(rhtc/100<<3)+(temp/100))]
which seems not to be a problem
my RX line is
SERIN2 PORTc.4,16780,250,programstart,[str myvar\6]
but I don't get what I send. I'm sure there is a glaring error somewhere, but when I hserout myvar I get numbers, but not what I sent
so, what happened was..........
I did write uS when I meant mS, but no worries.
The synching issue isn't a problem, because the PIC on the PC sends a command out to the other PIC and it acts on that command. The other PIC is in receive mode straight after the command is sent waiting 250ms for something to come in.
On the code bit....
I expected 3638, I got 146. I expected 3640 or something close, and I get 224. The annoying thing is, I had this part working a few weeks ago, and I messed around with it, and now I can't remember how I done it. thats how I ended up messing around with the formats, and of course, sending a byte and getting a string....not a good way to make things work
ALTHOUGH, I have now found the error. It's not so much in the TX or RX, but in the definition of temp. I'm working on that now, so I will get back with a real update in the next hour or two
Manchester? are they the 3rd best team in England or something?
Ski, I spent yesterday and Sunday encoding my data with the Manchester coding, and it is a very bulky way of getting information from point A to B via RF. I did a lot of playing around and I found that if I send what I want at 4800 bps and inverted (mode 16752) or 2400 bps and inverted it will arrive fine EVERY TIME. HOWEVER, if you try and send the data NON-INVERTED it just arrives muddled and messed up. Here is the TX and RX code. There is no need for synching because the the temp/hum sender only sends the data when asked, and sends it individually.
(PC Based 16F877)
transmit: 'Send commands
let i=0 ' Set i to 0
for i = 0 to 1 ' 2 pass loop
portd.1=1 ' Switch on TX module
pause 125 ' wait 125 ms to slew TX
serout2 PORTd.0,16572,[25,25,25,25] ' send command to get Temp
pause 25 ' pause
next i ' Next pass
portd.1=0 ' switch off TX module
portc.3=1 ' switch on RX module
pause 113 ' pause to allow RX to slew
SERIN2 PORTc.4,16572,250,programstart,[STR temp\25\13] 'receive temp up to 25 bits, ending with char 13
HSEROUT [str temp\21,13,10,32,CR] ' display temp
clear ' clear array
pause 10000 ' wait 10 seconds
let i=0 ' set i to 0
for i = 0 to 1 ' start 2 pass loop
portd.1=1 ' switch on TX module
pause 125 ' allow time for TX module to switch on
serout2 PORTd.0,16572,[35,35,35,35] ' send command to get Humidity
pause 25 ' pause
next i ' next pass
portd.1=0 ' switch off TX module
portc.3=1 ' switch on RX module
pause 113 ' pause
SERIN2 PORTc.4,16572,250,programstart ,[STR hum\25\13] 'receive humidity up to 25 bits, ending with char 13
HSEROUT [" ",str hum\21,13,10,32,CR] ' Display result
CLEAR ' Clear array
pause 125 ' Pause
portc.3=0 ' switch off RX module
pause 10 ' Pause
goto programstart
(Temp / Humidity module)
receive: ' receive
portc.1 = 1 ' switch on port
pause 25
SERIN2 PORTC.0,16572,250,main,[command]
if command = 25 then goto tempsend
if command = 35 then goto humsend
goto main
'*********************** Send the Temperature *********************'
tempsend:
portc.1=0 :
portc.3=1
for c =0 to 2
pause 150 'pause 150 mS
SEROUT2 PORTc.2,16572,["**Temperature ",dec2(temp/100),".",dec1 (Temp),13]
PAUSE 100 ' Pause 100mS
next c ' next pass
portc.3=0 : goto main
'********************** Send the Humidity ***********************'
humsend:
portc.1=0 ' Back to main
portc.3=1 ' switch on tx
for c =0 to 2 ' start 4 pass loop
pause 150
SEROUT2 PORTc.2,16572,["**Humidity ",DEC2 (RHtc/10),".",DEC1 RHtc,13]
PAUSE 100 ' Pause 100uS
next c
portc.3=0
goto main ' next pass