I just flip these around and it works
if temperature.0[counter] = 0 then temperature.0[counter] =1
if temperature.0[counter] = 1 then temperature.0[counter] =0
I just flip these around and it works
if temperature.0[counter] = 0 then temperature.0[counter] =1
if temperature.0[counter] = 1 then temperature.0[counter] =0
when it get to ZERO, it shows 655,
then when it reach about -3 then it shows the right temp, weird..
any idea?
its all good now, exept foe that part between 0 to -5 degrees celcius,
There is no grey area, if the bit 11 os 1, then goto zerotemp, the math is the same for -1 C or -10C....
'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 word : tempc var byte : tempF var word
temperature1 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= 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)
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
Zerotemp: ' cases when zero celcius and positive Fahrenheit
temperature = temperature >> 1 'removing lowest bit
temperature1 = temperature
for counter = 0 to 6
if temperature.0[counter] = 1 then
temperature.0[counter] = 0
else
temperature.0[counter] = 1
endif
next counter
temp = temp + 1 ' 2,s compliment ends by adding a one
temp = temp >> 5
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)
if tempF = 0 then goto ZeroF
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop
ZeroF: ' cases when zero celcius and 0 Fahrenheit
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop
end
Last edited by lerameur; - 29th December 2006 at 00:34.
You do realize that 0C is not 0F right?
0C = 32F
0F = -17.78C
Maybe it would be easier (if you really need to display both C and F) if you'd convert your initial celsius reading from the serin statements over to the Kelvin scale (0C = 273K, 0K = -273C), add in the correction factors, and then convert them back, taking into account the + and - as needed right before displaying the final numbers
Last edited by skimask; - 29th December 2006 at 01:31.
And all based from the celsius value....
1) if tempC > 0 then both C and F are positive
2) if tempC => -17 and tempC <=0 then C is negative, F is positive
3) if tempC < -17 then both C and F are negative
or in Kelvin terms...
1) if tempK > 273 then C/F +
2) if tempK => 256 and tempK <=273 then C- and F+
3) if tempK < 256 then C/F -
Well, this might be a bug...or not...the tempC to tempF conversion is done differently in the 2 spots...and so are the lines above that...2 different methods... Shouldn't everything be the same except for the display?
I'm not sure, you're doing it a bit different than I would do it... maybe it's one of those 'features' like Windows always has in it that Microsoft fixes every Tuesday![]()
I made these formulas and tested them on a calculator. it works. I dont know hy it do not work on the pogram I wrote.
So
ZeroF: ' cases when zero celcius and 0 Fahrenheit
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)
--- SO if I need to do the conversion : -17C to 1.4F
so I take 1700 (17 *100) put it in the formula (temperature) I get 140, just divide by 100 to get the answer..
k
Last edited by lerameur; - 29th December 2006 at 02:44.
Zerotemp: ' cases when zero celcius and positive Fahrenheit
temperature = temperature >> 1 'removing lowest bit
temperature1 = temperature
for counter = 0 to 6
if temperature.0[counter] = 1 then
temperature.0[counter] = 0
else
temperature.0[counter] = 1
endif
next counter
------------------------------------temp value right here not set up
temp = temp + 1 ' 2,s compliment ends by adding a one
temp = temp >> 5
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)
if tempF = 0 then goto ZeroF
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop
ZeroF: ' cases when zero celcius and 0 Fahrenheit
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop
Where is the first temp getting set at? I don't think it is. I think it's always $ab (left over $aa from the serin with 1 added).
See my post above referring to your post #114...your logic above is flawed also
(temperature.0[counter] - just call it temp for right now)
if temp is zero, set it to one. then go to the next line down
if temp is one, set it to zero. again, it just got set to 1 on the line above!
Bookmarks