Mercurial > public > hwos_code
annotate src/ms5541.asm @ 276:e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
author | heinrichsweikamp |
---|---|
date | Tue, 12 May 2015 14:24:46 +0200 |
parents | 653a3ab08062 |
children | 573f2251cf49 |
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 | |
176 movff sim_pressure+0,isr_xC+1 ; override readings with simulator values | |
177 movff sim_pressure+1,isr_xC+2 | |
178 | |
179 calc_compensation_2: | |
180 banksel isr_backup | |
181 movf isr_xC+1,W ; Then sum_up to pressure averaging buffer. | |
182 addwf amb_pressure_avg+0,F | |
183 movf isr_xC+2,W | |
184 addwfc amb_pressure_avg+1,F | |
185 | |
186 ; calculate temp = 200 + dT*(C6+100)/2^11 | |
187 movlw LOW(.100) ; C6 + 100 --> A | |
188 addwf C6+0,W | |
189 movwf isr_xA+0 | |
190 movlw HIGH(.100) | |
191 addwfc C6+1,W | |
192 movwf isr_xA+1 | |
193 | |
194 movff xdT2+0,isr_xB+0 ; dT2 --> B | |
195 movff xdT2+1,isr_xB+1 | |
196 call isr_signed_mult16x16 ; A*B | |
197 movlw .11-.8 ; A 12bit shift = 1 byte + 3 bits. | |
198 call isr_shift_C31 | |
199 | |
200 movlw LOW(.200) ; Add 200 | |
201 addwf isr_xC+1,F | |
202 movlw HIGH(.200) | |
203 addwfc isr_xC+2,F | |
204 | |
205 movf isr_xC+1,W | |
206 addwf temperature_avg+0,F | |
207 movf isr_xC+2,W | |
208 addwfc temperature_avg+1,F | |
209 | |
210 return ; Done. | |
211 | |
212 ;============================================================================= | |
213 global get_pressure_start | |
214 get_pressure_start: | |
215 rcall reset_MS5541 | |
216 movlw b'10100000' ;+3*high as start and 1+low as stop! | |
217 get_pressure_start2: | |
218 movwf isr1_temp | |
219 movlw d'12' | |
220 rcall send_data_MS5541 | |
221 return | |
222 | |
223 global get_pressure_value | |
224 get_pressure_value: | |
225 btfsc MS5541_miso ; Conversion done? | |
226 return ; No, Return | |
227 rcall get_2bytes_MS5541 | |
228 movff dMSB,D1+1 | |
229 movff dLSB,D1+0 | |
230 return | |
231 | |
232 ;============================================================================= | |
233 global get_temperature_start | |
234 get_temperature_start: | |
235 rcall reset_MS5541 | |
236 movlw b'10010000' ;+3*high as start and 1+low as stop! | |
237 bra get_pressure_start2 ; continue in "get_pressure" | |
238 | |
239 global get_temperature_value | |
240 get_temperature_value: | |
241 btfsc MS5541_miso ; Conversion done? | |
242 return ; No, Return | |
243 rcall get_2bytes_MS5541 | |
244 movff dMSB,D2+1 | |
245 movff dLSB,D2+0 | |
246 return | |
247 | |
248 ;============================================================================= | |
249 global get_calibration_data | |
250 get_calibration_data: | |
251 banksel common | |
252 bsf no_sensor_int ; disable sensor interrupts | |
253 banksel isr_backup ; Back to Bank0 ISR data | |
254 | |
255 rcall reset_MS5541 | |
256 movlw b'01010100' ;+3*high as start and 1+low as stop! | |
257 movwf isr1_temp | |
258 movlw d'13' | |
259 rcall send_data_MS5541 | |
260 rcall get_2bytes_MS5541 | |
255 | 261 movff dMSB,ir_s8_buffer+1 |
262 movff dLSB,ir_s8_buffer+0 | |
0 | 263 |
264 movlw b'01011000' ;+3*high as start and 1+low as stop! | |
265 movwf isr1_temp | |
266 movlw d'13' | |
267 rcall send_data_MS5541 | |
268 rcall get_2bytes_MS5541 | |
255 | 269 movff dMSB,ir_s8_buffer+3 |
270 movff dLSB,ir_s8_buffer+2 | |
0 | 271 |
272 movlw b'01100100' ;+3*high as start and 1+low as stop! | |
273 movwf isr1_temp | |
274 movlw d'13' | |
275 rcall send_data_MS5541 | |
276 rcall get_2bytes_MS5541 | |
255 | 277 movff dMSB,ir_s8_buffer+5 |
278 movff dLSB,ir_s8_buffer+4 | |
0 | 279 |
280 movlw b'01101000' ;+3*high as start and 1+low as stop! | |
281 movwf isr1_temp | |
282 movlw d'13' | |
283 rcall send_data_MS5541 | |
284 rcall get_2bytes_MS5541 | |
255 | 285 movff dMSB,ir_s8_buffer+7 |
286 movff dLSB,ir_s8_buffer+6 | |
0 | 287 |
288 ; calculate C1 (16Bit) | |
255 | 289 movff ir_s8_buffer+1, C1+1 |
0 | 290 bcf STATUS,C |
291 rrcf C1+1 | |
292 bcf STATUS,C | |
293 rrcf C1+1 | |
294 bcf STATUS,C | |
295 rrcf C1+1 | |
255 | 296 movff ir_s8_buffer+0, C1+0 |
0 | 297 bsf STATUS,C |
255 | 298 btfss ir_s8_buffer+1,0 |
0 | 299 bcf STATUS,C |
300 rrcf C1+0 | |
301 bsf STATUS,C | |
255 | 302 btfss ir_s8_buffer+1,1 |
0 | 303 bcf STATUS,C |
304 rrcf C1+0 | |
305 bsf STATUS,C | |
255 | 306 btfss ir_s8_buffer+1,2 |
0 | 307 bcf STATUS,C |
308 rrcf C1+0 | |
309 | |
310 ; calculate C2 (16Bit) | |
255 | 311 movff ir_s8_buffer+2, C2+0 |
0 | 312 bsf STATUS,C |
255 | 313 btfss ir_s8_buffer+3,0 |
0 | 314 bcf STATUS,C |
315 rrcf C2+0 | |
316 bsf STATUS,C | |
255 | 317 btfss ir_s8_buffer+3,1 |
0 | 318 bcf STATUS,C |
319 rrcf C2+0 | |
320 bsf STATUS,C | |
255 | 321 btfss ir_s8_buffer+3,2 |
0 | 322 bcf STATUS,C |
323 rrcf C2+0 | |
324 bsf STATUS,C | |
255 | 325 btfss ir_s8_buffer+3,3 |
0 | 326 bcf STATUS,C |
327 rrcf C2+0 | |
328 bsf STATUS,C | |
255 | 329 btfss ir_s8_buffer+3,4 |
0 | 330 bcf STATUS,C |
331 rrcf C2+0 | |
332 bsf STATUS,C | |
255 | 333 btfss ir_s8_buffer+3,5 |
0 | 334 bcf STATUS,C |
335 rrcf C2+0 | |
336 | |
255 | 337 movff ir_s8_buffer+3, C2+1 |
0 | 338 bsf STATUS,C |
255 | 339 btfss ir_s8_buffer+0,0 |
0 | 340 bcf STATUS,C |
341 rrcf C2+1 | |
342 bsf STATUS,C | |
255 | 343 btfss ir_s8_buffer+0,1 |
0 | 344 bcf STATUS,C |
345 rrcf C2+1 | |
346 bsf STATUS,C | |
255 | 347 btfss ir_s8_buffer+0,2 |
0 | 348 bcf STATUS,C |
349 rrcf C2+1 | |
350 bcf STATUS,C | |
351 rrcf C2+1 | |
352 bcf STATUS,C | |
353 rrcf C2+1 | |
354 bcf STATUS,C | |
355 rrcf C2+1 | |
356 | |
357 ; calculate C3 (16Bit) | |
255 | 358 movff ir_s8_buffer+5,C3+0 |
0 | 359 bsf STATUS,C |
255 | 360 btfss ir_s8_buffer+4,7 |
0 | 361 bcf STATUS,C |
362 rlcf C3+0 | |
363 bsf STATUS,C | |
255 | 364 btfss ir_s8_buffer+4,6 |
0 | 365 bcf STATUS,C |
366 rlcf C3+0 | |
367 clrf C3+1 | |
255 | 368 btfsc ir_s8_buffer+5,7 |
0 | 369 bsf C3+1,1 |
255 | 370 btfsc ir_s8_buffer+5,6 |
0 | 371 bsf C3+1,0 |
372 | |
373 ; calculate C4 (16Bit) | |
255 | 374 movff ir_s8_buffer+7,C4+0 |
0 | 375 bsf STATUS,C |
255 | 376 btfss ir_s8_buffer+6,7 |
0 | 377 bcf STATUS,C |
378 rlcf C4+0 | |
379 clrf C4+1 | |
255 | 380 btfsc ir_s8_buffer+7,7 |
0 | 381 bsf C4+1,0 |
382 | |
383 ; C4=C4-250 | |
384 movlw LOW(-.250) ; C4 - 250 --> C4 | |
385 addwf C4+0,W | |
386 movwf C4+0 | |
387 movlw -1 ; HIGH(- .250) is not understood... | |
388 addwfc C4+1,W | |
389 movwf C4+1 | |
390 | |
391 ; calculate C5 (16Bit) | |
255 | 392 movff ir_s8_buffer+4,C5+0 |
0 | 393 bcf C5+0,6 |
255 | 394 btfsc ir_s8_buffer+2,0 |
0 | 395 bsf C5+0,6 |
396 bcf C5+0,7 | |
255 | 397 btfsc ir_s8_buffer+2,1 |
0 | 398 bsf C5+0,7 |
399 clrf C5+1 | |
255 | 400 btfsc ir_s8_buffer+2,2 |
0 | 401 bsf C5+1,0 |
255 | 402 btfsc ir_s8_buffer+2,3 |
0 | 403 bsf C5+1,1 |
255 | 404 btfsc ir_s8_buffer+2,4 |
0 | 405 bsf C5+1,2 |
255 | 406 btfsc ir_s8_buffer+2,5 |
0 | 407 bsf C5+1,3 |
408 | |
409 ; calculate C5 = UT1 | |
410 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760) | |
411 clrf isr_xA+1 | |
412 movlw d'8' | |
413 movwf isr_xA+0 | |
414 movff C5+0,isr_xB+0 | |
415 movff C5+1,isr_xB+1 | |
416 call isr_unsigned_mult16x16 ;isr_xA*isr_xB=isr_xC | |
417 movff isr_xC+0,C5+0 | |
418 movff isr_xC+1,C5+1 | |
419 movlw LOW d'10000' | |
420 addwf C5+0,F | |
421 movlw HIGH d'10000' | |
422 addwfc C5+1,F ; = 8*C5 + 10000 | |
423 | |
424 ; calculate C6 (16Bit) | |
425 clrf C6+1 | |
255 | 426 movff ir_s8_buffer+6,C6+0 |
0 | 427 bcf C6+0,7 |
428 | |
429 banksel common | |
430 bcf no_sensor_int ; enable sensor interrupts | |
431 bcf pressure_refresh ; Clear flag | |
432 banksel isr_backup ; Back to Bank0 ISR data | |
433 | |
434 clrf sensor_state_counter ; Then reset State counter | |
435 | |
436 return | |
437 | |
438 ;============================================================================= | |
439 reset_MS5541_one: | |
440 bsf MS5541_mosi | |
441 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return | |
442 | |
443 reset_MS5541_zero: | |
444 bcf MS5541_mosi | |
445 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return | |
446 | |
447 reset_MS5541: | |
448 rcall reset_MS5541_one ;0 | |
449 rcall reset_MS5541_zero | |
450 rcall reset_MS5541_one | |
451 rcall reset_MS5541_zero | |
452 rcall reset_MS5541_one | |
453 rcall reset_MS5541_zero | |
454 rcall reset_MS5541_one | |
455 rcall reset_MS5541_zero | |
456 rcall reset_MS5541_one | |
457 rcall reset_MS5541_zero | |
458 rcall reset_MS5541_one | |
459 rcall reset_MS5541_zero | |
460 rcall reset_MS5541_one | |
461 rcall reset_MS5541_zero | |
462 rcall reset_MS5541_one | |
463 rcall reset_MS5541_zero ;15 | |
464 rcall reset_MS5541_zero | |
465 rcall reset_MS5541_zero | |
466 rcall reset_MS5541_zero | |
467 rcall reset_MS5541_zero | |
468 rcall reset_MS5541_zero ;20 | |
469 return | |
470 | |
471 get_2bytes_MS5541: | |
472 movlw d'8' | |
473 movwf clock_count | |
474 rcall recieve_loop | |
475 movff isr1_temp,dMSB | |
476 | |
477 movlw d'8' | |
478 movwf clock_count | |
479 rcall recieve_loop | |
480 movff isr1_temp,dLSB | |
481 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return | |
482 ;return | |
483 | |
484 recieve_loop: | |
485 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk | |
486 btfss MS5541_miso ;MSB first | |
487 bcf STATUS,C | |
488 btfsc MS5541_miso ;MSB first | |
489 bsf STATUS,C | |
490 rlcf isr1_temp,F | |
491 decfsz clock_count,F | |
492 bra recieve_loop | |
493 return | |
494 | |
495 send_clk_pulse: | |
496 bsf MS5541_clk | |
497 nop | |
498 nop | |
499 nop | |
500 nop | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
501 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
502 nop |
0 | 503 bcf MS5541_clk |
504 nop | |
505 nop | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
506 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
507 nop |
0 | 508 return |
509 | |
510 send_data_MS5541: | |
511 movwf clock_count ; From WREG | |
512 ; send three startbits first | |
513 bcf MS5541_clk | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
514 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
515 nop |
0 | 516 bsf MS5541_mosi |
517 movlw d'3' | |
518 subwf clock_count,F ; total bit counter | |
519 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk | |
520 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk | |
521 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk | |
522 ; now send 8 bytes from isr_temp1 and fill-up with zeros | |
523 send_data_MS5541_2: | |
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 |
528 btfss isr1_temp,7 ;MSB first | |
529 bcf MS5541_mosi | |
530 btfsc isr1_temp,7 ;MSB first | |
531 bsf MS5541_mosi | |
532 | |
533 bsf MS5541_clk | |
534 | |
535 bcf STATUS,C | |
536 rlcf isr1_temp,F | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
537 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
538 nop |
0 | 539 ; nop |
540 ; nop | |
541 ; nop | |
542 ; nop | |
543 ; bcf MS5541_clk | |
544 | |
545 decfsz clock_count,F | |
546 bra send_data_MS5541_2 | |
547 bcf MS5541_clk | |
548 return | |
549 | |
550 END |