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