'{$STAMP BS2} 'LCD temperature display message1 data "Temperature: ",0 messageClr data " ",0 messageBy1 data "Thermometer____________",0 messageBy2 data "______by_airchild______",0 messageOver data "HIGH! ",0 messageUnd data "LOW! ",0 messageErr data "Malfunction",0 SPECIAL1 data %00000100 data %00001110 data %00011111 data %00000100 data %00000100 data %00000000 data %00000000 data %00000000 SPECIAL2 data %00000000 data %00000000 data %00000000 data %00000100 data %00000100 data %00011111 data %00001110 data %00000100 SPECIAL3 data %00000000 data %00000000 data %00000000 data %00011111 data %00011111 data %00000000 data %00000000 data %00000000 i var word temploc var word difference var word(2) counter var byte counterroll con 12 GoSub SubInitLCD LCDData = %100 GoSub SubDisplayControlLCD LCDData = SPECIAL1 LCDData2 = 0 GoSub SubCharLCD LCDData = SPECIAL2 LCDData2 = 1 GoSub SubCharLCD LCDData = SPECIAL3 LCDData2 = 2 GoSub SubCharLCD '''''''' init: '''''''' '' draw temp message LCDData = 0 'go to location 0 GoSub SubMoveLCD LCDData = messageBy1 GoSub SubMessageLCD 'write first line LCDData = $40 'go to second line GoSub SubMoveLCD LCDData = messageBy2 'write second line GoSub SubMessageLCD pause 1000 'show welcome message :) GoSub GetTemp LCDData = 0 'go to location 0 GoSub SubMoveLCD LCDData = messageClr GoSub SubMessageLCD 'clear LCDData = 0 'go to location 0 GoSub SubMoveLCD LCDData = message1 GoSub SubMessageLCD 'write Temp message temploc = LCDData 'remember where end is (add offset if necessary, if cursor wasn't at home) LCDData = $40 'go to second line GoSub SubMoveLCD LCDData = messageClr 'write second line GoSub SubMessageLCD difference(0) = temperature difference(1) = temperature '''''''' main: '''''''' GoSub FormatDisplayTemp 'debug ?temperature GoSub GetTemp goto main ''''''' FormatDisplayTemp: ''''''' LCDData = 0 GoSub SubMoveLCD MAXtemp con 1200 '120.0 degrees F MINtemp con 100 ' 10.0 degrees F Errtemp con 5000 'obviously an error if temperature > Errtemp then formaterr if temperature = 0 then formaterr LCDData = message1 GoSub SubMessageLCD if temperature > MAXtemp then formatOver if temperature < MINtemp then formatUnd 'temperature change icon LCDData = $40+23 GoSub SubMoveLCD counter = counter+1 max (counterroll+1) if (counter < counterroll) then skipdifference difference(0) = difference(1) difference(1) = temperature skipdifference: i = ((difference(1) - difference(0)) & $80) max 1 TEMPDELTA con 5 i = (abs(difference(0) - difference(1)) min TEMPDELTA - TEMPDELTA max 1)<<1 | i '' xy x = changed y = up or down lookup i,[2,2,0,1], LCDData 'debug ?i 'debug ?difference(0) 'debug ?difference(1) GoSub SubDataLCD LCDData = temploc GoSub SubMoveLCD digits var byte(4) digitsC var byte(4) 'format into digits digits(3) = (temperature // 10) + "0" 'LSD, tenths digits(2) = ((temperature/10) // 10) + "0" 'ones digits(1) = ((temperature/100) // 10) + "0" 'tens digits(0) = ((temperature/1000) // 10) + "0" 'hundreds digitsC(0) = " " if (celsius < $8000) then nonnegative digitsC(0) = "-" celsius = -celsius nonnegative: digitsC(3) = (celsius // 10) + "0" 'LSD, tenths digitsC(2) = ((celsius /10) // 10) + "0" 'ones digitsC(1) = ((celsius /100) // 10) + "0" 'tens if NOT ((digitsC(0) = "-") and (digitsC(1) = "0")) then skipsingledigit digitsC(0) = " " digitsC(1) = "-" skipsingledigit: if NOT ((digitsC(0) = " ") and (digitsC(1) = "0")) then skipsingledigitpos digitsC(0) = " " digitsC(1) = " " skipsingledigitpos: if digits(0) <> "0" then skiphundredsblank digits(0) = " " skiphundredsblank: if NOT ((digits(0) = " ") and (digitsC(1) = "0")) then skiptensblank digits(1) = " " skiptensblank: 'display values LCDData = digits(0) GoSub SubDrawLCD LCDData = digits(1) GoSub SubDrawLCD LCDData = digits(2) GoSub SubDrawLCD LCDData = "." GoSub SubDrawLCD LCDData = digits(3) GoSub SubDrawLCD LCDData = $DF 'degree symbol GoSub SubDrawLCD LCDData = "F" GoSub SubDrawLCD LCDData = " " GoSub SubDrawLCD LCDData = $40 + temploc GoSub SubMoveLCD 'celsius display LCDData = digitsC(0) GoSub SubDrawLCD LCDData = digitsC(1) GoSub SubDrawLCD LCDData = digitsC(2) GoSub SubDrawLCD LCDData = "." GoSub SubDrawLCD LCDData = digitsC(3) GoSub SubDrawLCD LCDData = $DF 'degree symbol GoSub SubDrawLCD LCDData = "C" GoSub SubDrawLCD LCDData = " " GoSub SubDrawLCD return formatOver: LCDData = messageOver Gosub SubMessageLCD LCDData = $40 GoSub SubMoveLCD LCDData = messageClr GoSub SubMessageLCD return formatUnd: LCDData = messageUnd Gosub SubMessageLCD LCDData = $40 GoSub SubMoveLCD LCDData = messageClr GoSub SubMessageLCD return formatErr: LCDData = messageClr GoSub SubMessageLCD LCDData = 0 GoSub SubMoveLCD LCDData = messageErr Gosub SubMessageLCD LCDData = $40 GoSub SubMoveLCD LCDData = messageClr GoSub SubMessageLCD return ''''''' GetTemp: ''''''' TempPin con 11 'hook this pin to R1 to A to C1 to GND. hook tempOutVoltage to R2 to A. SamplePin con 12 SAMPLELENGTH con 2000 PRESAMPLE con 300 temperature var word celsius var word measure var bit outs.bit0(TempPin) = 0 'low dirs.bit0(TempPin) = 1 'output 'presample to equalize voltage before counting duty cycle for i = 1 to PRESAMPLE outs.bit0(TempPin) = ~ins.bit0(SamplePin) 'always output opposite temperature = temperature + (outs.bit0(TempPin)) next temperature = 0 for i = 1 to SAMPLELENGTH outs.bit0(TempPin) = ~ins.bit0(SamplePin) 'always output opposite temperature = temperature + (outs.bit0(TempPin)) next dirs.bit0(TempPin) = 0 'input '''''calculate temperature from duty cycle 'Vx = 1.458 crossover point on input pin 'Vt = temp from device. solver for this 'Vd = duty cycle from pin ' 'Vx = average( Vd, Vt) if both Rs are the same ' THRESHHOLD con 1458*2 'input pin threshold i = temperature i = ((5 * i) / (SAMPLELENGTH/1000)) temperature = THRESHHOLD - i 'calibration i = (temperature * 15) i = i + (34 - (temperature/100)) temperature = i / 16 + 2 celsius = (temperature * 5 / 9) - 178 return ''''''' ' LCD subroutines ''''''' EnablePin con 10 RSPin con 8 RWPin con 9 LCDOut var Outs.byte0 LCDDir var Dirs.byte0 LCDIn var Ins.byte0 DirOutput con $ff DirInput con 0 LCDData var byte LCDData2 var byte '''''''''''''''''' SubInitLCD: ''' '''''''''''''''''' LOW RWPin 'set for output to LOW RSPin LOW EnablePin pause 10 'make sure LCD gets stablized LCDDir = DirOutput LCDOut = %00111000 'function set. 8bit, multi-line, 5x8 letters High EnablePin Low EnablePin LCDOut = %00000001 'reset display 'pause 1 High EnablePin Low EnablePin pause 4 LCDOut = %00000110 'set display mode, increment, no shift 'pause 1 High EnablePin Low EnablePin 'pause 1 LCDDir = DirInput return ''''''''''''''''''''''' SubDisplayControlLCD: '''''''''''''''''''''''set display data 'debug "display: ", BIN3 LCDData, cr LOW RSPin LOW RWPin LCDOut = %00001000 | (%00000111 & LCDData) ''' last three bits are display, cursor, and blink LCDDir = DirOutput 'pause 1 High EnablePin Low EnablePin 'pause 1 LCDDir = DirInput return '''''''''''''''' SubMoveLCD: ''''''''''''''''move to location LCDData in DRam 'debug "move, loc: ", DEC LCDData, cr LOW RSPin LOW RWPin LCDOut = %10000000 | (%01111111 & LCDData) LCDDir = DirOutput 'pause 1 High EnablePin Low EnablePin 'pause 1 LCDDir = DirInput return ''''''''''''''' SubDataLCD: '''''''''''''''send data out 'debug "data $", hex2 LCDData, " -- ", LCDData, cr HIGH RSPin LOW RWPin LCDOut = LCDData LCDDir = DirOutput 'pause 1 High EnablePin Low EnablePin 'pause 1 LCDDir = DirInput return ''''''''''''''' SubDrawLCD: '''''''''''''''send cursor out, then data DISPLAYPAUSE con 20 HIGH RSPin LOW RWPin LCDOut = $FF 'cursor LCDDir = DirOutput High EnablePin Low EnablePin LOW RSPin LOW RWPin LCDOut = %00010000 High EnablePin Low EnablePin pause DISPLAYPAUSE HIGH RSPin LOW RWPin LCDOut = " " 'cursor LCDDir = DirOutput High EnablePin Low EnablePin LOW RSPin LOW RWPin LCDOut = %00010000 High EnablePin Low EnablePin pause DISPLAYPAUSE HIGH RSPin LCDOut = LCDData High EnablePin Low EnablePin LOW RSPin LCDDir = DirInput pause DISPLAYPAUSE return '''''''''''''' SubMessageLCD: '''''''''''''' LCDData contains location of message. returns LCDData as length of message i = LCDData loopMessage: read i, LCDData if LCDData = 0 then returnfromSubMessage i = i + 1 GoSub SubDataLCD goto loopMessage returnfromSubMessage: LCDData = i return '''''''''''''' SubCharLCD: '''''''''''''' LCDData = location of char data, LCDData2 = location to set LOW RSPin LOW RWPin LCDOut = %01000000 | ((LCDData2 << 3) & %00111111) LCDDir = DirOutput High EnablePin Low EnablePin HIGH RSPin for LCDData2 = 0 to 7 read LCDData, LCDOut High EnablePin Low EnablePin LCDData = LCDData + 1 next LCDData = LCDData - 8 LOW RSPin LCDDir = DirInput return