Hallo Leute
Vielen dank für eure hilfe ich habs geschafft![]()
Nun der Code der auch funktioniert:
Kann man ihn noch kürzen?Code:$regfile = "m16def.dat" $framesize = 60 $swstack = 60 $hwstack = 60 $crystal = 8000000 $baud = 4800 Config Scl = Portc.0 Config Sda = Portc.1 Declare sub Ds1631reset Declare Sub Ds1631convert Declare Sub Ds1631get_status Declare Sub Ds1631set_status Declare Sub Ds1631wait_ready Declare Sub Ds1631get_temp Dim Addr As Byte Dim Dat As Byte Const Convert = &H51 Const Stop_convert = &H22 Const Read_temp = &HAA Const Conf = &HAC Const Reset = &H54 Dim Temp As Word Dim Temphi As Byte Dim Templo As Byte Dim Temp1 As Byte Dim Temp2 As Byte Const Ds1631 = &H90 'Adresse '------------------------------------------------------------- Ds1631reset Ds1631set_status I2cinit Do Waitms 10 Ds1631convert Ds1631wait_ready Ds1631get_temp Shift Temp , Right , 7 Temp1 = Temp / 2 Temp2 = Temp + 1 Temp2 = Temp2 * 5 Print "TEMP: " ; Temp1 ; "." ; Temp2 ; " C " ; Temp Wait 2 Loop '----------------------------------------------------- '------------------ DS1631 RESET ------------------ '----------------------------------------------------- Sub Ds1631reset(addr As Byte) Addr = Ds1631 I2cstart I2cwbyte Addr I2cwbyte Reset I2cstop End Sub '----------------------------------------------------- '------------------ DS1631 CONVERT ---------------- '----------------------------------------------------- Sub Ds1631convert(addr As Byte) Addr = Ds1631 I2cstart I2cwbyte Addr I2cwbyte Convert I2cstop End Sub '----------------------------------------------------- '----------------- GET DS1631 STATUS ----------------- '----------------------------------------------------- Sub Ds1631get_status(addr As Byte) Dim Data As Byte Addr = Ds1631 I2cstart I2cwbyte Addr I2cwbyte Conf I2cstop I2cstart Addr = Addr + 1 I2cwbyte Addr I2crbyte Dat Print "dat1 " ; Dat I2cstop End Sub '------------------------------------------------------- '----------------- SET DS1631 STATUS ----------------- '------------------------------------------------------- Sub Ds1631set_status(addr As Byte , Dat As Byte) Addr = Ds1631 I2cstart I2cwbyte Addr I2cwbyte Conf I2cwbyte &HA1 I2cstop End Sub '------------------------------------------------------- '----------------- WAIT DS1631 READY ----------------- '------------------------------------------------------- Sub Ds1631wait_ready(addr As Byte) Waitms 20 Ds1631get_status End Sub '----------------------------------------------------- '----------------- GET DS1631 TEMP ----------------- '----------------------------------------------------- Sub Ds1631get_temp(addr As Byte , Temp As Word , Dat As Byte ) Addr = Ds1631 I2cstart I2cwbyte Addr I2cwbyte Read_temp I2cstop Addr = Addr + 1 I2cstart I2cwbyte Addr I2crbyte Dat , Ack Temp = Dat * 256 Print ; "dat2 " ; Dat I2crbyte Dat , Nack Temp = Temp + Dat print;"dat3 ";dat I2cstop End Sub







Zitieren

Lesezeichen