' ========================================================================= ' ' File....... HR_Test.BS2 ' Purpose.... ' Author..... Jon Williams -- Parallax, Inc. ' E-mail..... jwilliams@parallax.com ' Started.... ' Updated.... 30 JUL 2005 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- ' -----[ Constants ]------------------------------------------------------- DegSym CON 186 ' degrees symbol ' -----[ Variables ]------------------------------------------------------- testRec VAR Nib ' test record eePntr VAR Byte tempIn VAR Word ' raw temperature sign VAR tempIn.BIT8 ' 1 = negative temperature cRem VAR Word ' count remaining slope VAR Word ' slope (counts per degree) tC VAR Word ' Celsius tF VAR Word ' Fahrenheit ' -----[ EEPROM Data ]----------------------------------------------------- HrVals DATA Word 0, 94, 127 DATA Word 0, 98, 127 DATA Word 0, 97, 127 DATA Word 0, 99, 127 ' -----[ Initialization ]-------------------------------------------------- Reset: ' -----[ Program Code ]---------------------------------------------------- Main: FOR testRec = 0 TO 3 GOSUB Get_HR_Temp Show_C: DEBUG "C", TAB, (tC.BIT15 * 13 + 32), DEC (ABS tC / 100), ".", DEC2 (ABS tC), DegSym, CR Show_F: DEBUG "F", TAB, (tF.BIT15 * 13 + 32), DEC (ABS tF / 100), ".", DEC2 (ABS tF), DegSym, CR, CR PAUSE 500 NEXT END ' -----[ Subroutines ]----------------------------------------------------- Get_HR_Temp: eePntr = testRec * 4 ' point to record READ eePntr, Word tempIn, cRem, slope ' read values IF (sign = 0) THEN ' positive? tC = (tempIn / 2) * 100 ' yes, conver to 100ths tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp IF (tC.BIT15 = 0) THEN ' positive? tF = tC * 9 / 5 + 3200 ' convert to Fahr ELSE tF = 3200 - ((ABS tC) * 9 / 5) ENDIF ELSE tC = (tempIn / 2) | $FF00 * 100 ' fix neg bits, make 100ths tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp tF = 3200 - ((ABS tC) * 9 / 5) ' convert to Fahr ENDIF RETURN