Hallo,

na schon fündig geworden mit dem BASCOM-Code ?

Wenn nicht, probier das mal :

Code:
$regfile = "m644def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 40
$prog &HFF , &HE2 , &HD9 , &HFE                                                 ' BODEN=1,8V, JTAG disabled, sonst Standard

Config Clock = Soft , Gosub = Sectic
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Lcd = 16 * 2 , Chipset = Dogm162v3

' Timer1, Fast-PWM (Mode 15), Prescale = 1, variable Frequenz, Tast 1:1, OC1A -> ca. 32.768Hz
Tccr1a.7 = 0                                                                    ' COM1A1
Tccr1a.6 = 1                                                                    ' COM1A0
Tccr1a.1 = 1                                                                    ' WGM11
Tccr1a.0 = 1                                                                    ' WGM10
Tccr1b.4 = 1                                                                    ' WGM13
Tccr1b.3 = 1                                                                    ' WGM12
Tccr1b.2 = 0                                                                    ' CS12
Tccr1b.1 = 0                                                                    ' CS11
Tccr1b.0 = 1                                                                    ' CS10
Ocr1ah = 0
Ocr1al = 120

Cursor Off Noblink
Cls

Config Portd.0 = Output
Portd.0 = 0                                                                     ' GND MS5534
Sclk Alias Portd.1
Config Portd.1 = Output                                                         ' SCLK MS5534
Dout Alias Pind.2
Config Pind.2 = Input                                                           ' Dout MS5534
Din Alias Portd.3
Config Portd.3 = Output                                                         ' Din MS5534
Mclk Alias Portd.5
Config Portd.5 = Output                                                         ' MCLK MS5534
Config Portd.6 = Output
Portd.6 = 1                                                                     ' VDD MS5534

Const Hoehe = 610

Const Conv_start_press = &B1111010000000000
Const Conv_start_temp = &B1111001000000000
Const Read_cali_data_1 = &B1110101010000000
Const Read_cali_data_2 = &B1110101100000000
Const Read_cali_data_3 = &B1110110010000000
Const Read_cali_data_4 = &B1110110100000000
Const Reset_sequence = &B1010101010101010

Dim V As Word                                                                   ' allgemeine Variable
Dim W As Word                                                                   ' allgemeine Variable
Dim Temp_integer As Integer
Dim Temp_word As Word
Dim Temp_single As Single
Dim S As String * 6

' Globale Variable für originale Calibration Data aus Sensor
Dim W1 As Word
Dim W2 As Word
Dim W3 As Word
Dim W4 As Word

' Globale Variablen für umgerechneten Calibration Data
Dim C1 As Word
Dim C2 As Word
Dim C3 As Word
Dim C4 As Word
Dim C5 As Word
Dim C6 As Word

' Globale Variablen für Luftdruck und Temperatur aus Sensor
Dim D1 As Word
Dim D2 As Word
Dim Ut1 As Single
Dim Dt As Single
Dim T As Single
Dim T2 As Single
Dim Offset As Single
Dim Sens As Single
Dim P As Single
Dim P2 As Single
Dim Pm(8) As Single

' Prototypen definieren
Declare Sub Read_calibration_data(byval Adress As Word , Value As Word )

Gosub Contrastset

Locate 1 , 3 : Lcd "Test MS5534"
Locate 2 , 3 : Lcd "by Knickohr"

Enable Timer1
Enable Interrupts

'Wait 1
'Cls

' Reset-Sequence
Temp_word = Reset_sequence
Shiftout Din , Sclk , Temp_word , 1 , 16 , 50
For V = 1 To 5
   Pulseout Portd , 1 , 100
   Waitus 100
Next V

' Calibration Data auslesen und auf Display ausgeben
Call Read_calibration_data(read_cali_data_1 , W1)
Call Read_calibration_data(read_cali_data_2 , W2)
Call Read_calibration_data(read_cali_data_3 , W3)
Call Read_calibration_data(read_cali_data_4 , W4)
Gosub Calc_calibration_data

'Cls

'Locate 1 , 1 : Lcd W1
'Locate 1 , 9 : Lcd W2
'Locate 2 , 1 : Lcd W3
'Locate 2 , 9 : Lcd W4

