Der Code für den Drucksensor (noch nicht getestet), von http://www.kh-gps.de/
Code:'BMP085_8_lcd2a_t 86% belegt OK am 25.3.2010 '############################################################################### $regfile = "m8def.dat" $crystal = 8000000 $baud = 9600 $hwstack = 64 $swstack = 64 $framesize = 64 $sim '############################################################################### 'Byte = 0 to 255 'Word = 0 to 65535 'Integer = -32768 to 32767 'Long = -214783648 to 2147483647 'Single = 1.5 x 10^-45 to 3.4 x 10^38 'Double = 5.0 x 10^-324 to 1.7 x 10^38 Dim Ac1 As Single Dim Ac2 As Single Dim Ac3 As Single Dim Ac4 As Long Dim Ac5 As Long Dim Ac6 As Long Dim B1 As Single Dim B2 As Single Dim B3 As Long Dim B4 As Long Dim B4a As Single Dim B5 As Single Dim B6 As Single Dim B7 As Long Dim Mb As Single Dim Mc As Single Dim Md As Single Dim Ut As Long Dim Up As Long Dim X1 As Single Dim X2 As Single Dim X3 As Single Dim Zwr1 As Single Dim Zwr2 As Single Dim Zwr3 As Single Dim Zwr4 As Single Dim T As Single Dim T_str As String * 4 Dim P As Single Dim P2 As Single Dim Po As Single Dim A As Single Dim A2 As Word Dim Adres As Byte Dim Value As Byte Dim Result As Integer Dim Hi As Long Dim Lo As Long Dim Xlo As Long Config Scl = Portb.1 Config Sda = Portb.0 I2cinit Config Portb.6 = Output Config Portb.7 = Output Portb = &B11000000 Dim N As Byte N = 1 Do Portb.6 = 1 Portb.7 = 0 Waitms 50 Portb.6 = 0 Portb.7 = 1 Waitms 50 N = N + 1 Loop Until N = 20 Declare Sub Write_bmp(byval Adres As Byte , Byval Value As Byte) Declare Sub Read_bmp(byval Adres As Byte , Value As Byte) Declare Sub Read_reg Const Addressw = &B11101110 'slave write address Const Addressr = &B11101111 'slave read address Config Lcd = 16 * 2 Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0 Cls Cursor Off Locate 1 , 1 Lcd " BMP085-DECODER " Locate 2 , 1 Lcd "(C)2010 KHH V1.2" Wait 3 'hole Kalibrierungsdaten '------------------------------------------------------------------------------- Adres = &HAA 'Startadresse calibration data 'Do Waitms 50 Call Read_reg Ac1 = Result 'Print "AC1= " ; Ac1 Call Read_reg Ac2 = Result 'Print "AC2= " ; Ac2 Call Read_reg Ac3 = Result 'Print "AC3= " ; Ac3 Call Read_reg Ac4 = Result 'Print "AC4= " ; Ac4 Call Read_reg Ac5 = Result 'Print "AC5= " ; Ac5 Call Read_reg Ac6 = Result 'Print "AC6= " ; Ac6 Call Read_reg B1 = Result 'Print "B1= " ; B1 Call Read_reg B2 = Result 'Print "B2= " ; B2 Call Read_reg Mb = Result 'Print "MB= " ; Mb Call Read_reg Mc = Result 'Print "MC= " ; Mc Call Read_reg Md = Result 'Print "MD= " ; Md 'Print Dim Xx As Byte Xx = 1 Do Waitms 100 'hole Rohdaten Temperatur '------------------------------------------------------------------------------- Call Write_bmp(&Hf4 , &H2E) Waitms 5 Call Read_bmp(&Hf6 , Value) 'read it back Hi = Value * 256 Call Read_bmp(&Hf7 , Value) 'read it back Ut = Hi + Value 'Print "UT= " ; Ut 'Print Waitms 100 'hole Rohdaten Luftdruck '------------------------------------------------------------------------------- Call Write_bmp(&Hf4 , &H34) Waitms 40 Call Read_bmp(&Hf6 , Value) 'read it back Hi = Value * 256 Call Read_bmp(&Hf7 , Value) 'read it back Up = Hi + Value 'Print "UP= " ; Up 'Print 'Testwerte '------------------------------------------------------ Ac1 = 408 Ac2 = -72 Ac3 = -14383 Ac4 = 32741 Ac5 = 32757 Ac6 = 23153 B1 = 6190 B2 = 4 Mb = -32768 Mc = -8711 Md = 2868 Ut = 27898 'Temperatur Up = 23843 'Pressure 'kalkuliere tatsaechliche Temperatur '------------------------------------------------------------------------------- Zwr1 = Ut - Ac6 Zwr2 = 2 ^ 15 Zwr2 = Ac5 / Zwr2 X1 = Zwr1 * Zwr2 Print "X1= " ; X1 Zwr1 = 2 ^ 11 Zwr2 = Mc * Zwr1 Zwr3 = X1 + Md X2 = Zwr2 / Zwr3 Print "X2= " ; X2 B5 = X1 + X2 Print "B5= " ; B5 T = B5 + 8 Zwr3 = 2 ^ 4 T = T / Zwr3 T = T / 10 T_str = Str(t) T_str = Left(t_str , 4) Print "T= " ; T_str ; " C" Print 'kalkuliere tatsaechlichen Luftdruck '------------------------------------------------------------------------------- B6 = B5 - 4000 Print "B6= " ; B6 Zwr1 = 2 ^ 11 Zwr2 = 2 ^ 12 Zwr3 = B6 / Zwr2 Zwr3 = B6 * Zwr3 Zwr4 = B2 * Zwr3 X1 = Zwr4 / Zwr1 Print "X1= " ; X1 Zwr1 = 2 ^ 11 Zwr2 = B6 / Zwr1 X2 = Ac2 * Zwr2 Print "X2= " ; X2 X3 = X1 + X2 Print "X3= " ; X3 Zwr1 = Ac1 * 4 Zwr1 = Zwr1 + X3 Zwr1 = Zwr1 + 2 If Xx = 1 Then B3 = Zwr1 * 4 '681 If Xx = 2 Then B3 = Zwr1 * 2 '1006 If Xx = 3 Then B3 = Zwr1 '142 If Xx = 4 Then B3 = Zwr1 / 2 '720 If Xx = 5 Then B3 = Zwr1 / 4 '1010(orig) Print "B3= " ; B3 Zwr1 = 2 ^ 13 Zwr2 = B6 / Zwr1 X1 = Ac3 * Zwr2 'Print X1 'X1 = Abs(x1) Print "X1= " ; X1 Zwr1 = 2 ^ 12 Zwr2 = 2 ^ 16 Zwr3 = B6 / Zwr1 Zwr3 = B6 * Zwr3 Zwr4 = B1 * Zwr3 X2 = Zwr4 / Zwr2 Print "X2= " ; X2 X3 = X1 + X2 X3 = X3 + 2 X3 = X3 / 4 Print "X3= " ; X3 Zwr1 = X3 + 32768 Zwr2 = 2 ^ 15 Zwr3 = Zwr1 / Zwr2 'Print "Zwr3= " ; Zwr3 'Print "Ac4 = " ; Ac4 B4a = Ac4 * Zwr3 B4 = Abs(b4a) Print "B4= " ; B4a B7 = Up - B3 Dim B7a As Long B7a = B7 * 50000 Print "B7= " ; B7a Zwr1 = B7a * 2 Zwr1 = Zwr1 / B4 Zwr2 = B7a / B4 Zwr2 = Zwr2 * 2 If B7a < &H8000000 Then P = Zwr1 Else P = Zwr2 Print "P= " ; P Zwr1 = 2 ^ 8 Zwr2 = P / Zwr1 X1 = Zwr2 * Zwr2 Print "X1= " ; X1 Zwr1 = 2 ^ 16 X1 = X1 * 3028 X1 = X1 / Zwr1 X1 = Abs(x1) Print "X1= " ; X1 Zwr1 = -7357 * P Zwr2 = 2 ^ 16 X2 = Zwr1 / Zwr2 Print "X2= " ; X2 Print Zwr1 = X1 + X2 Zwr1 = Zwr1 + 3791 Zwr2 = 2 ^ 4 Zwr1 = Zwr1 / Zwr2 P = P + Zwr1 Print "P= " ; P ; "Pa" P = P / 100 Print "XX= " ; Xx Dim P_str As String * 8 P_str = Fusing(p , "#.##") Print "P= " ; P_str ; "hPa" 'kalkuliere Hoehenwerte '------------------------------------------------------------------------------- Po = 1013.25 'Pressure auf Seepegel Zwr1 = 1 / 5.255 Zwr2 = P / Po Zwr3 = Zwr2 ^ Zwr1 Zwr4 = 1 - Zwr3 A = 44330 * Zwr4 A2 = Int(a) Print "A= " ; A2 ; "m" Print 'LCD-Ausgabe '------------------------------------------------------------------------------- Cls Locate 1 , 7 Lcd P_str ; "hPa" Locate 1 , 1 Lcd Up Locate 2 , 1 Lcd A2 ; "m" Locate 2 , 11 Lcd T_str ; Chr(223) ; "C" 'Wait 2 Xx = Xx + 1 If Xx = 6 Then Xx = 1 Loop End '------------------------------------------------------------ Sub Read_reg Call Read_bmp(adres , Value) Hi = Value * 256 Adres = Adres + 1 Call Read_bmp(adres , Value) Result = Hi + Value Adres = Adres + 1 End Sub '---------------------------------------------------------- Sub Write_bmp(byval Adres As Byte , Byval Value As Byte) I2cstart 'start condition I2cwbyte Addressw 'slave address I2cwbyte Adres 'address of register I2cwbyte Value 'value to write I2cstop 'stop condition Waitms 10 'wait for 10 milliseconds End Sub '---------------------------------------------------------- Sub Read_bmp(byval Adres As Byte , Value As Byte) I2cstart 'generate start I2cwbyte Addressw 'slave address I2cwbyte Adres 'address of register I2cstart 'repeated start I2cwbyte Addressr 'slave address (read) I2crbyte Value , Nack 'read byte I2cstop 'generate stop Waitms 10 End Sub







Zitieren


Lesezeichen