Hi
This is a project I did a while ago, it was not working at 100%, I am back into it now and I cannot resolve the issue. The I am using two modules, One sending and one receiving (wireless). The sending modulesends the raw data, and the receiving module decodes it and interprets it onto a LCD screen..
I do get the right temperature, but it just keep changing to extrem values, . Lets say it 21 degrees, then it would chnge to -6500 then to 320 then back to 21. I tried changing the baudrate, faster and slower, no success.
here are both programs.
In the sending program i used to have a LCD to see what was sending, But the final version do not have a LCD, but by removing all the lines corresponging to the LCD, it even worst, I barely see the real temperature, and most of the time its random numbers..
thanks for the help.
'TRANSMIT PIC Code
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]
'23
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
'43
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
'59
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
end
'RECEIVE PIC Code
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' 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 byte : encoded2 var byte : 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 word : tempc var word : tempF var word
temperature1 var word : temp1 var word : tempbit var byte : tempf0 var word
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.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) +3200)
lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop
Bookmarks