$regfile = "m8def.dat"
$crystal = 8000000
$lib "i2c_twi.lbx"
$hwstack = 128
$swstack = 128
$framesize = 32
Dim Temp As Word
Dim T1 As Single
Dim Dat(2) As Byte
Dim Tempvar As Byte
Declare Sub Ds1631_gettemp(byval Device As Byte)
Declare Sub Ds1631_convert(byval Device As Byte)
Declare Sub Ds1631_setstatus(byval Device As Byte , Byval Status As Byte)
Declare Sub Ds1631_por(byval Device As Byte)
Declare Sub Ds1631_waitready(byval Device As Byte)
'SDA und SCL definieren
Config Sda = Portc.4
Config Scl = Portc.5
Ddrb = &B00000111
Portb = &B11111000
Led Alias Portb.2
Config Lcdpin = Pin , Db4 = Portd.6 , Db5 = Portd.5 , Db6 = Portb.0 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.4
Config Lcd = 16 * 1a
Config Lcdmode = Port
Config Lcdbus = 4
Cursor Off Noblink
Enable Interrupts
Config Clock = Soft 'Softclock aktivieren
Config Date = Dmy , Separator = . 'Deutsches Datumsformat
Time$ = "00:00:00" 'Setzen auf Startwert
Date$ = "18.12.07"
'-------------------------------------------------------------
I2cinit
Cls
Call Ds1631_Por(&H90)
Call Ds1631_setstatus(&H90 , 13)
Do
Call Ds1631_convert(&H90)
Call Ds1631_Waitready(&H90)
Call Ds1631_Gettemp(&H90)
Locate 1 , 1
Lcd Time$
Locate 2 , 1
T1 = Temp
If Dat(1).7 = 1 Then T1 = T1 - 4096
T1 = T1 / 16
Lcd Fusing(t1 , "+##.#") ; "ßC "
If T1 > 24.8 Then
Led = 1
Else
Led = 0
End If
Waitms 20
Loop
Sub Ds1631_convert(device As Byte)
I2csend Device , &H51
End Sub
Sub Ds1631_Gettemp(device As Byte)
Dat(1) = &HAA
I2creceive , Device , Dat(1) , 1 , 2
Temp = Dat(1)
Shift Temp , Left , 4
Shift Dat(2) , Right , 4
Temp = Temp + Dat(2)
End Sub
Sub Ds1631_Por(device As Byte)
I2csend Device , &H54
End Sub
Sub Ds1631_Setstatus(device As Byte , Status As Byte)
Dat(1) = &HAC
Dat(2) = Status
I2csend Device , Dat(1) , 2
End Sub
Sub Ds1631_Waitready(device As Byte)
Waitms 200
Dat(1) = &HAC
Do
I2creceive Device , Dat(1) , 1 , 1
Loop Until Dat(1).7 = 1
End Sub