'--------------------------------------------------------------------------- ' Description: ' ' SE-TEMP ' ' Celsius Temperature Display ' ' ' Written by Junghoon Kim 27-Aug-2003 ' Compiled by BASCOM 8051 Demo ' ' http://www.mcselec.com/download_8051.htm ' ' SAMPLE Electronics co. ' #301 Jeshin Bd. 43-22 Shinkey-dong Yongsan-ku ' Seoul 190-040 South KOREA ' Tel: +82-2-707-3882(Office) +82-2-701-8051(Show Room) ' Fax: +82-2-707-3884(Office) +82-2-701-8058(Show Room) ' Mail : sample@korea.com ' Web : HTTP://WWW.SAMPLE.CO.KR '--------------------------------------------------------------------------- ' 7 Segment Pattern Data Const Segpat0 = &B11000000 ' 0 ****A*** Const Segpat1 = &B11111001 ' 1 * * Const Segpat2 = &B10100100 ' 2 F B Const Segpat3 = &B10110000 ' 3 * * Const Segpat4 = &B10011001 ' 4 ****G*** Const Segpat5 = &B10010010 ' 5 * * Const Segpat6 = &B10000010 ' 6 E C Const Segpat7 = &B11011000 ' 7 * * Const Segpat8 = &B10000000 ' 8 ****D*** Const Segpat9 = &B10011000 ' 9 Const Segpatm = &B10111111 ' Minus Sign Const Segpatb = &B11111111 ' A BLANK '--------------------------------------------------------------------------- Fndsela Alias P3.2 ' FND 1 Common Anode Fndselb Alias P3.3 ' FND 2 Common Anode Fndselc Alias P3.4 ' FND 3 Common Anode Fndseld Alias P3.5 ' FND 4 Common Anode Ds18s20 Alias P3.7 ' Dallas DS18S20 '--------------------------------------------------------------------------- ' $crystal = 12000000 ' Crystal attached ' Config 1wire = Ds18s20 ' 1 Wire Port ' Dim Tlsb As Byte , Tmsb As Byte Dim Fndd As Byte , Fndc As Byte , Fndb As Byte , Fnda As Byte Dim D As Byte , F As Byte , P As Byte , I As Byte , J As Byte ' Do ' Incr J If J = 0 Then Gosub Read_ds18s20 Else Waitms 5 End If 'Waitms 5 : Tmsb = &H00 : Tlsb = &HAA ' // FND Test +85.0 'Waitms 5 : Tmsb = &H00 : Tlsb = &H32 ' // FND Test +25.0 'Waitms 5 : Tmsb = &H00 : Tlsb = &H01 ' // FND Test + 0.0 'Waitms 5 : Tmsb = &H00 : Tlsb = &HAA ' // FND Test +85.0 'Waitms 5 : Tmsb = &HFF : Tlsb = &HFF ' // FND Test - 0.5 'Waitms 5 : Tmsb = &HFF : Tlsb = &HCE ' // FND Test -25.0 'Waitms 5 : Tmsb = &HFF : Tlsb = &H92 ' // FND Test -55.0 Gosub Genpat ' Incr I : I = I And &H03 Set Fndsela : Set Fndselb : Set Fndselc : Set Fndseld ' If I = 0 Then P1 = Fnda : Reset Fndsela End If ' If I = 1 Then P1 = Fndb : Reset Fndselb End If ' If I = 2 Then P1 = Fndc : Reset Fndselc End If ' If I = 3 Then P1 = Fndd : Reset Fndseld End If ' Loop '--------------------------------------------------------------------------- Read_ds18s20: ' Read DS18S20 Temperature Sensor ' 1wreset ' Reset the device 1wwrite &HCCH ' Master issues Skip ROM command 1wwrite &H44H ' Master issues Convert T command ' 1wreset 1wwrite &HCCH ' Master issues Skip ROM command 1wwrite &HBEH ' Master issues Read Scratchepad command ' Tlsb = 1wread() ' Read Temperature Low Byte Tmsb = 1wread() ' Read Temperature High Byte ' Return '--------------------------------------------------------------------------- Genpat: ' F = Tlsb ' If Tmsb <> 0 Then F = F Xor &HFF : F = F + 1 ' Minus Temperature End If ' Shift F , Right ' If Tlsb.0 = 0 Then Fndd = Segpat0 Else Fndd = Segpat5 End If ' D = F Mod 10 : F = F / 10 : Gosub Patcon : Fndc = P And &B01111111 D = F Mod 10 : F = F / 10 : Gosub Patcon : Fndb = P D = F Mod 10 : Gosub Patcon : Fnda = P ' If Tmsb = 0 Then If Fnda = Segpat0 Then Fnda = Segpatb If Fndb = Segpat0 Then Fndb = Segpatb End If End If Else Fnda = Segpatm If Fndb = Segpat0 Then Fndb = Segpatb End If End If ' Return '--------------------------------------------------------------------------- Patcon: ' FND ÆÐÅÏ º¯È¯ ' D = D And &H0F Select Case D Case 0 : P = Segpat0 Case 1 : P = Segpat1 Case 2 : P = Segpat2 Case 3 : P = Segpat3 Case 4 : P = Segpat4 Case 5 : P = Segpat5 Case 6 : P = Segpat6 Case 7 : P = Segpat7 Case 8 : P = Segpat8 Case 9 : P = Segpat9 Case Else End Select ' Return '--------------------------------------------------------------------------- End