annotate src/ms5541.asm @ 598:e1f0f5e3d4e4

BUGFIX: Internal deco planner did not display results in imperial units
author heinrichsweikamp
date Mon, 30 Jul 2018 19:45:53 +0200
parents 57e349960ef4
children ca4556fb60b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File ms5541.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; Sensor subroutines
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-03 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
11
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 255
diff changeset
12 #include "hwos.inc" ; Mandatory header
0
heinrichsweikamp
parents:
diff changeset
13 #include "math.inc" ; Math routines
heinrichsweikamp
parents:
diff changeset
14
heinrichsweikamp
parents:
diff changeset
15 sensors CODE
heinrichsweikamp
parents:
diff changeset
16
heinrichsweikamp
parents:
diff changeset
17 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
18 ; Expose internal variables, to ease debug:
heinrichsweikamp
parents:
diff changeset
19 global D1, D2
heinrichsweikamp
parents:
diff changeset
20 global C1, C2, C3, C4, C5, C6
heinrichsweikamp
parents:
diff changeset
21 global xdT, xdT2, OFF, SENS, amb_pressure_avg, temperature_avg
heinrichsweikamp
parents:
diff changeset
22
heinrichsweikamp
parents:
diff changeset
23 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
24 global calculate_compensation
heinrichsweikamp
parents:
diff changeset
25 calculate_compensation:
heinrichsweikamp
parents:
diff changeset
26 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350)
heinrichsweikamp
parents:
diff changeset
27 movf C5+0,W ; Get Value to be subtracted
heinrichsweikamp
parents:
diff changeset
28 subwf D2+0,W ; Do the Low Byte
heinrichsweikamp
parents:
diff changeset
29 movwf xdT+0
heinrichsweikamp
parents:
diff changeset
30 movf C5+1,W ; Then the high byte.
heinrichsweikamp
parents:
diff changeset
31 subwfb D2+1,W
heinrichsweikamp
parents:
diff changeset
32 movwf xdT+1
heinrichsweikamp
parents:
diff changeset
33
heinrichsweikamp
parents:
diff changeset
34 ; Second order temperature calculation
heinrichsweikamp
parents:
diff changeset
35 ; xdT/128 is in range -89..+96, hence signed 8bit. dT/128 = (2*dT)/256
heinrichsweikamp
parents:
diff changeset
36 rlcf xdT+0,W ; put hit bit in carry.
heinrichsweikamp
parents:
diff changeset
37 rlcf xdT+1,W ; inject in high byte.
heinrichsweikamp
parents:
diff changeset
38 movwf isr_xA+0 ; and put result in low byte.
heinrichsweikamp
parents:
diff changeset
39 clrf isr_xA+1
heinrichsweikamp
parents:
diff changeset
40 btfsc xdT+1,7 ; If dT < 0
heinrichsweikamp
parents:
diff changeset
41 setf isr_xA+1 ; then signextend to -1
heinrichsweikamp
parents:
diff changeset
42 movff isr_xA+0,isr_xB+0 ; copy A to B
heinrichsweikamp
parents:
diff changeset
43 movff isr_xA+1,isr_xB+1
heinrichsweikamp
parents:
diff changeset
44 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits)
heinrichsweikamp
parents:
diff changeset
45
heinrichsweikamp
parents:
diff changeset
46 ; dT >= 0: divide by 8, ie. 3 shifts rights.
heinrichsweikamp
parents:
diff changeset
47 ; dT < 0: divide by 2, ie. 1 shifts rights.
heinrichsweikamp
parents:
diff changeset
48 movlw .3
heinrichsweikamp
parents:
diff changeset
49 btfss xdT+1,7 ; Was dT negative ?
heinrichsweikamp
parents:
diff changeset
50 movlw .1
heinrichsweikamp
parents:
diff changeset
51 calc_loop_1:
heinrichsweikamp
parents:
diff changeset
52 bcf STATUS,C ;dT^2 is positive, so injected zeros.
heinrichsweikamp
parents:
diff changeset
53 rrcf isr_xC+1,F
heinrichsweikamp
parents:
diff changeset
54 rrcf isr_xC+0,F
heinrichsweikamp
parents:
diff changeset
55 decfsz WREG
heinrichsweikamp
parents:
diff changeset
56 bra calc_loop_1
heinrichsweikamp
parents:
diff changeset
57
heinrichsweikamp
parents:
diff changeset
58 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8)
heinrichsweikamp
parents:
diff changeset
59 subwf xdT+0,W
heinrichsweikamp
parents:
diff changeset
60 movwf xdT2+0
heinrichsweikamp
parents:
diff changeset
61 movf isr_xC+1,W
heinrichsweikamp
parents:
diff changeset
62 subwfb xdT+1,W
heinrichsweikamp
parents:
diff changeset
63 movwf xdT2+1
heinrichsweikamp
parents:
diff changeset
64
heinrichsweikamp
parents:
diff changeset
65 ; Calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
68 movff C4+1,isr_xA+1
heinrichsweikamp
parents:
diff changeset
69 movff xdT2+0,isr_xB+0 ; dT2 --> B
heinrichsweikamp
parents:
diff changeset
70 movff xdT2+1,isr_xB+1
heinrichsweikamp
parents:
diff changeset
71 call isr_signed_mult16x16
368
57e349960ef4 Additional temperature calibration via PC interface
heinrichsweikamp
parents: 353
diff changeset
72
0
heinrichsweikamp
parents:
diff changeset
73 movlw .12-.8 ; A 12bit shift = 1 byte + 4 bits.
heinrichsweikamp
parents:
diff changeset
74 call isr_shift_C31
heinrichsweikamp
parents:
diff changeset
75
heinrichsweikamp
parents:
diff changeset
76 movlw LOW(.10000) ; Add 10000
heinrichsweikamp
parents:
diff changeset
77 addwf isr_xC+1,F
heinrichsweikamp
parents:
diff changeset
78 movlw HIGH(.10000)
heinrichsweikamp
parents:
diff changeset
79 addwfc isr_xC+2,F
heinrichsweikamp
parents:
diff changeset
80
heinrichsweikamp
parents:
diff changeset
81 movf C2+0,W ; Add C2, and save into OFF
heinrichsweikamp
parents:
diff changeset
82 addwf isr_xC+1,W
heinrichsweikamp
parents:
diff changeset
83 movwf OFF+0
heinrichsweikamp
parents:
diff changeset
84 movf C2+1,W
heinrichsweikamp
parents:
diff changeset
85 addwfc isr_xC+2,W
heinrichsweikamp
parents:
diff changeset
86 movwf OFF+1
heinrichsweikamp
parents:
diff changeset
87
heinrichsweikamp
parents:
diff changeset
88 ; Calculate SENS = C1/2 + ((C3+200)*dT)/2^13 + 3000
heinrichsweikamp
parents:
diff changeset
89 movlw LOW(.200) ; C3+200 --> A
heinrichsweikamp
parents:
diff changeset
90 addwf C3+0,W
heinrichsweikamp
parents:
diff changeset
91 movwf isr_xA+0
heinrichsweikamp
parents:
diff changeset
92 movlw HIGH(.200)
heinrichsweikamp
parents:
diff changeset
93 addwfc C3+1,W
heinrichsweikamp
parents:
diff changeset
94 movwf isr_xA+1
heinrichsweikamp
parents:
diff changeset
95 ; B still contains dT2
heinrichsweikamp
parents:
diff changeset
96 call isr_signed_mult16x16 ; A*B --> C
heinrichsweikamp
parents:
diff changeset
97 movlw .13-.8 ; A 13bit shift = 1 byte + 5 bits.
heinrichsweikamp
parents:
diff changeset
98 call isr_shift_C31
heinrichsweikamp
parents:
diff changeset
99
heinrichsweikamp
parents:
diff changeset
100 bcf STATUS,C ; SENS = C1 / 2
heinrichsweikamp
parents:
diff changeset
101 rrcf C1+1,W
heinrichsweikamp
parents:
diff changeset
102 movwf SENS+1
heinrichsweikamp
parents:
diff changeset
103 rrcf C1+0,W
heinrichsweikamp
parents:
diff changeset
104 movwf SENS+0
heinrichsweikamp
parents:
diff changeset
105
heinrichsweikamp
parents:
diff changeset
106 movlw LOW(.3000) ; Add 3000
heinrichsweikamp
parents:
diff changeset
107 addwf isr_xC+1,F
heinrichsweikamp
parents:
diff changeset
108 movlw HIGH(.3000)
heinrichsweikamp
parents:
diff changeset
109 addwfc isr_xC+2,F
heinrichsweikamp
parents:
diff changeset
110
heinrichsweikamp
parents:
diff changeset
111 movf isr_xC+1,W ; And sum into SENS
heinrichsweikamp
parents:
diff changeset
112 addwf SENS+0,F
heinrichsweikamp
parents:
diff changeset
113 movf isr_xC+2,W
heinrichsweikamp
parents:
diff changeset
114 addwfc SENS+1,F
heinrichsweikamp
parents:
diff changeset
115
heinrichsweikamp
parents:
diff changeset
116 ; calculate amb_pressure = (sens * (d1-off))/2^12 + 1000
heinrichsweikamp
parents:
diff changeset
117 movf OFF+0,W ; d1-off --> a
heinrichsweikamp
parents:
diff changeset
118 subwf D1+0,W
heinrichsweikamp
parents:
diff changeset
119 movwf isr_xA+0
heinrichsweikamp
parents:
diff changeset
120 movf OFF+1,W
heinrichsweikamp
parents:
diff changeset
121 subwfb D1+1,W
heinrichsweikamp
parents:
diff changeset
122 movwf isr_xA+1
heinrichsweikamp
parents:
diff changeset
123
heinrichsweikamp
parents:
diff changeset
124 movff SENS+0,isr_xB+0 ; sens --> b
heinrichsweikamp
parents:
diff changeset
125 movff SENS+1,isr_xB+1
heinrichsweikamp
parents:
diff changeset
126 call isr_signed_mult16x16
heinrichsweikamp
parents:
diff changeset
127 movlw .12-.8 ; a 12bit shift = 1 byte + 4 bits.
heinrichsweikamp
parents:
diff changeset
128 call isr_shift_C31
heinrichsweikamp
parents:
diff changeset
129
heinrichsweikamp
parents:
diff changeset
130 movlw LOW(.1000) ; add 1000
heinrichsweikamp
parents:
diff changeset
131 addwf isr_xC+1,F
heinrichsweikamp
parents:
diff changeset
132 movlw HIGH(.1000)
heinrichsweikamp
parents:
diff changeset
133 addwfc isr_xC+2,F
heinrichsweikamp
parents:
diff changeset
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
39f6c07ce2f6 BUGFIX: Average depth computation
heinrichsweikamp
parents: 92
diff changeset
166 banksel common ; flag2 is in bank 1
0
heinrichsweikamp
parents:
diff changeset
167 btfss simulatormode_active ; are we in simulator mode?
heinrichsweikamp
parents:
diff changeset
168 bra calc_compensation_2 ; no
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
181 movff sim_pressure+0,isr_xC+1 ; override readings with simulator values
heinrichsweikamp
parents:
diff changeset
182 movff sim_pressure+1,isr_xC+2
heinrichsweikamp
parents:
diff changeset
183
heinrichsweikamp
parents:
diff changeset
184 calc_compensation_2:
heinrichsweikamp
parents:
diff changeset
185 banksel isr_backup
heinrichsweikamp
parents:
diff changeset
186 movf isr_xC+1,W ; Then sum_up to pressure averaging buffer.
heinrichsweikamp
parents:
diff changeset
187 addwf amb_pressure_avg+0,F
heinrichsweikamp
parents:
diff changeset
188 movf isr_xC+2,W
heinrichsweikamp
parents:
diff changeset
189 addwfc amb_pressure_avg+1,F
heinrichsweikamp
parents:
diff changeset
190
heinrichsweikamp
parents:
diff changeset
191 ; calculate temp = 200 + dT*(C6+100)/2^11
heinrichsweikamp
parents:
diff changeset
192 movlw LOW(.100) ; C6 + 100 --> A
heinrichsweikamp
parents:
diff changeset
193 addwf C6+0,W
heinrichsweikamp
parents:
diff changeset
194 movwf isr_xA+0
heinrichsweikamp
parents:
diff changeset
195 movlw HIGH(.100)
heinrichsweikamp
parents:
diff changeset
196 addwfc C6+1,W
heinrichsweikamp
parents:
diff changeset
197 movwf isr_xA+1
heinrichsweikamp
parents:
diff changeset
198
heinrichsweikamp
parents:
diff changeset
199 movff xdT2+0,isr_xB+0 ; dT2 --> B
heinrichsweikamp
parents:
diff changeset
200 movff xdT2+1,isr_xB+1
heinrichsweikamp
parents:
diff changeset
201 call isr_signed_mult16x16 ; A*B
heinrichsweikamp
parents:
diff changeset
202 movlw .11-.8 ; A 12bit shift = 1 byte + 3 bits.
heinrichsweikamp
parents:
diff changeset
203 call isr_shift_C31
heinrichsweikamp
parents:
diff changeset
204
heinrichsweikamp
parents:
diff changeset
205 movlw LOW(.200) ; Add 200
heinrichsweikamp
parents:
diff changeset
206 addwf isr_xC+1,F
heinrichsweikamp
parents:
diff changeset
207 movlw HIGH(.200)
heinrichsweikamp
parents:
diff changeset
208 addwfc isr_xC+2,F
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
241 movf isr_xC+1,W
heinrichsweikamp
parents:
diff changeset
242 addwf temperature_avg+0,F
heinrichsweikamp
parents:
diff changeset
243 movf isr_xC+2,W
heinrichsweikamp
parents:
diff changeset
244 addwfc temperature_avg+1,F
heinrichsweikamp
parents:
diff changeset
245
heinrichsweikamp
parents:
diff changeset
246 return ; Done.
heinrichsweikamp
parents:
diff changeset
247
heinrichsweikamp
parents:
diff changeset
248 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
249 global get_pressure_start
heinrichsweikamp
parents:
diff changeset
250 get_pressure_start:
heinrichsweikamp
parents:
diff changeset
251 rcall reset_MS5541
heinrichsweikamp
parents:
diff changeset
252 movlw b'10100000' ;+3*high as start and 1+low as stop!
heinrichsweikamp
parents:
diff changeset
253 get_pressure_start2:
heinrichsweikamp
parents:
diff changeset
254 movwf isr1_temp
heinrichsweikamp
parents:
diff changeset
255 movlw d'12'
heinrichsweikamp
parents:
diff changeset
256 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
257 return
heinrichsweikamp
parents:
diff changeset
258
heinrichsweikamp
parents:
diff changeset
259 global get_pressure_value
heinrichsweikamp
parents:
diff changeset
260 get_pressure_value:
heinrichsweikamp
parents:
diff changeset
261 btfsc MS5541_miso ; Conversion done?
heinrichsweikamp
parents:
diff changeset
262 return ; No, Return
heinrichsweikamp
parents:
diff changeset
263 rcall get_2bytes_MS5541
heinrichsweikamp
parents:
diff changeset
264 movff dMSB,D1+1
heinrichsweikamp
parents:
diff changeset
265 movff dLSB,D1+0
heinrichsweikamp
parents:
diff changeset
266 return
heinrichsweikamp
parents:
diff changeset
267
heinrichsweikamp
parents:
diff changeset
268 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
269 global get_temperature_start
heinrichsweikamp
parents:
diff changeset
270 get_temperature_start:
heinrichsweikamp
parents:
diff changeset
271 rcall reset_MS5541
heinrichsweikamp
parents:
diff changeset
272 movlw b'10010000' ;+3*high as start and 1+low as stop!
heinrichsweikamp
parents:
diff changeset
273 bra get_pressure_start2 ; continue in "get_pressure"
heinrichsweikamp
parents:
diff changeset
274
heinrichsweikamp
parents:
diff changeset
275 global get_temperature_value
heinrichsweikamp
parents:
diff changeset
276 get_temperature_value:
heinrichsweikamp
parents:
diff changeset
277 btfsc MS5541_miso ; Conversion done?
heinrichsweikamp
parents:
diff changeset
278 return ; No, Return
heinrichsweikamp
parents:
diff changeset
279 rcall get_2bytes_MS5541
heinrichsweikamp
parents:
diff changeset
280 movff dMSB,D2+1
heinrichsweikamp
parents:
diff changeset
281 movff dLSB,D2+0
heinrichsweikamp
parents:
diff changeset
282 return
heinrichsweikamp
parents:
diff changeset
283
heinrichsweikamp
parents:
diff changeset
284 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
285 global get_calibration_data
heinrichsweikamp
parents:
diff changeset
286 get_calibration_data:
heinrichsweikamp
parents:
diff changeset
287 banksel common
heinrichsweikamp
parents:
diff changeset
288 bsf no_sensor_int ; disable sensor interrupts
heinrichsweikamp
parents:
diff changeset
289 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
290
heinrichsweikamp
parents:
diff changeset
291 rcall reset_MS5541
heinrichsweikamp
parents:
diff changeset
292 movlw b'01010100' ;+3*high as start and 1+low as stop!
heinrichsweikamp
parents:
diff changeset
293 movwf isr1_temp
heinrichsweikamp
parents:
diff changeset
294 movlw d'13'
heinrichsweikamp
parents:
diff changeset
295 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
296 rcall get_2bytes_MS5541
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
297 movff dMSB,ir_s8_buffer+1
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
298 movff dLSB,ir_s8_buffer+0
0
heinrichsweikamp
parents:
diff changeset
299
heinrichsweikamp
parents:
diff changeset
300 movlw b'01011000' ;+3*high as start and 1+low as stop!
heinrichsweikamp
parents:
diff changeset
301 movwf isr1_temp
heinrichsweikamp
parents:
diff changeset
302 movlw d'13'
heinrichsweikamp
parents:
diff changeset
303 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
304 rcall get_2bytes_MS5541
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
305 movff dMSB,ir_s8_buffer+3
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
306 movff dLSB,ir_s8_buffer+2
0
heinrichsweikamp
parents:
diff changeset
307
heinrichsweikamp
parents:
diff changeset
308 movlw b'01100100' ;+3*high as start and 1+low as stop!
heinrichsweikamp
parents:
diff changeset
309 movwf isr1_temp
heinrichsweikamp
parents:
diff changeset
310 movlw d'13'
heinrichsweikamp
parents:
diff changeset
311 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
312 rcall get_2bytes_MS5541
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
313 movff dMSB,ir_s8_buffer+5
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
314 movff dLSB,ir_s8_buffer+4
0
heinrichsweikamp
parents:
diff changeset
315
heinrichsweikamp
parents:
diff changeset
316 movlw b'01101000' ;+3*high as start and 1+low as stop!
heinrichsweikamp
parents:
diff changeset
317 movwf isr1_temp
heinrichsweikamp
parents:
diff changeset
318 movlw d'13'
heinrichsweikamp
parents:
diff changeset
319 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
320 rcall get_2bytes_MS5541
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
321 movff dMSB,ir_s8_buffer+7
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
322 movff dLSB,ir_s8_buffer+6
0
heinrichsweikamp
parents:
diff changeset
323
heinrichsweikamp
parents:
diff changeset
324 ; calculate C1 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
325 movff ir_s8_buffer+1, C1+1
0
heinrichsweikamp
parents:
diff changeset
326 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
327 rrcf C1+1
heinrichsweikamp
parents:
diff changeset
328 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
329 rrcf C1+1
heinrichsweikamp
parents:
diff changeset
330 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
331 rrcf C1+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
332 movff ir_s8_buffer+0, C1+0
0
heinrichsweikamp
parents:
diff changeset
333 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
334 btfss ir_s8_buffer+1,0
0
heinrichsweikamp
parents:
diff changeset
335 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
336 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
337 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
338 btfss ir_s8_buffer+1,1
0
heinrichsweikamp
parents:
diff changeset
339 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
340 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
341 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
342 btfss ir_s8_buffer+1,2
0
heinrichsweikamp
parents:
diff changeset
343 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
344 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
345
heinrichsweikamp
parents:
diff changeset
346 ; calculate C2 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
347 movff ir_s8_buffer+2, C2+0
0
heinrichsweikamp
parents:
diff changeset
348 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
349 btfss ir_s8_buffer+3,0
0
heinrichsweikamp
parents:
diff changeset
350 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
351 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
352 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
353 btfss ir_s8_buffer+3,1
0
heinrichsweikamp
parents:
diff changeset
354 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
355 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
356 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
357 btfss ir_s8_buffer+3,2
0
heinrichsweikamp
parents:
diff changeset
358 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
359 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
360 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
361 btfss ir_s8_buffer+3,3
0
heinrichsweikamp
parents:
diff changeset
362 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
363 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
364 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
365 btfss ir_s8_buffer+3,4
0
heinrichsweikamp
parents:
diff changeset
366 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
367 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
368 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
369 btfss ir_s8_buffer+3,5
0
heinrichsweikamp
parents:
diff changeset
370 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
371 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
372
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
373 movff ir_s8_buffer+3, C2+1
0
heinrichsweikamp
parents:
diff changeset
374 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
375 btfss ir_s8_buffer+0,0
0
heinrichsweikamp
parents:
diff changeset
376 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
377 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
378 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
379 btfss ir_s8_buffer+0,1
0
heinrichsweikamp
parents:
diff changeset
380 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
381 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
382 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
383 btfss ir_s8_buffer+0,2
0
heinrichsweikamp
parents:
diff changeset
384 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
385 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
386 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
387 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
388 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
389 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
390 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
391 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
392
heinrichsweikamp
parents:
diff changeset
393 ; calculate C3 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
394 movff ir_s8_buffer+5,C3+0
0
heinrichsweikamp
parents:
diff changeset
395 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
396 btfss ir_s8_buffer+4,7
0
heinrichsweikamp
parents:
diff changeset
397 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
398 rlcf C3+0
heinrichsweikamp
parents:
diff changeset
399 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
400 btfss ir_s8_buffer+4,6
0
heinrichsweikamp
parents:
diff changeset
401 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
402 rlcf C3+0
heinrichsweikamp
parents:
diff changeset
403 clrf C3+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
404 btfsc ir_s8_buffer+5,7
0
heinrichsweikamp
parents:
diff changeset
405 bsf C3+1,1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
406 btfsc ir_s8_buffer+5,6
0
heinrichsweikamp
parents:
diff changeset
407 bsf C3+1,0
heinrichsweikamp
parents:
diff changeset
408
heinrichsweikamp
parents:
diff changeset
409 ; calculate C4 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
410 movff ir_s8_buffer+7,C4+0
0
heinrichsweikamp
parents:
diff changeset
411 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
412 btfss ir_s8_buffer+6,7
0
heinrichsweikamp
parents:
diff changeset
413 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
414 rlcf C4+0
heinrichsweikamp
parents:
diff changeset
415 clrf C4+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
416 btfsc ir_s8_buffer+7,7
0
heinrichsweikamp
parents:
diff changeset
417 bsf C4+1,0
heinrichsweikamp
parents:
diff changeset
418
heinrichsweikamp
parents:
diff changeset
419 ; C4=C4-250
heinrichsweikamp
parents:
diff changeset
420 movlw LOW(-.250) ; C4 - 250 --> C4
heinrichsweikamp
parents:
diff changeset
421 addwf C4+0,W
heinrichsweikamp
parents:
diff changeset
422 movwf C4+0
heinrichsweikamp
parents:
diff changeset
423 movlw -1 ; HIGH(- .250) is not understood...
heinrichsweikamp
parents:
diff changeset
424 addwfc C4+1,W
heinrichsweikamp
parents:
diff changeset
425 movwf C4+1
heinrichsweikamp
parents:
diff changeset
426
heinrichsweikamp
parents:
diff changeset
427 ; calculate C5 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
428 movff ir_s8_buffer+4,C5+0
0
heinrichsweikamp
parents:
diff changeset
429 bcf C5+0,6
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
430 btfsc ir_s8_buffer+2,0
0
heinrichsweikamp
parents:
diff changeset
431 bsf C5+0,6
heinrichsweikamp
parents:
diff changeset
432 bcf C5+0,7
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
433 btfsc ir_s8_buffer+2,1
0
heinrichsweikamp
parents:
diff changeset
434 bsf C5+0,7
heinrichsweikamp
parents:
diff changeset
435 clrf C5+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
436 btfsc ir_s8_buffer+2,2
0
heinrichsweikamp
parents:
diff changeset
437 bsf C5+1,0
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
438 btfsc ir_s8_buffer+2,3
0
heinrichsweikamp
parents:
diff changeset
439 bsf C5+1,1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
440 btfsc ir_s8_buffer+2,4
0
heinrichsweikamp
parents:
diff changeset
441 bsf C5+1,2
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
442 btfsc ir_s8_buffer+2,5
0
heinrichsweikamp
parents:
diff changeset
443 bsf C5+1,3
heinrichsweikamp
parents:
diff changeset
444
heinrichsweikamp
parents:
diff changeset
445 ; calculate C5 = UT1
heinrichsweikamp
parents:
diff changeset
446 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760)
heinrichsweikamp
parents:
diff changeset
447 clrf isr_xA+1
heinrichsweikamp
parents:
diff changeset
448 movlw d'8'
heinrichsweikamp
parents:
diff changeset
449 movwf isr_xA+0
heinrichsweikamp
parents:
diff changeset
450 movff C5+0,isr_xB+0
heinrichsweikamp
parents:
diff changeset
451 movff C5+1,isr_xB+1
heinrichsweikamp
parents:
diff changeset
452 call isr_unsigned_mult16x16 ;isr_xA*isr_xB=isr_xC
heinrichsweikamp
parents:
diff changeset
453 movff isr_xC+0,C5+0
heinrichsweikamp
parents:
diff changeset
454 movff isr_xC+1,C5+1
heinrichsweikamp
parents:
diff changeset
455 movlw LOW d'10000'
heinrichsweikamp
parents:
diff changeset
456 addwf C5+0,F
heinrichsweikamp
parents:
diff changeset
457 movlw HIGH d'10000'
heinrichsweikamp
parents:
diff changeset
458 addwfc C5+1,F ; = 8*C5 + 10000
heinrichsweikamp
parents:
diff changeset
459
heinrichsweikamp
parents:
diff changeset
460 ; calculate C6 (16Bit)
heinrichsweikamp
parents:
diff changeset
461 clrf C6+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
462 movff ir_s8_buffer+6,C6+0
0
heinrichsweikamp
parents:
diff changeset
463 bcf C6+0,7
heinrichsweikamp
parents:
diff changeset
464
heinrichsweikamp
parents:
diff changeset
465 banksel common
heinrichsweikamp
parents:
diff changeset
466 bcf no_sensor_int ; enable sensor interrupts
heinrichsweikamp
parents:
diff changeset
467 bcf pressure_refresh ; Clear flag
heinrichsweikamp
parents:
diff changeset
468 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
469
heinrichsweikamp
parents:
diff changeset
470 clrf sensor_state_counter ; Then reset State counter
heinrichsweikamp
parents:
diff changeset
471
heinrichsweikamp
parents:
diff changeset
472 return
heinrichsweikamp
parents:
diff changeset
473
heinrichsweikamp
parents:
diff changeset
474 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
475 reset_MS5541_one:
heinrichsweikamp
parents:
diff changeset
476 bsf MS5541_mosi
heinrichsweikamp
parents:
diff changeset
477 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return
heinrichsweikamp
parents:
diff changeset
478
heinrichsweikamp
parents:
diff changeset
479 reset_MS5541_zero:
heinrichsweikamp
parents:
diff changeset
480 bcf MS5541_mosi
heinrichsweikamp
parents:
diff changeset
481 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return
heinrichsweikamp
parents:
diff changeset
482
heinrichsweikamp
parents:
diff changeset
483 reset_MS5541:
heinrichsweikamp
parents:
diff changeset
484 rcall reset_MS5541_one ;0
heinrichsweikamp
parents:
diff changeset
485 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
486 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
487 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
488 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
489 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
490 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
491 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
492 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
493 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
494 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
495 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
496 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
497 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
498 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
499 rcall reset_MS5541_zero ;15
heinrichsweikamp
parents:
diff changeset
500 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
501 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
502 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
503 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
504 rcall reset_MS5541_zero ;20
heinrichsweikamp
parents:
diff changeset
505 return
heinrichsweikamp
parents:
diff changeset
506
heinrichsweikamp
parents:
diff changeset
507 get_2bytes_MS5541:
heinrichsweikamp
parents:
diff changeset
508 movlw d'8'
heinrichsweikamp
parents:
diff changeset
509 movwf clock_count
heinrichsweikamp
parents:
diff changeset
510 rcall recieve_loop
heinrichsweikamp
parents:
diff changeset
511 movff isr1_temp,dMSB
heinrichsweikamp
parents:
diff changeset
512
heinrichsweikamp
parents:
diff changeset
513 movlw d'8'
heinrichsweikamp
parents:
diff changeset
514 movwf clock_count
heinrichsweikamp
parents:
diff changeset
515 rcall recieve_loop
heinrichsweikamp
parents:
diff changeset
516 movff isr1_temp,dLSB
heinrichsweikamp
parents:
diff changeset
517 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return
heinrichsweikamp
parents:
diff changeset
518 ;return
heinrichsweikamp
parents:
diff changeset
519
heinrichsweikamp
parents:
diff changeset
520 recieve_loop:
heinrichsweikamp
parents:
diff changeset
521 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk
heinrichsweikamp
parents:
diff changeset
522 btfss MS5541_miso ;MSB first
heinrichsweikamp
parents:
diff changeset
523 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
524 btfsc MS5541_miso ;MSB first
heinrichsweikamp
parents:
diff changeset
525 bsf STATUS,C
heinrichsweikamp
parents:
diff changeset
526 rlcf isr1_temp,F
heinrichsweikamp
parents:
diff changeset
527 decfsz clock_count,F
heinrichsweikamp
parents:
diff changeset
528 bra recieve_loop
heinrichsweikamp
parents:
diff changeset
529 return
heinrichsweikamp
parents:
diff changeset
530
heinrichsweikamp
parents:
diff changeset
531 send_clk_pulse:
heinrichsweikamp
parents:
diff changeset
532 bsf MS5541_clk
heinrichsweikamp
parents:
diff changeset
533 nop
heinrichsweikamp
parents:
diff changeset
534 nop
heinrichsweikamp
parents:
diff changeset
535 nop
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
539 bcf MS5541_clk
heinrichsweikamp
parents:
diff changeset
540 nop
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
544 return
heinrichsweikamp
parents:
diff changeset
545
heinrichsweikamp
parents:
diff changeset
546 send_data_MS5541:
heinrichsweikamp
parents:
diff changeset
547 movwf clock_count ; From WREG
heinrichsweikamp
parents:
diff changeset
548 ; send three startbits first
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
552 bsf MS5541_mosi
heinrichsweikamp
parents:
diff changeset
553 movlw d'3'
heinrichsweikamp
parents:
diff changeset
554 subwf clock_count,F ; total bit counter
heinrichsweikamp
parents:
diff changeset
555 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk
heinrichsweikamp
parents:
diff changeset
556 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk
heinrichsweikamp
parents:
diff changeset
557 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk
heinrichsweikamp
parents:
diff changeset
558 ; now send 8 bytes from isr_temp1 and fill-up with zeros
heinrichsweikamp
parents:
diff changeset
559 send_data_MS5541_2:
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
563
heinrichsweikamp
parents:
diff changeset
564 btfss isr1_temp,7 ;MSB first
heinrichsweikamp
parents:
diff changeset
565 bcf MS5541_mosi
heinrichsweikamp
parents:
diff changeset
566 btfsc isr1_temp,7 ;MSB first
heinrichsweikamp
parents:
diff changeset
567 bsf MS5541_mosi
heinrichsweikamp
parents:
diff changeset
568
heinrichsweikamp
parents:
diff changeset
569 bsf MS5541_clk
heinrichsweikamp
parents:
diff changeset
570
heinrichsweikamp
parents:
diff changeset
571 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
575 ; nop
heinrichsweikamp
parents:
diff changeset
576 ; nop
heinrichsweikamp
parents:
diff changeset
577 ; nop
heinrichsweikamp
parents:
diff changeset
578 ; nop
heinrichsweikamp
parents:
diff changeset
579 ; bcf MS5541_clk
heinrichsweikamp
parents:
diff changeset
580
heinrichsweikamp
parents:
diff changeset
581 decfsz clock_count,F
heinrichsweikamp
parents:
diff changeset
582 bra send_data_MS5541_2
heinrichsweikamp
parents:
diff changeset
583 bcf MS5541_clk
heinrichsweikamp
parents:
diff changeset
584 return
heinrichsweikamp
parents:
diff changeset
585
heinrichsweikamp
parents:
diff changeset
586 END