pengoomeister
New Member
Hi,
I think I'am out of ideas and need some help with my code.
I have built TX and RX units which works when I run a simple test loop with LEDs connected. I've run the code in proteus and in the virtual terminal everything works, it also works on my veloboard connecting the PICs with a straight wire.
But in real life I have trouble getting a stable transmission, and my temperature from the TX unit is 0.0.
TX code
RX code
I think I'am out of ideas and need some help with my code.
I have built TX and RX units which works when I run a simple test loop with LEDs connected. I've run the code in proteus and in the virtual terminal everything works, it also works on my veloboard connecting the PICs with a straight wire.
But in real life I have trouble getting a stable transmission, and my temperature from the TX unit is 0.0.
TX code
Code:
'Symbol definitions
symbol TempRead = w0 '(b1:b0)
symbol TempC_100 = w1 '(b3:b2)
symbol Whole = b4
symbol Remainder = b5
symbol msb = b7
symbol STATIONID = $02
main:
pause 5000
high 2 'turn on DS18B20 temp sensor
ReadTemp12 2,TempRead 'Read tube air temp
low 2 'deactivate temp sensor
Goto DoCal 'Calculate Temp
end
DoCal:
msb = TempRead / 256 / 128 'Find most significant bit, 0 means a positive number.
if msb = 1 then '1 is a negative number
TempRead = TempRead ^ $ffff + 1 'Twos comp for neg calc
endif
'Start 12 bit conversion
TempC_100 = TempRead * 6
TempRead = TempRead * 25 / 100
TempC_100 = TempC_100 + TempRead
'End 12 bit conversion
Whole = TempC_100 / 100 ' "/" returns whole number
Remainder = TempC_100 // 100 ' "//" or "%" = modulus divide
Remainder = Remainder / 10 'Reduces the amount of decimal places by one, but rounds down.
if msb = 0 then
positive:
high 1 'activate transmitter
pause 500
serout 4,T300,($55, $55, $55, B4, B5, B7, STATIONID)
low 1 'deactivate transmitter
pulsout 0,20000 ' red LED winks as data sent
goto main
endif
if msb = 1 then
negative:
high 1 'activate transmitter
pause 500
serout 4,T300,($55, $55, $55), B4, B5, B7, STATIONID
low 1 'deactivate transmitter
pulsout 0,20000 ' red LED winks as data sent
goto main
endif
Code:
'Reciver code
'Symbol definitions
symbol Whole = b4
symbol Remainder = b5
symbol msb = b7
symbol STATIONID = b6
high 1 'activate reciver
pulsout 0,2000 ' red LED winks as data sent
rxloop:
serin 4,T300,Whole, Remainder, msb, STATIONID
pulsout 0,2000 ' red LED winks as data sent
if msb = 0 then
positive:
serout 2,T300,(#Stationid,";",#Whole,".",#Remainder,13, 10) 'DataLink
pulsout 0,20000 ' red LED winks as data sent
goto rxloop
endif
if msb = 1 then
negative:
serout 2,T300,(#Stationid,";","-",#Whole,".",#Remainder,13, 10) 'DataLink
pulsout 0,20000 ' red LED winks as data sent
goto rxloop
endif