'**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 18.02.2010 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** DEFINE OSCCAL_1K 1 CMCON = %11111111 ANSEL = %00000000 DEFINE LCD_DREG PORTC DEFINE LCD_RSREG PORTC DEFINE LCD_RSBIT 4 DEFINE LCD_EREG PORTC DEFINE LCD_EBIT 5 DEFINE LCD_LINES 1 DEFINE LCD_COMMANDUS 2000 DEFINE LCD_DATAUS 50 Comm_Pin1 VAR PortA.4 Comm_Pin2 VAR PortA.5 Busy VAR BIT ' Busy Status-Bit R_Temp VAR WORD ' RAW Temperature readings TempC VAR WORD ' Temp in deg C TempF VAR WORD ' Temp in deg F Float VAR WORD ' Holds remainder for + temp C display Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C Real_Cold CON 1 ' Define Real_Cold = 1 BAUD CON 16468 ' N9600 for serial LCD Deg CON 223 ' Data to display Deg ° symbol CLR CON 1 ' CLR LCD command LINE1 CON 128 ' LCD line #1 LINE2 CON 192 ' LCD line #2 INS CON 254 ' LCD command mode parameter Sign VAR BYTE ' +/- sign for temp display Dummy VAR BYTE ' Dummy for Div32 temp VAR BYTE temp_d VAR BYTE znak VAR bit temp1 var byte temp2 var byte sign1 var byte sign2 var byte PAUSE 1000 LCDOUT $fe,1 Start_Convert1: OWOUT Comm_Pin1, 1, [$CC, $44]' Skip ROM search & do temp conversion Wait_Up1: OWIN Comm_Pin1, 4, [Busy] ' Read busy-bit IF Busy = 0 THEN Wait_Up1 ' Still busy..?, Wait_Up..! OWOUT Comm_Pin1, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory OWIN Comm_Pin1, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms GOSUB Convert_Temp temp1 = temp: sign1 = sign Start_Convert2: OWOUT Comm_Pin2, 1, [$CC, $44]' Skip ROM search & do temp conversion Wait_Up2: OWIN Comm_Pin2, 4, [Busy] ' Read busy-bit IF Busy = 0 THEN Wait_Up2 ' Still busy..?, Wait_Up..! OWOUT Comm_Pin2, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory OWIN Comm_Pin2, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms GOSUB Convert_Temp temp2 = temp: sign2 = sign IF temp1 = 0 THEN sign1 = " " ENDIF if temp2 = 0 then sign2 = " " ENDIF LCDOUT $fe, $80, sign1, #temp1, " ", sign2,#temp2, " " goto Start_Convert1 Convert_Temp: ' +32.0 to +257 F IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C Sign = "+" : znak = 0 Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value TempC = DIV32 10 ' Use Div32 value to calculate precise deg C Dummy = 1125 * R_Temp TempF = DIV32 100 IF TempF >6795 THEN ' Over 99.5 deg F..? TempF = TempF + 3200 ELSE TempF = TempF + 3200 ENDIF TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625 temp = TempC: temp_d = Float DIG 3 RETURN Yikes: ' Display full range -C to -F conversion Sign = "-" : znak = 1 ' Display - symbol for negative temp Dummy = 625 * ~R_Temp+1' Multiply to load internal registers with 32-bit value TempC = DIV32 10 ' Use Div32 value to calculate precise deg C TempF = ~R_Temp / 16 ' Begin conversion from -C to deg +/-F IF TempF >=18 THEN ' Check for -degrees F "-18 C = -0.4 F" TempF = ((((TempF + 50) * 9) /5) -122) ' -C to -F below -17 deg C temp = (TempC DIG 4)*10 + (TempC DIG 3): temp_d = TempC DIG 2 ELSE ' Else result = +deg F TempF = ((((-TempF + 50) * 9) /5) -58)' -C to +F below 32.0 deg F to -17 deg C temp = (TempC DIG 4) *10 + (TempC DIG 3): temp_d = TempC DIG 2 ENDIF RETURN