Mercurial > public > hwos_code
annotate src/ms5541.asm @ 356:fcf3ae0fee6a
Changed content for new 0x6F command (Get compact headers)
author | heinrichsweikamp |
---|---|
date | Sun, 02 Aug 2015 09:52:28 +0200 |
parents | 573f2251cf49 |
children | 57e349960ef4 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File ms5541.asm | |
4 ; | |
5 ; Sensor subroutines | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-03 : [mH] moving from OSTC code | |
11 | |
275 | 12 #include "hwos.inc" ; Mandatory header |
0 | 13 #include "math.inc" ; Math routines |
14 | |
15 sensors CODE | |
16 | |
17 ;============================================================================= | |
18 ; Expose internal variables, to ease debug: | |
19 global D1, D2 | |
20 global C1, C2, C3, C4, C5, C6 | |
21 global xdT, xdT2, OFF, SENS, amb_pressure_avg, temperature_avg | |
22 | |
23 ;============================================================================= | |
24 global calculate_compensation | |
25 calculate_compensation: | |
26 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350) | |
27 movf C5+0,W ; Get Value to be subtracted | |
28 subwf D2+0,W ; Do the Low Byte | |
29 movwf xdT+0 | |
30 movf C5+1,W ; Then the high byte. | |
31 subwfb D2+1,W | |
32 movwf xdT+1 | |
33 | |
34 ; Second order temperature calculation | |
35 ; xdT/128 is in range -89..+96, hence signed 8bit. dT/128 = (2*dT)/256 | |
36 rlcf xdT+0,W ; put hit bit in carry. | |
37 rlcf xdT+1,W ; inject in high byte. | |
38 movwf isr_xA+0 ; and put result in low byte. | |
39 clrf isr_xA+1 | |
40 btfsc xdT+1,7 ; If dT < 0 | |
41 setf isr_xA+1 ; then signextend to -1 | |
42 movff isr_xA+0,isr_xB+0 ; copy A to B | |
43 movff isr_xA+1,isr_xB+1 | |
44 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits) | |
45 | |
46 ; dT >= 0: divide by 8, ie. 3 shifts rights. | |
47 ; dT < 0: divide by 2, ie. 1 shifts rights. | |
48 movlw .3 | |
49 btfss xdT+1,7 ; Was dT negative ? | |
50 movlw .1 | |
51 calc_loop_1: | |
52 bcf STATUS,C ;dT^2 is positive, so injected zeros. | |
53 rrcf isr_xC+1,F | |
54 rrcf isr_xC+0,F | |
55 decfsz WREG | |
56 bra calc_loop_1 | |
57 | |
58 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8) | |
59 subwf xdT+0,W | |
60 movwf xdT2+0 | |
61 movf isr_xC+1,W | |
62 subwfb xdT+1,W | |
63 movwf xdT2+1 | |
64 | |
65 ; Calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000 | |
66 ; (range +9.246 .. +18.887) | |
67 movff C4+0,isr_xA+0 | |
68 movff C4+1,isr_xA+1 | |
69 ; movlw LOW(-.250) ; C4 - 250 --> A | |
70 ; addwf C4+0,W | |
71 ; movwf isr_xA+0 | |
72 ; movlw -1 ; HIGH(- .250) is not understood... | |
73 ; addwfc C4+1,W | |
74 ; movwf isr_xA+1 | |
75 | |
76 movff xdT2+0,isr_xB+0 ; dT2 --> B | |
77 movff xdT2+1,isr_xB+1 | |
78 call isr_signed_mult16x16 | |
79 movlw .12-.8 ; A 12bit shift = 1 byte + 4 bits. | |
80 call isr_shift_C31 | |
81 | |
82 movlw LOW(.10000) ; Add 10000 | |
83 addwf isr_xC+1,F | |
84 movlw HIGH(.10000) | |
85 addwfc isr_xC+2,F | |
86 | |
87 movf C2+0,W ; Add C2, and save into OFF | |
88 addwf isr_xC+1,W | |
89 movwf OFF+0 | |
90 movf C2+1,W | |
91 addwfc isr_xC+2,W | |
92 movwf OFF+1 | |
93 | |
94 ; Calculate SENS = C1/2 + ((C3+200)*dT)/2^13 + 3000 | |
95 movlw LOW(.200) ; C3+200 --> A | |
96 addwf C3+0,W | |
97 movwf isr_xA+0 | |
98 movlw HIGH(.200) | |
99 addwfc C3+1,W | |
100 movwf isr_xA+1 | |
101 ; B still contains dT2 | |
102 call isr_signed_mult16x16 ; A*B --> C | |
103 movlw .13-.8 ; A 13bit shift = 1 byte + 5 bits. | |
104 call isr_shift_C31 | |
105 | |
106 bcf STATUS,C ; SENS = C1 / 2 | |
107 rrcf C1+1,W | |
108 movwf SENS+1 | |
109 rrcf C1+0,W | |
110 movwf SENS+0 | |
111 | |
112 movlw LOW(.3000) ; Add 3000 | |
113 addwf isr_xC+1,F | |
114 movlw HIGH(.3000) | |
115 addwfc isr_xC+2,F | |
116 | |
117 movf isr_xC+1,W ; And sum into SENS | |
118 addwf SENS+0,F | |
119 movf isr_xC+2,W | |
120 addwfc SENS+1,F | |
121 | |
122 ; calculate amb_pressure = (sens * (d1-off))/2^12 + 1000 | |
123 movf OFF+0,W ; d1-off --> a | |
124 subwf D1+0,W | |
125 movwf isr_xA+0 | |
126 movf OFF+1,W | |
127 subwfb D1+1,W | |
128 movwf isr_xA+1 | |
129 | |
130 movff SENS+0,isr_xB+0 ; sens --> b | |
131 movff SENS+1,isr_xB+1 | |
132 call isr_signed_mult16x16 | |
133 movlw .12-.8 ; a 12bit shift = 1 byte + 4 bits. | |
134 call isr_shift_C31 | |
135 | |
136 movlw LOW(.1000) ; add 1000 | |
137 addwf isr_xC+1,F | |
138 movlw HIGH(.1000) | |
139 addwfc isr_xC+2,F | |
140 | |
92
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
141 ; Add opt_pressure_adjust to result (SIGNED!) |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
142 movff opt_pressure_adjust,isr_xC+0 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
143 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
144 btfss isr_xC+0,7 ; <0? |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
145 bra pressure_extra_add ; No |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
146 ; Yes |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
147 comf isr_xC+0,F |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
148 incf isr_xC+0,F |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
149 ; Check for max. of 20mbar |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
150 movlw .21 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
151 cpfslt isr_xC+0 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
152 clrf isr_xC+0 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
153 ; Subtract |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
154 movf isr_xC+0,W |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
155 subwf isr_xC+1,F |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
156 movlw .0 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
157 subwfb isr_xC+2,F |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
158 bra pressure_extra_common |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
159 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
160 pressure_extra_add: |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
161 ; Check for max. of 20mbar |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
162 movlw .21 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
163 cpfslt isr_xC+0 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
164 clrf isr_xC+0 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
165 ; Add |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
166 movf isr_xC+0,W |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
167 addwf isr_xC+1,F |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
168 movlw .0 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
169 addwfc isr_xC+2,F |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
170 |
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
171 pressure_extra_common: |
178 | 172 banksel common ; flag2 is in bank 1 |
0 | 173 btfss simulatormode_active ; are we in simulator mode? |
174 bra calc_compensation_2 ; no | |
175 | |
353
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
176 banksel isr_xC+2 |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
177 movlw .5 |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
178 cpfsgt isr_xC+2 ; >1280mbar ? |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
179 bra pressure_extra_common2 ; No |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
180 ; Yes, reset sim_pressure:2 to 1000mbar (End of sim) |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
181 movlw LOW .1000 |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
182 movwf sim_pressure+0 |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
183 movlw HIGH .1000 |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
184 movwf sim_pressure+1 |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
185 |
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
186 pressure_extra_common2: |
0 | 187 movff sim_pressure+0,isr_xC+1 ; override readings with simulator values |
188 movff sim_pressure+1,isr_xC+2 | |
189 | |
190 calc_compensation_2: | |
191 banksel isr_backup | |
192 movf isr_xC+1,W ; Then sum_up to pressure averaging buffer. | |
193 addwf amb_pressure_avg+0,F | |
194 movf isr_xC+2,W | |
195 addwfc amb_pressure_avg+1,F | |
196 | |
197 ; calculate temp = 200 + dT*(C6+100)/2^11 | |
198 movlw LOW(.100) ; C6 + 100 --> A | |
199 addwf C6+0,W | |
200 movwf isr_xA+0 | |
201 movlw HIGH(.100) | |
202 addwfc C6+1,W | |
203 movwf isr_xA+1 | |
204 | |
205 movff xdT2+0,isr_xB+0 ; dT2 --> B | |
206 movff xdT2+1,isr_xB+1 | |
207 call isr_signed_mult16x16 ; A*B | |
208 movlw .11-.8 ; A 12bit shift = 1 byte + 3 bits. | |
209 call isr_shift_C31 | |
210 | |
211 movlw LOW(.200) ; Add 200 | |
212 addwf isr_xC+1,F | |
213 movlw HIGH(.200) | |
214 addwfc isr_xC+2,F | |
215 | |
216 movf isr_xC+1,W | |
217 addwf temperature_avg+0,F | |
218 movf isr_xC+2,W | |
219 addwfc temperature_avg+1,F | |
220 | |
221 return ; Done. | |
222 | |
223 ;============================================================================= | |
224 global get_pressure_start | |
225 get_pressure_start: | |
226 rcall reset_MS5541 | |
227 movlw b'10100000' ;+3*high as start and 1+low as stop! | |
228 get_pressure_start2: | |
229 movwf isr1_temp | |
230 movlw d'12' | |
231 rcall send_data_MS5541 | |
232 return | |
233 | |
234 global get_pressure_value | |
235 get_pressure_value: | |
236 btfsc MS5541_miso ; Conversion done? | |
237 return ; No, Return | |
238 rcall get_2bytes_MS5541 | |
239 movff dMSB,D1+1 | |
240 movff dLSB,D1+0 | |
241 return | |
242 | |
243 ;============================================================================= | |
244 global get_temperature_start | |
245 get_temperature_start: | |
246 rcall reset_MS5541 | |
247 movlw b'10010000' ;+3*high as start and 1+low as stop! | |
248 bra get_pressure_start2 ; continue in "get_pressure" | |
249 | |
250 global get_temperature_value | |
251 get_temperature_value: | |
252 btfsc MS5541_miso ; Conversion done? | |
253 return ; No, Return | |
254 rcall get_2bytes_MS5541 | |
255 movff dMSB,D2+1 | |
256 movff dLSB,D2+0 | |
257 return | |
258 | |
259 ;============================================================================= | |
260 global get_calibration_data | |
261 get_calibration_data: | |
262 banksel common | |
263 bsf no_sensor_int ; disable sensor interrupts | |
264 banksel isr_backup ; Back to Bank0 ISR data | |
265 | |
266 rcall reset_MS5541 | |
267 movlw b'01010100' ;+3*high as start and 1+low as stop! | |
268 movwf isr1_temp | |
269 movlw d'13' | |
270 rcall send_data_MS5541 | |
271 rcall get_2bytes_MS5541 | |
255 | 272 movff dMSB,ir_s8_buffer+1 |
273 movff dLSB,ir_s8_buffer+0 | |
0 | 274 |
275 movlw b'01011000' ;+3*high as start and 1+low as stop! | |
276 movwf isr1_temp | |
277 movlw d'13' | |
278 rcall send_data_MS5541 | |
279 rcall get_2bytes_MS5541 | |
255 | 280 movff dMSB,ir_s8_buffer+3 |
281 movff dLSB,ir_s8_buffer+2 | |
0 | 282 |
283 movlw b'01100100' ;+3*high as start and 1+low as stop! | |
284 movwf isr1_temp | |
285 movlw d'13' | |
286 rcall send_data_MS5541 | |
287 rcall get_2bytes_MS5541 | |
255 | 288 movff dMSB,ir_s8_buffer+5 |
289 movff dLSB,ir_s8_buffer+4 | |
0 | 290 |
291 movlw b'01101000' ;+3*high as start and 1+low as stop! | |
292 movwf isr1_temp | |
293 movlw d'13' | |
294 rcall send_data_MS5541 | |
295 rcall get_2bytes_MS5541 | |
255 | 296 movff dMSB,ir_s8_buffer+7 |
297 movff dLSB,ir_s8_buffer+6 | |
0 | 298 |
299 ; calculate C1 (16Bit) | |
255 | 300 movff ir_s8_buffer+1, C1+1 |
0 | 301 bcf STATUS,C |
302 rrcf C1+1 | |
303 bcf STATUS,C | |
304 rrcf C1+1 | |
305 bcf STATUS,C | |
306 rrcf C1+1 | |
255 | 307 movff ir_s8_buffer+0, C1+0 |
0 | 308 bsf STATUS,C |
255 | 309 btfss ir_s8_buffer+1,0 |
0 | 310 bcf STATUS,C |
311 rrcf C1+0 | |
312 bsf STATUS,C | |
255 | 313 btfss ir_s8_buffer+1,1 |
0 | 314 bcf STATUS,C |
315 rrcf C1+0 | |
316 bsf STATUS,C | |
255 | 317 btfss ir_s8_buffer+1,2 |
0 | 318 bcf STATUS,C |
319 rrcf C1+0 | |
320 | |
321 ; calculate C2 (16Bit) | |
255 | 322 movff ir_s8_buffer+2, C2+0 |
0 | 323 bsf STATUS,C |
255 | 324 btfss ir_s8_buffer+3,0 |
0 | 325 bcf STATUS,C |
326 rrcf C2+0 | |
327 bsf STATUS,C | |
255 | 328 btfss ir_s8_buffer+3,1 |
0 | 329 bcf STATUS,C |
330 rrcf C2+0 | |
331 bsf STATUS,C | |
255 | 332 btfss ir_s8_buffer+3,2 |
0 | 333 bcf STATUS,C |
334 rrcf C2+0 | |
335 bsf STATUS,C | |
255 | 336 btfss ir_s8_buffer+3,3 |
0 | 337 bcf STATUS,C |
338 rrcf C2+0 | |
339 bsf STATUS,C | |
255 | 340 btfss ir_s8_buffer+3,4 |
0 | 341 bcf STATUS,C |
342 rrcf C2+0 | |
343 bsf STATUS,C | |
255 | 344 btfss ir_s8_buffer+3,5 |
0 | 345 bcf STATUS,C |
346 rrcf C2+0 | |
347 | |
255 | 348 movff ir_s8_buffer+3, C2+1 |
0 | 349 bsf STATUS,C |
255 | 350 btfss ir_s8_buffer+0,0 |
0 | 351 bcf STATUS,C |
352 rrcf C2+1 | |
353 bsf STATUS,C | |
255 | 354 btfss ir_s8_buffer+0,1 |
0 | 355 bcf STATUS,C |
356 rrcf C2+1 | |
357 bsf STATUS,C | |
255 | 358 btfss ir_s8_buffer+0,2 |
0 | 359 bcf STATUS,C |
360 rrcf C2+1 | |
361 bcf STATUS,C | |
362 rrcf C2+1 | |
363 bcf STATUS,C | |
364 rrcf C2+1 | |
365 bcf STATUS,C | |
366 rrcf C2+1 | |
367 | |
368 ; calculate C3 (16Bit) | |
255 | 369 movff ir_s8_buffer+5,C3+0 |
0 | 370 bsf STATUS,C |
255 | 371 btfss ir_s8_buffer+4,7 |
0 | 372 bcf STATUS,C |
373 rlcf C3+0 | |
374 bsf STATUS,C | |
255 | 375 btfss ir_s8_buffer+4,6 |
0 | 376 bcf STATUS,C |
377 rlcf C3+0 | |
378 clrf C3+1 | |
255 | 379 btfsc ir_s8_buffer+5,7 |
0 | 380 bsf C3+1,1 |
255 | 381 btfsc ir_s8_buffer+5,6 |
0 | 382 bsf C3+1,0 |
383 | |
384 ; calculate C4 (16Bit) | |
255 | 385 movff ir_s8_buffer+7,C4+0 |
0 | 386 bsf STATUS,C |
255 | 387 btfss ir_s8_buffer+6,7 |
0 | 388 bcf STATUS,C |
389 rlcf C4+0 | |
390 clrf C4+1 | |
255 | 391 btfsc ir_s8_buffer+7,7 |
0 | 392 bsf C4+1,0 |
393 | |
394 ; C4=C4-250 | |
395 movlw LOW(-.250) ; C4 - 250 --> C4 | |
396 addwf C4+0,W | |
397 movwf C4+0 | |
398 movlw -1 ; HIGH(- .250) is not understood... | |
399 addwfc C4+1,W | |
400 movwf C4+1 | |
401 | |
402 ; calculate C5 (16Bit) | |
255 | 403 movff ir_s8_buffer+4,C5+0 |
0 | 404 bcf C5+0,6 |
255 | 405 btfsc ir_s8_buffer+2,0 |
0 | 406 bsf C5+0,6 |
407 bcf C5+0,7 | |
255 | 408 btfsc ir_s8_buffer+2,1 |
0 | 409 bsf C5+0,7 |
410 clrf C5+1 | |
255 | 411 btfsc ir_s8_buffer+2,2 |
0 | 412 bsf C5+1,0 |
255 | 413 btfsc ir_s8_buffer+2,3 |
0 | 414 bsf C5+1,1 |
255 | 415 btfsc ir_s8_buffer+2,4 |
0 | 416 bsf C5+1,2 |
255 | 417 btfsc ir_s8_buffer+2,5 |
0 | 418 bsf C5+1,3 |
419 | |
420 ; calculate C5 = UT1 | |
421 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760) | |
422 clrf isr_xA+1 | |
423 movlw d'8' | |
424 movwf isr_xA+0 | |
425 movff C5+0,isr_xB+0 | |
426 movff C5+1,isr_xB+1 | |
427 call isr_unsigned_mult16x16 ;isr_xA*isr_xB=isr_xC | |
428 movff isr_xC+0,C5+0 | |
429 movff isr_xC+1,C5+1 | |
430 movlw LOW d'10000' | |
431 addwf C5+0,F | |
432 movlw HIGH d'10000' | |
433 addwfc C5+1,F ; = 8*C5 + 10000 | |
434 | |
435 ; calculate C6 (16Bit) | |
436 clrf C6+1 | |
255 | 437 movff ir_s8_buffer+6,C6+0 |
0 | 438 bcf C6+0,7 |
439 | |
440 banksel common | |
441 bcf no_sensor_int ; enable sensor interrupts | |
442 bcf pressure_refresh ; Clear flag | |
443 banksel isr_backup ; Back to Bank0 ISR data | |
444 | |
445 clrf sensor_state_counter ; Then reset State counter | |
446 | |
447 return | |
448 | |
449 ;============================================================================= | |
450 reset_MS5541_one: | |
451 bsf MS5541_mosi | |
452 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return | |
453 | |
454 reset_MS5541_zero: | |
455 bcf MS5541_mosi | |
456 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return | |
457 | |
458 reset_MS5541: | |
459 rcall reset_MS5541_one ;0 | |
460 rcall reset_MS5541_zero | |
461 rcall reset_MS5541_one | |
462 rcall reset_MS5541_zero | |
463 rcall reset_MS5541_one | |
464 rcall reset_MS5541_zero | |
465 rcall reset_MS5541_one | |
466 rcall reset_MS5541_zero | |
467 rcall reset_MS5541_one | |
468 rcall reset_MS5541_zero | |
469 rcall reset_MS5541_one | |
470 rcall reset_MS5541_zero | |
471 rcall reset_MS5541_one | |
472 rcall reset_MS5541_zero | |
473 rcall reset_MS5541_one | |
474 rcall reset_MS5541_zero ;15 | |
475 rcall reset_MS5541_zero | |
476 rcall reset_MS5541_zero | |
477 rcall reset_MS5541_zero | |
478 rcall reset_MS5541_zero | |
479 rcall reset_MS5541_zero ;20 | |
480 return | |
481 | |
482 get_2bytes_MS5541: | |
483 movlw d'8' | |
484 movwf clock_count | |
485 rcall recieve_loop | |
486 movff isr1_temp,dMSB | |
487 | |
488 movlw d'8' | |
489 movwf clock_count | |
490 rcall recieve_loop | |
491 movff isr1_temp,dLSB | |
492 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return | |
493 ;return | |
494 | |
495 recieve_loop: | |
496 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk | |
497 btfss MS5541_miso ;MSB first | |
498 bcf STATUS,C | |
499 btfsc MS5541_miso ;MSB first | |
500 bsf STATUS,C | |
501 rlcf isr1_temp,F | |
502 decfsz clock_count,F | |
503 bra recieve_loop | |
504 return | |
505 | |
506 send_clk_pulse: | |
507 bsf MS5541_clk | |
508 nop | |
509 nop | |
510 nop | |
511 nop | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
512 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
513 nop |
0 | 514 bcf MS5541_clk |
515 nop | |
516 nop | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
517 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
518 nop |
0 | 519 return |
520 | |
521 send_data_MS5541: | |
522 movwf clock_count ; From WREG | |
523 ; send three startbits first | |
524 bcf MS5541_clk | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
525 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
526 nop |
0 | 527 bsf MS5541_mosi |
528 movlw d'3' | |
529 subwf clock_count,F ; total bit counter | |
530 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk | |
531 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk | |
532 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk | |
533 ; now send 8 bytes from isr_temp1 and fill-up with zeros | |
534 send_data_MS5541_2: | |
535 bcf MS5541_clk | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
536 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
537 nop |
0 | 538 |
539 btfss isr1_temp,7 ;MSB first | |
540 bcf MS5541_mosi | |
541 btfsc isr1_temp,7 ;MSB first | |
542 bsf MS5541_mosi | |
543 | |
544 bsf MS5541_clk | |
545 | |
546 bcf STATUS,C | |
547 rlcf isr1_temp,F | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
548 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
549 nop |
0 | 550 ; nop |
551 ; nop | |
552 ; nop | |
553 ; nop | |
554 ; bcf MS5541_clk | |
555 | |
556 decfsz clock_count,F | |
557 bra send_data_MS5541_2 | |
558 bcf MS5541_clk | |
559 return | |
560 | |
561 END |