'Wait 1
'Cls

'Locate 1 , 1 : Lcd C1
'Locate 1 , 7 : Lcd C2
'Locate 1 , 12 : Lcd C3
'Locate 2 , 1 : Lcd C4
'Locate 2 , 6 : Lcd C5
'Locate 2 , 11 : Lcd C6

Wait 1
Cls

Do

   Locate 1 , 16 : Lcd "*"

   ' Pressure Measurement

   ' Reset-Sequence
   Temp_word = Reset_sequence
   Shiftout Din , Sclk , Temp_word , 1 , 16 , 50
   For V = 1 To 5
      Pulseout Portd , 1 , 100
      Waitus 100
   Next V

   ' Saubere Startbedingungen schaffen
   Reset Sclk
   Reset Din

   ' START + Adresse + STOP + 2x warten
   Temp_word = Conv_start_press
   Shiftout Din , Sclk , Temp_word , 1 , 12 , 50
   V = 0
   Do                                                                           ' Warten auf "end of conversation"
      Incr V
      If V > 50 Then Exit Do
      Waitms 1
   Loop Until Dout = 0
   If V < 50 Then                                                               ' nur wenn kein Timeout
      Shiftin Dout , Sclk , D1 , 0 , 16 , 50
      Pulseout Portd , 1 , 100
'      Locate 1 , 1 : Lcd D1
'   Else
'      Locate 1 , 1 : Lcd "Fehler Druck"
   End If

   ' Temperature Measurement

   ' Reset-Sequence
   Temp_word = Reset_sequence
   Shiftout Din , Sclk , Temp_word , 1 , 16 , 50
   For V = 1 To 5
      Pulseout Portd , 1 , 100
      Waitus 100
   Next V

   ' Saubere Startbedingungen schaffen
   Reset Sclk
   Reset Din

   ' START + Adresse + STOP + 2x warten
   Temp_word = Conv_start_temp
   Shiftout Din , Sclk , Temp_word , 1 , 12 , 50
   V = 0
   Do                                                                           ' Warten auf "end of conversation"
      Incr V
      If V > 50 Then Exit Do
      Waitms 1
   Loop Until Dout = 0
   If V < 50 Then                                                               ' nur wenn kein Timeout
      Shiftin Dout , Sclk , D2 , 0 , 16 , 50
      Pulseout Portd , 1 , 100
'      Locate 2 , 1 : Lcd D2
'   Else
'      Locate 2 , 1 : Lcd "Fehler Temp"
   End If

   ' Temperatur berechnen
   Temp_single = 8 * C5
   Ut1 = Temp_single + 20224
   Dt = D2 - Ut1
   Temp_single = C6 + 50
   Temp_single = Temp_single * Dt
   Temp_single = Temp_single / 1024
   T = 200 + Temp_single

   ' Luftdruck berechnen
   Temp_single = C4 - 512
   Temp_single = Temp_single * Dt
   Temp_single = Temp_single / 4096
   Temp_word = C2 * 4
   Offset = Temp_single + Temp_word
   Temp_single = C3 * Dt
   Temp_single = Temp_single / 1024
   Temp_single = Temp_single + 24576
   Sens = C1 + Temp_single
   Temp_single = D1 - 7168
   Temp_single = Sens * Temp_single
   Temp_single = Temp_single / 16384
   Temp_single = Temp_single - Offset
   Temp_single = Temp_single * 10
   Temp_single = Temp_single / 32
   P = Temp_single + 2500

   ' Second-Order Temperature Compensation
   Select Case T
      Case Is < 200
         Temp_single = 200 - T
         Temp_single = Temp_single ^ 2
         Temp_word = C6 + 24
         Temp_single = Temp_single * Temp_word
         Temp_single = 11 * Temp_single
         T2 = Temp_single / 1048576
         Temp_single = P - 3500
         Temp_single = Temp_single * T2
         Temp_single = Temp_single * 3
         P2 = Temp_single / 16384
      Case Is > 450
         Temp_single = 450 - T
         Temp_single = Temp_single ^ 2
         Temp_word = C6 + 24
         Temp_single = Temp_single * Temp_word
         Temp_single = 3 * Temp_single
         T2 = Temp_single / 1048576
         Temp_single = P - 10000
         Temp_single = Temp_single * T2
         P2 = Temp_single / 8192
      Case Else
         T2 = 0
         P2 = 0
   End Select
   T = T - T2
   P = P - P2

   ' Mittelwertbildung über 8 Messungen
   Select Case P                                                                ' Plausibilitätsprüfung
      Case Is < 8000
         !nop
      Case Is > 11000
         !nop
      Case Else
         For V = 1 To 7
            W = V + 1
            Pm(v) = Pm(w)
         Next V
         Pm(8) = P
         If Pm(1) <> 0 Then                                                     ' allererste 7 Messung nicht mitteln
            Temp_single = 0
            For V = 1 To 8
               Temp_single = Temp_single + Pm(v)
            Next V
            P = Temp_single / 8
         End If
   End Select

   ' Druckberechnung bezogen auf Meereshöhe
   Temp_single = T / 10
   Temp_single = Temp_single + 273.15
   Temp_single = 0.0065 / Temp_single
   Temp_single = Temp_single * Hoehe
   Temp_single = 1 - Temp_single
   Temp_single = Temp_single ^ 5.255
   P = P / Temp_single

