naa, i was initializing zerotemp dee.
I am going to put the calculation on the receiver side only, this is getting real confusing.
The reason i did not want to do that is I am sending 4 byte of coded information. I want to have a high accuracy, so i would like to send the count_per_c and count_remain and in the data sheet. that will add more bytes, If I take the raw information and send it, it will be 4 bytes or 8 encoded byte to send. Is this do able ?
I mean is it too much to send wireles ?
k
anywau here si the code fo the sending part:
i am just worried about the two serout line, should I put it into one line, or is it just the same like this,
I am leaving now, coming back ina few hours
'TRANSMIT PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
DQ var PortB.5
temp var word
temperature var word
count_remain var byte
count_per_c var byte
counter var byte
encoded1 var word
encoded2 var word
encoded22 var word
encoded11 var word
encoded33 var word
encoded44 var word
loop:
owout DQ,1,[$cc]
owout DQ,0,[$44]
Pause 500
owout DQ,1,[$cc]
owout DQ,0,[$be]
owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
'50
encoded1 =temperature.LowBYTE
encoded2 =temperature.HighBYTE
For counter=0 TO 7
IF encoded1.0[counter]=0 Then
encoded11.0[counter*2]=0
encoded11.0[counter*2+1]=1
Else
encoded11.0[counter*2]=1
encoded11.0[counter*2+1]=0
EndIF
Next counter
For counter=0 TO 7
IF encoded2.0[counter]=0 Then
encoded22.0[counter*2]=0
encoded22.0[counter*2+1]=1
Else
encoded22.0[counter*2]=1
encoded22.0[counter*2+1]=0
EndIF
Next counter
For counter=0 TO 7
IF count_remain.0[counter]=0 Then
encoded33.0[counter*2]=0
encoded33.0[counter*2+1]=1
Else
encoded33.0[counter*2]=1
encoded33.0[counter*2+1]=0
EndIF
Next counter
For counter=0 TO 7
IF count_per_c.0[counter]=0 Then
encoded44.0[counter*2]=0
encoded44.0[counter*2+1]=1
Else
encoded44.0[counter*2]=1
encoded44.0[counter*2+1]=0
EndIF
Next counter
lcdout $FE,1
LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin count_remain , ".", bin count_per_c," ",$DF,"F"
serout portb.2, n2400, [$55, $55, $55, $55, $aa]
serout portb.2, n2400, [encoded11.HighBYTE, encoded11.LowBYTE, encoded22.HighBYTE, encoded22.LowBYTE ]
serout portb.2, n2400, [encoded33.HighBYTE, encoded33.LowBYTE, encoded44.HighBYTE, encoded44.LowBYTE ]
goto loop
End
Now that the whole thing is working, you can probably condense those serout lines down into one line...try it and find out...
That and it makes the program shorter on the screen so you don't have to scroll thru so much stuff...
'TRANSMIT PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
DQ var PortB.5 : temp var word : temperature var word : count_remain var byte : count_per_c var byte : counter var byte
encoded1 var word:encoded2 var word:encoded22 var word:encoded11 var word:encoded33 var word:encoded44 var word
loop:
owout DQ,1,[$cc] : owout DQ,0,[$44] : Pause 500 : owout DQ,1,[$cc] : owout DQ,0,[$be]
owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
'50
encoded1 =temperature.LowBYTE : encoded2 =temperature.HighBYTE
'I'd put these encoding/decoding sections into their own subroutine to GOSUB to...
For counter=0 TO 7
IF encoded1.0[counter]=0 Then
encoded11.0[counter*2]=0 : encoded11.0[counter*2+1]=1
Else
encoded11.0[counter*2]=1 : encoded11.0[counter*2+1]=0
EndIF
Next counter
For counter=0 TO 7
IF encoded2.0[counter]=0 Then
encoded22.0[counter*2]=0 : encoded22.0[counter*2+1]=1
Else
encoded22.0[counter*2]=1 : encoded22.0[counter*2+1]=0
EndIF
Next counter
For counter=0 TO 7
IF count_remain.0[counter]=0 Then
encoded33.0[counter*2]=0 : encoded33.0[counter*2+1]=1
Else
encoded33.0[counter*2]=1 : encoded33.0[counter*2+1]=0
EndIF
Next counter
For counter=0 TO 7
IF count_per_c.0[counter]=0 Then
encoded44.0[counter*2]=0 : encoded44.0[counter*2+1]=1
Else
encoded44.0[counter*2]=1 : encoded44.0[counter*2+1]=0
EndIF
Next counter
lcdout $FE,1 : LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin count_remain , ".", bin count_per_c," ",$DF,"F"
serout portb.2, n2400,[$55,$55,$55,$55,$aa,encoded11.HighBYTE,encoded11.L owBYTE,encoded22.HighBYTE]
serout portb.2, n2400,[encoded22.LowBYTE,encoded33.HighBYTE,encoded33.Low BYTE,encoded44.HighBYTE]
serout portb.2, n2400,[encoded44.LowBYTE]
goto loop
Last edited by skimask; - 28th December 2006 at 17:16.
OK, I must be getting lucky, I'm not getting many mistakes as before. The system works now, the sending code is good. The receiving is good for positive celcius, For some undetermined reason it is not giving the right Ferenheit degrees, and I am using the same math equation as before to translate from C to F.
I am now working on the negative celcius and also in that scenatio there is two cases, positive and negative F ...
I will the subroutine for later, I never touched it before so I will do it at the end once everything is working
'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
counter var byte : temperature var word : encoded1 var word : encoded2 var word : encoded3 var byte
encoded11 var word : encoded22 var word : encoded33 var word : encoded44 var word : encoded4 var byte
count_remain var byte : count_per_c var byte : temp var byte : tempc var byte
pause 2000
loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55
waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa
serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE
For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter
temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4
IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempc = (((temperature *9) / 5)+3200)
lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempc / 100) , ".", dec2 tempc >> 1," ",$DF,"F"
goto loop
Zerotemp:
temperature = temperature >> 1 'removing lowest bit
for counter=0 to 14 ' 2's compliment, starting to invert all the digits
if temperature.0[counter] = 1 then temperature.0[counter] =1
if temperature.0[counter] = 0 then temperature.0[counter] =0
next counter
temperature = temperature + 1 ' 2,s compliment ends by adding a one
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempc = (((temperature *9) / 5)+3200)
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempc / 100) , ".", dec2 tempc >> 1," ",$DF,"F"
goto loop
end
for one thing, tempc should be tempf shouldn't it?
Another thing, if your temp value (which I assume is multiplied by 100 by that conversion/correction thing you've got going on) is above 7281, you'll overflow your 16 bit tempc value (65536 / 9 = 7281.xxx). So try dividing by 5 first, then multiply by 9.
tempc = ( ( ( temperature / 5 ) * 9 ) + 3200 )
another thing...what are you trying to do with the lcdout line?
lcdout $FE,$C0,"TempF:",dec (tempc/100),".",dec2 tempc >>1," ",$DF,"F"
I think what you really mean is:
lcdout $fe,$c0,"TempF:",DEC3 (tempc/100),".",DEC2 (tempc//100)," ",$DF,"F"
use the remainder (modulus) ( // ) function, not the shift ( >> ) function.
its working good, now, I think I have a problem with the 2,s compliment, working on it
I am just doing 2,s compliment, I get all 1,s at the output
Zerotemp:
temperature = temperature >> 1 'removing lowest bit
temperature1 = temperature
for counter=0 to 6 ' 2's compliment, starting to invert all the digits
if temperature.0[counter] = 1 then temperature.0[counter] =0
if temperature.0[counter] = 0 then temperature.0[counter] =1
next counter
'temperature = temperature + 1 ' 2,s compliment ends by adding a one
'temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
'tempc = (((temperature *9) / 5) + 3200)
lcdout $FE,1, "TempC: ", bin temperature1, ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", bin temperature , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop
Last edited by lerameur; - 28th December 2006 at 23:36.
I send strings and strings of data using the TWS/RWS modules without much problem at all. Of course I get messed up data once in awhile, that's what error detection is for (checksums, etc.). 4/8 bytes is fine...1000 bytes is fine. It's all in how you want to send it, break it down, detect errors, etc. Just create and use LEDAWDTP (lerameur's error detection and wireless data transfer protocol).
I agree...send only the raw information, then do the math at the receiver end, again, with some error correction. For instance, you get one reading, save it placeA and display it...you get the next reading, save it in placeB. If the placeB reading is higher than placeA, then increment placeA by one, same thing is it's lower, decrement it by one. That way, a one-time reading that's 'out in the weeds' because of bad data won't neccessarily show up on the output as a fluctuating result.
Bookmarks