'Charlos Potma PA3CKR ' '20070218 v00 basic rs-232 string receive, checksum, timeout '20070220 v01 large font display '20070222 v02 handle sensor not attached (or i2c error) '20070429 v03 read potmeter voltage to determine temp trip setting ' $regfile = "m32def.dat" $crystal = 4000000 $baud = 9600 Const Versionstr = "v03" Const Cr = 10 Const Linefeed = 13 Const Strlength = 40 Const Maxnodata = 20 'Define a graphic LCD 'The dataport is the portname that is connected to the data lines of the LCD 'The controlport is the portname which pins are used to control the lcd 'CE, CD etc. are the pin number of the CONTROLPORT. ' For example CE =2 because it is connected to PORTC.2 'mode 8 gives 240 / 8 = 30 columns , mode=6 gives 240 / 6 = 40 columns 'The connections of the LCD used in this program: 'LCD pin connected to ' 1 GND GND '2 GND GND '3 +5V +5V '4 -9V -9V potmeter '5 /WR PORTC.0 '6 /RD PORTC.1 '7 /CE PORTC.2 '8 C/D PORTC.3 '9 NC not conneted '10 RESET PORTC.4 '11-18 D0-D7 PA '19 FS PORTC.5 '20 NC not connected Config Graphlcd = 240 * 128 , Dataport = Portb , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 6 'led flasher indicating activity Config Pind.7 = Output Led Alias Portd.7 'toggle this pin to invert lcd display Config Pind.6 = Output Lcdinvert Alias Portd.6 'temperature high alarm output pin Config Pind.5 = Output Tempalarmout Alias Portd.6 'potmeter voltage input to adc Config Pina.0 = Input Start Adc Dim Inchar As String * 1 Dim Inbyte As Byte Dim Inpstr As String * Strlength Dim Strcompl As Bit Dim Needcls As Bit Dim Tempalarm As Bit Dim Tempalarmcnt As Byte Dim Timeoutcount As Word Dim Strpos As Byte Dim Crc As Byte Dim Crchexstr As String * 4 Dim Crchexinp As String * 4 Dim Crctot As Word Dim Tempstr As String * 1 Dim Temperaturestr As String * 2 Dim Xpos As Byte Dim Ypos As Byte Dim Temperature As Byte Dim Adcin As Word Dim Temptrip As Word 'put big digit in tempstr on location xpos,ypos Declare Sub Lcddigit Timeoutcount = 0 Set Needcls Reset Tempalarm Reset Strcompl Reset Lcdinvert Reset Tempalarm Reset Tempalarmout Tempalarmcnt = 0 Strpos = 1 Enable Interrupts Enable Urxc 'where to go if a character arrives through the rs-232 i/f On Urxc Getchar Cursor Off Cls Locate 1 , 1 Lcd "Temperature receive & display, " ; Versionstr Wait 1 Cls Showpic 0 , 0 , Tjlogo Wait 3 Inpstr = " " Wait 2 Do Set Led Adcin = Getadc(0) Temptrip = Adcin / 100 Temptrip = Temptrip * 10 If Temptrip > 90 Then Temptrip = 90 If Temptrip < 20 Then Temptrip = 20 Locate 16 , 1 Lcd Temptrip If Tempalarm = 1 Then Toggle Lcdinvert Else Reset Lcdinvert End If Waitms 100 If Strcompl = 1 Then Timeoutcount = 0 Crchexstr = "????" Crctot = 0 Tempstr = Mid(inpstr , 1 , 7) Crc = Crc8(tempstr , 7) Crctot = Crctot + Crc Tempstr = Mid(inpstr , 8 , 7) Crc = Crc8(tempstr , 7) Crctot = Crctot + Crc Tempstr = Mid(inpstr , 15 , 7) Crc = Crc8(tempstr , 7) Crctot = Crctot + Crc Tempstr = Mid(inpstr , 22 , 7) Crc = Crc8(tempstr , 7) Crctot = Crctot + Crc Crchexstr = Hex(crctot) Crchexinp = Mid(inpstr , 29 , 4) If Crchexstr = Crchexinp Then Tempalarmcnt = 0 If Needcls = 1 Then 'cls only if we come here after "data corrupt" or "timeout" Cls Reset Needcls Showpic 0 , 0 , Bol End If 'display temperatures 'temp 1 Tempstr = Mid(inpstr , 4 , 1) If Tempstr <> " " Then Xpos = 104 Ypos = 0 Call Lcddigit End If Tempstr = Mid(inpstr , 5 , 1) If Tempstr <> " " Then Xpos = Xpos + 16 Call Lcddigit End If Temperaturestr = Mid(inpstr , 4 , 2) Temperature = Val(temperaturestr) If Temperature > Temptrip Then Incr Tempalarmcnt End If 'temp 2 Tempstr = Mid(inpstr , 11 , 1) If Tempstr <> " " Then Xpos = 16 Ypos = 32 Call Lcddigit End If Tempstr = Mid(inpstr , 12 , 1) If Tempstr <> " " Then Xpos = Xpos + 16 Call Lcddigit End If Temperaturestr = Mid(inpstr , 12 , 2) Temperature = Val(temperaturestr) If Temperature > Temptrip Then Incr Tempalarmcnt End If 'temp 3 Tempstr = Mid(inpstr , 18 , 1) If Tempstr <> " " Then Xpos = 40 Ypos = 80 Call Lcddigit End If Tempstr = Mid(inpstr , 19 , 1) If Tempstr <> " " Then Xpos = Xpos + 16 Call Lcddigit End If Temperaturestr = Mid(inpstr , 18 , 2) Temperature = Val(temperaturestr) If Temperature > Temptrip Then Incr Tempalarmcnt End If 'temp 4 Tempstr = Mid(inpstr , 25 , 1) If Tempstr <> " " Then Xpos = 184 Ypos = 80 Call Lcddigit End If Tempstr = Mid(inpstr , 26 , 1) If Tempstr <> " " Then Xpos = Xpos + 16 Call Lcddigit End If Temperaturestr = Mid(inpstr , 25 , 2) Temperature = Val(temperaturestr) If Temperature > Temptrip Then Incr Tempalarmcnt End If If Tempalarmcnt <> 0 Then Set Tempalarm Set Tempalarmout Else Reset Tempalarm Reset Tempalarmout End If Else Cls Locate 1 , 1 Lcd "Data incomplete or incorrect." Locate 4 , 1 Lcd Inpstr Set Needcls Set Tempalarm Set Tempalarmout End If Inpstr = " " Reset Strcompl Strpos = 1 Else Timeoutcount = Timeoutcount + 1 End If Reset Led Waitms 100 If Timeoutcount > Maxnodata Then Cls Locate 1 , 1 Lcd "No data received for two seconds." Timeoutcount = 0 Set Needcls Set Tempalarm Set Tempalarmout End If Loop Getchar: Inbyte = Inkey() If Inbyte > 0 Then Inchar = Chr(inbyte) If Inbyte = Cr Then Set Strcompl Else Mid(inpstr , Strpos , 1) = Inchar Strpos = Strpos + 1 If Strpos > Strlength Then Set Strcompl End If End If Return End Sub Lcddigit Select Case Tempstr Case "0" : Showpic Xpos , Ypos , Digit0 Case "1" : Showpic Xpos , Ypos , Digit1 Case "2" : Showpic Xpos , Ypos , Digit2 Case "3" : Showpic Xpos , Ypos , Digit3 Case "4" : Showpic Xpos , Ypos , Digit4 Case "5" : Showpic Xpos , Ypos , Digit5 Case "6" : Showpic Xpos , Ypos , Digit6 Case "7" : Showpic Xpos , Ypos , Digit7 Case "8" : Showpic Xpos , Ypos , Digit8 Case "9" : Showpic Xpos , Ypos , Digit9 Case "-" : Showpic Xpos , Ypos , Minus End Select End Sub Digit0: $bgf "0.bgf" Digit1: $bgf "1.bgf" Digit2: $bgf "2.bgf" Digit3: $bgf "3.bgf" Digit4: $bgf "4.bgf" Digit5: $bgf "5.bgf" Digit6: $bgf "6.bgf" Digit7: $bgf "7.bgf" Digit8: $bgf "8.bgf" Digit9: $bgf "9.bgf" Minus: $bgf "minus.bgf" Point: $bgf "point.bgf" Bol: $bgf "bol.bgf" Tjlogo: $bgf "tjlogo.bgf"