'   Wait 1
'   Cls

'   Locate 1 , 5 : Lcd Time$
   T = T * 10                                                                   ' 0.01° Resolution
   Temp_integer = Round(t)
   S = Str(temp_integer)
   Locate 1 , 5 : Lcd Format(s , "  0.00") ; "ßC"
   Temp_integer = Round(p)
   S = Str(temp_integer)
   Locate 2 , 3 : Lcd Format(s , "    0.0") ; "mbar"
   Locate 1 , 16 : Lcd " "

   Wait 1

Loop

End

Sectic:
   !nop
   Return

Contrastset:
   V = 15
   V = V And &B00001111
   V = V + &B01110000
   W = 15
   Shift W , Right , 4
   W = W + &B01010100
   _temp1 = &B00101001
   !rCall _Lcd_control
   _temp1 = V
   !rCall _Lcd_control
   _temp1 = W
   !rCall _Lcd_control
   _temp1 = &B00101000
   !rCall _Lcd_control
   Return


Calc_calibration_data:

   ' C1 aus Word1 berechnen
   C1 = W1
   Shift C1 , Right , 1

   ' C2 aus Word3 und Word4 berechnen
   C2 = W3 And &B0000000000111111
   Shift C2 , Left , 6
   Temp_word = W4 And &B0000000000111111
   C2 = C2 + Temp_word

   ' C3 aus Word4 berechnen
   C3 = W4
   Shift C3 , Right , 6

   ' C4 aus Word3 berechnen
   C4 = W3
   Shift C4 , Right , 6

   ' C5 aus Word1 und Word2 berechnen
   C5 = W1 And &B0000000000000001
   Shift C5 , Left , 10
   Temp_word = W2
   Shift Temp_word , Right , 6
   C5 = C5 + Temp_word

   ' C6 aus Word2 berechnen
   C6 = W2 And &B0000000000111111

   Return

Sub Read_calibration_data(byval Adress As Word , Value As Word )

   ' Saubere Startbedingungen schaffen
   Reset Sclk
   Reset Din

   ' START + Adresse + STOP + 1x warten
   Shiftout Din , Sclk , Adress , 1 , 13 , 50
   Shiftin Dout , Sclk , Value , 0 , 16 , 50

   ' weiteren SCLK für sauberen Abschluß
   Pulseout Portd , 1 , 100

End Sub
Warum ich aber eigentlich hier bin : Ich habe mehrere MS5534, doch
einer tritt irgendwie aus der Reihe. Die programmierten Initialwerte
sind ganz anders, als die der anderen und auch der Druckwert stimmt
hinten und vorne nicht. Temperatur scheint zu passen. Hat schon mal
jemand einen ähnlichen Fall gehabt ? Eigentlich sollte ich Intersema
anschreiben und reklamieren. Die Sensoren sind zu teuer, um sie nur
einfach wegzuwerfen.

Thomas