1 | $regfile = "m644def.dat"
|
2 | $crystal = 8000000
|
3 | $hwstack = 32
|
4 | $swstack = 32
|
5 | $framesize = 40
|
6 | $prog &HFF , &HE2 , &HD9 , &HFE ' BODEN=1,8V, JTAG disabled, sonst Standard
|
7 |
|
8 | Config Clock = Soft , Gosub = Sectic
|
9 | Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
|
10 | Config Lcd = 16 * 2 , Chipset = Dogm162v3
|
11 |
|
12 | ' Timer1, Fast-PWM (Mode 15), Prescale = 1, variable Frequenz, Tast 1:1, OC1A -> ca. 32.768Hz
|
13 | Tccr1a.7 = 0 ' COM1A1
|
14 | Tccr1a.6 = 1 ' COM1A0
|
15 | Tccr1a.1 = 1 ' WGM11
|
16 | Tccr1a.0 = 1 ' WGM10
|
17 | Tccr1b.4 = 1 ' WGM13
|
18 | Tccr1b.3 = 1 ' WGM12
|
19 | Tccr1b.2 = 0 ' CS12
|
20 | Tccr1b.1 = 0 ' CS11
|
21 | Tccr1b.0 = 1 ' CS10
|
22 | Ocr1ah = 0
|
23 | Ocr1al = 120
|
24 |
|
25 | Cursor Off Noblink
|
26 | Cls
|
27 |
|
28 | Config Portd.0 = Output
|
29 | Portd.0 = 0 ' GND MS5534
|
30 | Sclk Alias Portd.1
|
31 | Config Portd.1 = Output ' SCLK MS5534
|
32 | Dout Alias Pind.2
|
33 | Config Pind.2 = Input ' Dout MS5534
|
34 | Din Alias Portd.3
|
35 | Config Portd.3 = Output ' Din MS5534
|
36 | Mclk Alias Portd.5
|
37 | Config Portd.5 = Output ' MCLK MS5534
|
38 | Config Portd.6 = Output
|
39 | Portd.6 = 1 ' VDD MS5534
|
40 |
|
41 | Const Hoehe = 610
|
42 |
|
43 | Const Conv_start_press = &B1111010000000000
|
44 | Const Conv_start_temp = &B1111001000000000
|
45 | Const Read_cali_data_1 = &B1110101010000000
|
46 | Const Read_cali_data_2 = &B1110101100000000
|
47 | Const Read_cali_data_3 = &B1110110010000000
|
48 | Const Read_cali_data_4 = &B1110110100000000
|
49 | Const Reset_sequence = &B1010101010101010
|
50 |
|
51 | Dim V As Word ' allgemeine Variable
|
52 | Dim W As Word ' allgemeine Variable
|
53 | Dim Temp_integer As Integer
|
54 | Dim Temp_word As Word
|
55 | Dim Temp_single As Single
|
56 | Dim S As String * 6
|
57 |
|
58 | ' Globale Variable für originale Calibration Data aus Sensor
|
59 | Dim W1 As Word
|
60 | Dim W2 As Word
|
61 | Dim W3 As Word
|
62 | Dim W4 As Word
|
63 |
|
64 | ' Globale Variablen für umgerechneten Calibration Data
|
65 | Dim C1 As Word
|
66 | Dim C2 As Word
|
67 | Dim C3 As Word
|
68 | Dim C4 As Word
|
69 | Dim C5 As Word
|
70 | Dim C6 As Word
|
71 |
|
72 | ' Globale Variablen für Luftdruck und Temperatur aus Sensor
|
73 | Dim D1 As Word
|
74 | Dim D2 As Word
|
75 | Dim Ut1 As Single
|
76 | Dim Dt As Single
|
77 | Dim T As Single
|
78 | Dim T2 As Single
|
79 | Dim Offset As Single
|
80 | Dim Sens As Single
|
81 | Dim P As Single
|
82 | Dim P2 As Single
|
83 | Dim Pm(8) As Single
|
84 |
|
85 | ' Prototypen definieren
|
86 | Declare Sub Read_calibration_data(byval Adress As Word , Value As Word )
|
87 |
|
88 | Gosub Contrastset
|
89 |
|
90 | Locate 1 , 3 : Lcd "Test MS5534"
|
91 | Locate 2 , 3 : Lcd "by Knickohr"
|
92 |
|
93 | Enable Timer1
|
94 | Enable Interrupts
|
95 |
|
96 | 'Wait 1
|
97 | 'Cls
|
98 |
|
99 | ' Reset-Sequence
|
100 | Temp_word = Reset_sequence
|
101 | Shiftout Din , Sclk , Temp_word , 1 , 16 , 50
|
102 | For V = 1 To 5
|
103 | Pulseout Portd , 1 , 100
|
104 | Waitus 100
|
105 | Next V
|
106 |
|
107 | ' Calibration Data auslesen und auf Display ausgeben
|
108 | Call Read_calibration_data(read_cali_data_1 , W1)
|
109 | Call Read_calibration_data(read_cali_data_2 , W2)
|
110 | Call Read_calibration_data(read_cali_data_3 , W3)
|
111 | Call Read_calibration_data(read_cali_data_4 , W4)
|
112 | Gosub Calc_calibration_data
|
113 |
|
114 | 'Cls
|
115 |
|
116 | 'Locate 1 , 1 : Lcd W1
|
117 | 'Locate 1 , 9 : Lcd W2
|
118 | 'Locate 2 , 1 : Lcd W3
|
119 | 'Locate 2 , 9 : Lcd W4
|
120 |
|
121 | 'Wait 1
|
122 | 'Cls
|
123 |
|
124 | 'Locate 1 , 1 : Lcd C1
|
125 | 'Locate 1 , 7 : Lcd C2
|
126 | 'Locate 1 , 12 : Lcd C3
|
127 | 'Locate 2 , 1 : Lcd C4
|
128 | 'Locate 2 , 6 : Lcd C5
|
129 | 'Locate 2 , 11 : Lcd C6
|
130 |
|
131 | Wait 1
|
132 | Cls
|
133 |
|
134 | Do
|
135 |
|
136 | Locate 1 , 16 : Lcd "*"
|
137 |
|
138 | ' Pressure Measurement
|
139 |
|
140 | ' Reset-Sequence
|
141 | Temp_word = Reset_sequence
|
142 | Shiftout Din , Sclk , Temp_word , 1 , 16 , 50
|
143 | For V = 1 To 5
|
144 | Pulseout Portd , 1 , 100
|
145 | Waitus 100
|
146 | Next V
|
147 |
|
148 | ' Saubere Startbedingungen schaffen
|
149 | Reset Sclk
|
150 | Reset Din
|
151 |
|
152 | ' START + Adresse + STOP + 2x warten
|
153 | Temp_word = Conv_start_press
|
154 | Shiftout Din , Sclk , Temp_word , 1 , 12 , 50
|
155 | V = 0
|
156 | Do ' Warten auf "end of conversation"
|
157 | Incr V
|
158 | If V > 50 Then Exit Do
|
159 | Waitms 1
|
160 | Loop Until Dout = 0
|
161 | If V < 50 Then ' nur wenn kein Timeout
|
162 | Shiftin Dout , Sclk , D1 , 0 , 16 , 50
|
163 | Pulseout Portd , 1 , 100
|
164 | ' Locate 1 , 1 : Lcd D1
|
165 | ' Else
|
166 | ' Locate 1 , 1 : Lcd "Fehler Druck"
|
167 | End If
|
168 |
|
169 | ' Temperature Measurement
|
170 |
|
171 | ' Reset-Sequence
|
172 | Temp_word = Reset_sequence
|
173 | Shiftout Din , Sclk , Temp_word , 1 , 16 , 50
|
174 | For V = 1 To 5
|
175 | Pulseout Portd , 1 , 100
|
176 | Waitus 100
|
177 | Next V
|
178 |
|
179 | ' Saubere Startbedingungen schaffen
|
180 | Reset Sclk
|
181 | Reset Din
|
182 |
|
183 | ' START + Adresse + STOP + 2x warten
|
184 | Temp_word = Conv_start_temp
|
185 | Shiftout Din , Sclk , Temp_word , 1 , 12 , 50
|
186 | V = 0
|
187 | Do ' Warten auf "end of conversation"
|
188 | Incr V
|
189 | If V > 50 Then Exit Do
|
190 | Waitms 1
|
191 | Loop Until Dout = 0
|
192 | If V < 50 Then ' nur wenn kein Timeout
|
193 | Shiftin Dout , Sclk , D2 , 0 , 16 , 50
|
194 | Pulseout Portd , 1 , 100
|
195 | ' Locate 2 , 1 : Lcd D2
|
196 | ' Else
|
197 | ' Locate 2 , 1 : Lcd "Fehler Temp"
|
198 | End If
|
199 |
|
200 | ' Temperatur berechnen
|
201 | Temp_single = 8 * C5
|
202 | Ut1 = Temp_single + 20224
|
203 | Dt = D2 - Ut1
|
204 | Temp_single = C6 + 50
|
205 | Temp_single = Temp_single * Dt
|
206 | Temp_single = Temp_single / 1024
|
207 | T = 200 + Temp_single
|
208 |
|
209 | ' Luftdruck berechnen
|
210 | Temp_single = C4 - 512
|
211 | Temp_single = Temp_single * Dt
|
212 | Temp_single = Temp_single / 4096
|
213 | Temp_word = C2 * 4
|
214 | Offset = Temp_single + Temp_word
|
215 | Temp_single = C3 * Dt
|
216 | Temp_single = Temp_single / 1024
|
217 | Temp_single = Temp_single + 24576
|
218 | Sens = C1 + Temp_single
|
219 | Temp_single = D1 - 7168
|
220 | Temp_single = Sens * Temp_single
|
221 | Temp_single = Temp_single / 16384
|
222 | Temp_single = Temp_single - Offset
|
223 | Temp_single = Temp_single * 10
|
224 | Temp_single = Temp_single / 32
|
225 | P = Temp_single + 2500
|
226 |
|
227 | ' Second-Order Temperature Compensation
|
228 | Select Case T
|
229 | Case Is < 200
|
230 | Temp_single = 200 - T
|
231 | Temp_single = Temp_single ^ 2
|
232 | Temp_word = C6 + 24
|
233 | Temp_single = Temp_single * Temp_word
|
234 | Temp_single = 11 * Temp_single
|
235 | T2 = Temp_single / 1048576
|
236 | Temp_single = P - 3500
|
237 | Temp_single = Temp_single * T2
|
238 | Temp_single = Temp_single * 3
|
239 | P2 = Temp_single / 16384
|
240 | Case Is > 450
|
241 | Temp_single = 450 - T
|
242 | Temp_single = Temp_single ^ 2
|
243 | Temp_word = C6 + 24
|
244 | Temp_single = Temp_single * Temp_word
|
245 | Temp_single = 3 * Temp_single
|
246 | T2 = Temp_single / 1048576
|
247 | Temp_single = P - 10000
|
248 | Temp_single = Temp_single * T2
|
249 | P2 = Temp_single / 8192
|
250 | Case Else
|
251 | T2 = 0
|
252 | P2 = 0
|
253 | End Select
|
254 | T = T - T2
|
255 | P = P - P2
|
256 |
|
257 | ' Mittelwertbildung über 8 Messungen
|
258 | Select Case P ' Plausibilitätsprüfung
|
259 | Case Is < 8000
|
260 | !nop
|
261 | Case Is > 11000
|
262 | !nop
|
263 | Case Else
|
264 | For V = 1 To 7
|
265 | W = V + 1
|
266 | Pm(v) = Pm(w)
|
267 | Next V
|
268 | Pm(8) = P
|
269 | If Pm(1) <> 0 Then ' allererste 7 Messung nicht mitteln
|
270 | Temp_single = 0
|
271 | For V = 1 To 8
|
272 | Temp_single = Temp_single + Pm(v)
|
273 | Next V
|
274 | P = Temp_single / 8
|
275 | End If
|
276 | End Select
|
277 |
|
278 | ' Druckberechnung bezogen auf Meereshöhe
|
279 | Temp_single = T / 10
|
280 | Temp_single = Temp_single + 273.15
|
281 | Temp_single = 0.0065 / Temp_single
|
282 | Temp_single = Temp_single * Hoehe
|
283 | Temp_single = 1 - Temp_single
|
284 | Temp_single = Temp_single ^ 5.255
|
285 | P = P / Temp_single
|
286 |
|
287 | ' Wait 1
|
288 | ' Cls
|
289 |
|
290 | ' Locate 1 , 5 : Lcd Time$
|
291 | T = T * 10 ' 0.01° Resolution
|
292 | Temp_integer = Round(t)
|
293 | S = Str(temp_integer)
|
294 | Locate 1 , 5 : Lcd Format(s , " 0.00") ; "ßC"
|
295 | Temp_integer = Round(p)
|
296 | S = Str(temp_integer)
|
297 | Locate 2 , 3 : Lcd Format(s , " 0.0") ; "mbar"
|
298 | Locate 1 , 16 : Lcd " "
|
299 |
|
300 | Wait 1
|
301 |
|
302 | Loop
|
303 |
|
304 | End
|
305 |
|
306 | Sectic:
|
307 | !nop
|
308 | Return
|
309 |
|
310 | Contrastset:
|
311 | V = 15
|
312 | V = V And &B00001111
|
313 | V = V + &B01110000
|
314 | W = 15
|
315 | Shift W , Right , 4
|
316 | W = W + &B01010100
|
317 | _temp1 = &B00101001
|
318 | !rCall _Lcd_control
|
319 | _temp1 = V
|
320 | !rCall _Lcd_control
|
321 | _temp1 = W
|
322 | !rCall _Lcd_control
|
323 | _temp1 = &B00101000
|
324 | !rCall _Lcd_control
|
325 | Return
|
326 |
|
327 |
|
328 | Calc_calibration_data:
|
329 |
|
330 | ' C1 aus Word1 berechnen
|
331 | C1 = W1
|
332 | Shift C1 , Right , 1
|
333 |
|
334 | ' C2 aus Word3 und Word4 berechnen
|
335 | C2 = W3 And &B0000000000111111
|
336 | Shift C2 , Left , 6
|
337 | Temp_word = W4 And &B0000000000111111
|
338 | C2 = C2 + Temp_word
|
339 |
|
340 | ' C3 aus Word4 berechnen
|
341 | C3 = W4
|
342 | Shift C3 , Right , 6
|
343 |
|
344 | ' C4 aus Word3 berechnen
|
345 | C4 = W3
|
346 | Shift C4 , Right , 6
|
347 |
|
348 | ' C5 aus Word1 und Word2 berechnen
|
349 | C5 = W1 And &B0000000000000001
|
350 | Shift C5 , Left , 10
|
351 | Temp_word = W2
|
352 | Shift Temp_word , Right , 6
|
353 | C5 = C5 + Temp_word
|
354 |
|
355 | ' C6 aus Word2 berechnen
|
356 | C6 = W2 And &B0000000000111111
|
357 |
|
358 | Return
|
359 |
|
360 | Sub Read_calibration_data(byval Adress As Word , Value As Word )
|
361 |
|
362 | ' Saubere Startbedingungen schaffen
|
363 | Reset Sclk
|
364 | Reset Din
|
365 |
|
366 | ' START + Adresse + STOP + 1x warten
|
367 | Shiftout Din , Sclk , Adress , 1 , 13 , 50
|
368 | Shiftin Dout , Sclk , Value , 0 , 16 , 50
|
369 |
|
370 | ' weiteren SCLK für sauberen Abschluß
|
371 | Pulseout Portd , 1 , 100
|
372 |
|
373 | End Sub
|