Main Menu
PBP Code Menu
Login
Username:

Password:


Lost Password?

Register now!
Math: Temperature Conversion  
Author: Darrel Taylor
Published: 3/15/2005
Read 4361 times
Size 4.03 KB
Printer Friendly Page Tell a Friend
 
Temperature Conversion

Temperature Conversion (for Picbasic Pro)

Temp_Convert.pbp

This is an INCLUDE file that makes it EASY to convert between Celsius, Fahrenheit and Kelvin temperature scales.  It's compatible with both MPASM and PM, and is not processor dependant, so it should work on ANY chip that's supported by Picbasic Pro..

Functions:                           Input Range
  CtoF - Celsius to Fahrenheit    -273.0 to +1802.6
  FtoC - Fahrenheit to Celsius    -459.0 to +3276.7
  CtoK - Celsius to Kelvin        -273.0 to +3000.0
  KtoC - Kelvin to Celsius           0.0 to +3276.7
  FtoK - Fahrenheit to Kelvin     -459.0 to +3276.7
  KtoF - Kelvin to Fahrenheit        0.0 to +3276.7

All functions accept a Signed Word variable for the input, it MUST be a variable, and will NOT work with constants.  The output is also a Signed Word variable. Resolution is 0.1 deg.
In order for the numbers to fit in a word variable, it's multiplied *10
   25.0 deg C is stored as 250,  -10 is stored as -100

Here's a simple example that converts 25.0 °C to Fahrenheit.

INCLUDE  "Temp_Convert.pbp"
C  VAR WORD      ; Celsius
F  VAR WORD      ; Fahrenheit
K  VAR WORD      ; Kelvin
C = 250          ; Set to 25.0 deg. C
@  CtoF  _C, _F  ; Convert Celsius to Fahrenheit

 F now contains 770,  representing 77.0 °F
Notice the @ symbol at the beginning of the line, and the Underscore before the variable names.

To convert the previous result (77.0 °F) to Kelvin is just as easy.

@  FtoK  _F, _K  ; Convert Fahrenheit to Kelvin

  K now contains 2980,  representing 298.0 °K

And of course, you'll need to be able to display the results. 
Here's an example for use with an LCD display.

X  VAR WORD
X = F  ; Copy F to X for ShowTemp
GOSUB ShowTemp : LCDOUT $DF,"F"   ; $DF is deg. symbol

X = C
GOSUB ShowTemp : LCDOUT "  ",$DF,"C"

STOP
' --- Display a Signed Word with 1 decimal place ---
ShowTemp:
    if X.15 = 1 then LCDOUT "-"
    X = ABS(X)
    LCDOUT dec (X/10),".",dec X//10
Return

For a more complete example program, see the Test_Temp_Convert.pbp  file in the .Zip located below.

 
Downloads for Math: Temperature Conversion
Temp_Convert.zip
downloads File Description:
INCLUDE file that converts between Celsius, Fahrenheit and Kelvin

downloads 862  File Size 3.06 KB  File Mimetypeapplication/x-zip-compressedUploaded: 3/15/2005
Article Rated: 7.50 (2 votes)
Rate this Article
Return to Category | Return To Main Index
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
Anonymous
Posted: 2005/4/26 21:41  Updated: 2005/4/26 21:41
 Nice program
Cool, that works GREAT!

Thanks Darrel :)
Anonymous
Posted: 2005/5/18 10:14  Updated: 2005/5/18 10:14
 thx
great job !!! thx
Darrel Taylor
Posted: 2005/5/19 20:15  Updated: 2005/5/19 20:15
Webmaster
Joined: 2004/2/8
From: California
Posts: 86
Online!
 Re: thx
Thanks guys, It's nice to know it's working for you. Darrel