' ========================================================================= ' ' 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 line VAR Byte ' -----[ EEPROM Data ]----------------------------------------------------- ' raw data is: tempIn (two bytes), cRem, slope HrVals DATA Word 0, 94, 127 DATA Word 0, 98, 127 DATA Word 0, 97, 127 DATA Word 0, 99, 127 DATA Word 1, 62, 127 DATA Word 0, 82, 127 DATA Word 0, 89, 127 DATA Word 0, 93, 127 DATA Word 0, 100, 127 DATA Word 0, 105, 127 DATA Word 0, 121, 127 DATA Word 511, 3, 127 DATA Word 511, 10, 127 DATA Word 511, 15, 127 ' -----[ Initialization ]-------------------------------------------------- Reset: DEBUG CLS, "tempIn cRem slope tC tF ", CR, "--------- ----- ----- --------- ---------" ' -----[ Program Code ]---------------------------------------------------- Main: FOR testRec = 0 TO 13 eePntr = testRec * 4 READ HrVals + eePntr, Word tempIn, cRem, slope line = testRec + 2 DEBUG CRSRXY, 0, line, BIN9 tempIn, CRSRXY, 12, line, DEC3 cRem, CRSRXY, 19, line, DEC3 slope GOSUB Calc_HR_Temp Show_C: DEBUG CRSRXY, 25, line, (tC.BIT15 * 13 + 32), DEC (ABS tC / 100), ".", DEC2 (ABS tC), DegSym Show_F: DEBUG CRSRXY, 36, line, (tF.BIT15 * 13 + 32), DEC (ABS tF / 100), ".", DEC2 (ABS tF), DegSym NEXT END ' -----[ Subroutines ]----------------------------------------------------- Calc_HR_Temp: tempIn = tempIn >> 1 ' remove half degree bit tempIn.BYTE1 = -tempIn.BIT7 ' extend sign tC = tempIn * 100 ' convert to 100ths tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp IF (tC.BIT15 = 0) THEN tF = tC * 9 / 5 + 3200 ' convert pos C to Fahr ELSE tF = 3200 - ((ABS tC) * 9 / 5) ' convert neg C to Fahr ENDIF RETURN