0
|
1
|
|
2 ; OSTC - diving computer code
|
|
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR
|
|
4
|
|
5 ; This program is free software: you can redistribute it and/or modify
|
|
6 ; it under the terms of the GNU General Public License as published by
|
|
7 ; the Free Software Foundation, either version 3 of the License, or
|
|
8 ; (at your option) any later version.
|
|
9
|
|
10 ; This program is distributed in the hope that it will be useful,
|
|
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ; GNU General Public License for more details.
|
|
14
|
|
15 ; You should have received a copy of the GNU General Public License
|
|
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
|
18
|
|
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
|
|
20 ; written: 10/30/05
|
|
21 ; last updated: 05/16/08
|
|
22 ; known bugs:
|
|
23 ; ToDo:
|
|
24
|
|
25 ; the timer1 module interrupts every 62.5ms (16x/second)
|
|
26 ; temperature and pressure is averaged over 4 measurements
|
|
27 ; flag pressure_refresh is set every 500ms
|
|
28 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable)
|
|
29
|
|
30 uartint:
|
|
31 btfsc simulatormode_active ; are we in simulatormode?
|
|
32 bra simulator_int ; Yes, reading is depth in m!
|
|
33
|
|
34 movff RCREG,uart1_temp
|
|
35 movlw d'96'
|
|
36 subwf uart1_temp,F
|
|
37 dcfsnz uart1_temp,F ; "a"
|
|
38 bsf dump_external_eeprom ; set flag
|
|
39 dcfsnz uart1_temp,F ; "b"
|
|
40 bsf uart_settime ; set flag
|
|
41 dcfsnz uart1_temp,F ; "c"
|
|
42 bsf simulatormode_active ; set flag
|
|
43 dcfsnz uart1_temp,F ; "d"
|
|
44 bsf internal_eeprom_write ; set flag
|
|
45 dcfsnz uart1_temp,F ; "e"
|
|
46 bsf uart_send_hash ; set flag
|
|
47 dcfsnz uart1_temp,F ; "f"
|
49
|
48 nop ; no longer used command "f"
|
0
|
49 dcfsnz uart1_temp,F ; "g"
|
|
50 bsf uart_send_int_eeprom ; set flag
|
|
51 dcfsnz uart1_temp,F ; "h"
|
|
52 bsf uart_reset_decodata ; set flag
|
|
53 dcfsnz uart1_temp,F ; "i"
|
|
54 bsf internal_eeprom_write2 ; set flag
|
|
55 dcfsnz uart1_temp,F ; "j"
|
|
56 bsf uart_send_int_eeprom2 ; set flag
|
|
57 dcfsnz uart1_temp,F ; "k"
|
|
58 bsf uart_store_tissue_data ; set flag
|
|
59
|
|
60
|
|
61 uartint1:
|
|
62 movf RCREG,w ; unload RCREG in stand-alone simulator mode
|
|
63 bcf PIR1,RCIF ; Clear flag
|
|
64 bcf RCSTA,CREN ; Clear receiver status
|
|
65 bsf RCSTA,CREN
|
|
66 return
|
|
67
|
|
68 simulator_int:
|
|
69 btfsc standalone_simulator ; ignore in standalone simulator mode
|
|
70 bra uartint1
|
|
71
|
21
|
72 bsf LED_blue
|
0
|
73 tstfsz RCREG ; =0x00?
|
|
74 bra simulator_int1 ; No
|
|
75 incf RCREG,F ; Yes, so force RCREG=1
|
|
76
|
|
77 simulator_int1:
|
|
78 movf RCREG,w ; depth in m
|
|
79 mullw d'100' ; result will be mbar
|
|
80 movff PRODL,sim_pressure+0 ; stored for pressure overwrite
|
|
81 movff PRODH,sim_pressure+1
|
|
82 bra uartint1 ; exit uart int
|
|
83
|
238
|
84 switch_left_int:
|
0
|
85 bcf INTCON,INT0IF ; Clear flag
|
|
86
|
|
87 btfsc T0CON,TMR0ON ; Timer0 running?
|
|
88 bra timer0_restart ; Yes, restart
|
|
89
|
|
90 bsf switch_left ; Set flag, button press is OK
|
|
91
|
|
92 bsf T0CON,TMR0ON ; Start Timer 0
|
|
93 return
|
|
94
|
|
95
|
238
|
96 switch_right_int:
|
0
|
97 bcf INTCON3,INT1IF ; Clear flag
|
|
98
|
|
99 btfsc T0CON,TMR0ON ; Timer0 running?
|
|
100 bra timer0_restart ; Yes, restart
|
|
101
|
|
102 bsf switch_right ; Set flag, button press is OK
|
|
103
|
|
104 bsf T0CON,TMR0ON ; Start Timer 0
|
|
105 return
|
|
106
|
|
107 timer0_restart:
|
|
108 bcf INTCON,TMR0IF ; Clear flag
|
|
109 clrf T0CON ; Timer0
|
|
110 clrf TMR0H
|
|
111 clrf TMR0L
|
|
112 bsf T0CON,TMR0ON ; Start Timer 0
|
|
113 return
|
|
114
|
|
115 timer0int:
|
|
116 bcf INTCON,TMR0IF ; Clear flag
|
|
117 bcf T0CON,TMR0ON ; Stop Timer 0
|
|
118 clrf TMR0H
|
|
119 clrf TMR0L
|
|
120 return
|
|
121
|
|
122 timer1int:
|
|
123 bcf PIR1,TMR1IF ; Clear flag
|
|
124
|
|
125 timer1int_debug:
|
21
|
126 bcf LED_red ; LEDr off (For charge indicator)
|
0
|
127
|
|
128 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
|
|
129 cpfslt TMR1H ; Did we miss a 1/16 second?
|
|
130 incf timer1int_counter1,F ; Yes, add extra 1/16 second
|
|
131
|
|
132 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
|
|
133 subwf TMR1H,F
|
|
134
|
238
|
135 incf timer1int_counter1,F ; Increase timer1 counter
|
|
136
|
0
|
137 movlw d'15' ; One second 16
|
|
138 cpfsgt timer1int_counter1
|
|
139 bra sensor_int_pre ; only pressure sensor
|
238
|
140 rcall RTCisr ; adjust time, then query pressure sensor
|
0
|
141
|
|
142 sensor_int_pre:
|
238
|
143 btfsc sleepmode ; In sleepmode?
|
|
144 return ; Yes
|
0
|
145
|
|
146 sensor_int:
|
|
147 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep)
|
|
148 return
|
|
149
|
238
|
150 incf timer1int_counter2,F ; counts to eight for state maschine
|
0
|
151
|
238
|
152 ; State 1: Clear flags and average registers, get temperature (51us) and start pressure integration (73,5us)
|
|
153 ; State 2: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
|
|
154 ; State 3: Get temperature (51us) and start pressure integration (73,5us)
|
|
155 ; State 4: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
|
|
156 ; State 5: Get temperature (51us) and start pressure integration (73,5us)
|
|
157 ; State 6: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
|
|
158 ; State 7: Get temperature (51us) and start pressure integration (73,5us)
|
|
159 ; State 8: Get pressure (51us), start temperature integration (73,5us), calculate temperature compensated pressure (233us) and build average for half-second update of tempperature and pressure
|
|
160
|
|
161 movff timer1int_counter2,isr_divB ; isr_divB used as temp here...
|
|
162 dcfsnz isr_divB,F
|
|
163 bra sensor_int_state1_plus_restart ; Do State 1
|
|
164 dcfsnz isr_divB,F
|
|
165 bra sensor_int_state2 ; Do State 2
|
|
166 dcfsnz isr_divB,F
|
|
167 bra sensor_int_state1 ; Do State 3
|
|
168 dcfsnz isr_divB,F
|
|
169 bra sensor_int_state2 ; Do State 4
|
|
170 dcfsnz isr_divB,F
|
|
171 bra sensor_int_state1 ; Do State 5
|
|
172 dcfsnz isr_divB,F
|
|
173 bra sensor_int_state2 ; Do State 6
|
|
174 dcfsnz isr_divB,F
|
|
175 bra sensor_int_state1 ; Do State 7
|
|
176 ; bra sensor_int2_plus_average ; Do State 8
|
|
177
|
|
178 ;sensor_int2_plus_average:
|
|
179 rcall sensor_int_state2
|
|
180 sensor_int2_plus_average2:
|
0
|
181 bcf STATUS,C
|
|
182 rrcf isr3_temp+1 ; isr3_temp / 2
|
|
183 rrcf isr3_temp+0
|
|
184 bcf STATUS,C
|
|
185 rrcf temperature_temp+1 ; temperature_temp /2
|
|
186 rrcf temperature_temp+0
|
238
|
187
|
|
188 bcf STATUS,C
|
|
189 rrcf isr3_temp+1 ; isr3_temp / 4
|
|
190 rrcf isr3_temp+0
|
|
191 bcf STATUS,C
|
|
192 rrcf temperature_temp+1 ; temperature_temp /4
|
|
193 rrcf temperature_temp+0
|
|
194
|
0
|
195 movff isr3_temp+1,amb_pressure+1 ; copy into actual register
|
|
196 movff isr3_temp+0,amb_pressure+0
|
|
197
|
|
198 movff temperature_temp+1,temperature+1
|
|
199 movff temperature_temp+0,temperature+0
|
|
200
|
|
201 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
|
238
|
202 clrf timer1int_counter2 ; Then reset State counter
|
0
|
203
|
|
204 btfss simulatormode_active ; are we in simulator mode?
|
|
205 bra comp_air_pressure ; no
|
|
206
|
|
207 comp_air_pressure0:
|
|
208 movlw LOW d'1000' ; yes, so simulate 1Bar surface pressure
|
|
209 movwf last_surfpressure+0
|
|
210 movlw HIGH d'1000'
|
|
211 movwf last_surfpressure+1
|
|
212
|
|
213 comp_air_pressure:
|
|
214 bcf neg_flag
|
|
215 movf last_surfpressure+0,W ; compensate airpressure
|
|
216 subwf amb_pressure+0,W
|
238
|
217 movwf rel_pressure+0 ; rel_pressure stores depth!
|
0
|
218
|
|
219 movf last_surfpressure+1,W
|
|
220 subwfb amb_pressure+1,W
|
|
221 movwf rel_pressure+1
|
238
|
222 btfss STATUS,N ; result is below zero?
|
|
223 return
|
|
224 clrf rel_pressure+0 ; Yes, do not display negative depths
|
|
225 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
|
0
|
226 return
|
238
|
227
|
|
228
|
|
229 sensor_int_state1_plus_restart:
|
|
230 bcf pressure_refresh ; clear flags
|
|
231 clrf isr3_temp+0 ; pressure average registers
|
|
232 clrf isr3_temp+1
|
|
233 clrf temperature_temp+0
|
|
234 clrf temperature_temp+1
|
|
235
|
|
236 sensor_int_state1:
|
|
237 call get_temperature_value ; State 1: Get temperature
|
|
238 call get_pressure_start ; and start pressure integration.
|
|
239 return ; Done.
|
|
240
|
|
241 sensor_int_state2:
|
|
242 call get_pressure_value ; State2: Get pressure (51us)
|
|
243 call get_temperature_start ; and start temperature integration (73,5us)
|
|
244 call calculate_compensation ; calculate temperature compensated pressure (233us)
|
|
245 movf amb_pressure+0,W
|
|
246 addwf isr3_temp+0 ; average pressure
|
|
247 movf amb_pressure+1,W
|
|
248 addwfc isr3_temp+1
|
|
249 movf temperature+0,W
|
|
250 addwf temperature_temp+0 ; average temperature
|
|
251 movf temperature+1,W
|
|
252 addwfc temperature_temp+1
|
|
253 return
|
|
254
|
0
|
255
|
|
256 RTCisr:
|
|
257 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms)
|
|
258 bsf onesecupdate ; we have a new second!
|
|
259
|
|
260 bcf STATUS,Z ; are we in dive mode?
|
|
261 btfss divemode
|
238
|
262 bra RTCisr2 ; No, must be surface or sleepmode
|
0
|
263
|
|
264 incf samplesecs,F ; CF20 diving seconds done
|
|
265 decf samplesecs_value,W ; holds CF20 value (minus 1 into WREG)
|
|
266 cpfsgt samplesecs
|
238
|
267 bra RTCisr1 ; no
|
0
|
268
|
|
269 clrf samplesecs ; clear counter...
|
|
270 bsf store_sample ; ...and set bit for profile storage
|
238
|
271
|
0
|
272 RTCisr1:
|
|
273 ; Increase re-setable average depth divetime counter
|
111
|
274 incf average_divesecs+0,F ; increase stopwatch registers
|
0
|
275 btfsc STATUS,Z
|
111
|
276 incf average_divesecs+1,F ; increase stopwatch registers
|
0
|
277
|
|
278 btfss divemode2 ; displayed divetime is running?
|
|
279 bra RTCisr2 ; No (e.g. too shallow)
|
|
280
|
|
281 incf divesecs,F ; increase divetime registers
|
|
282 movlw d'59'
|
|
283 cpfsgt divesecs
|
|
284 bra RTCisr1a
|
238
|
285
|
0
|
286 clrf divesecs
|
|
287 bsf realdive ; this bit is always set (again) if the dive is longer then one minute
|
|
288
|
|
289 incf divemins+0,F ; increase divemins
|
|
290 btfsc STATUS,Z
|
|
291 incf divemins+1,F ; and now do the realtime clock routine anyway
|
|
292
|
|
293 RTCisr1a:
|
|
294 btfss FLAG_apnoe_mode ; Are we in Apnoe mode?
|
|
295 bra RTCisr2 ; No, skip the following
|
|
296
|
|
297 incf apnoe_secs,F ; increase descent registers
|
|
298 movlw d'59'
|
|
299 cpfsgt apnoe_secs
|
|
300 bra RTCisr2
|
|
301 clrf apnoe_secs
|
|
302
|
|
303 incf apnoe_mins,F ; increase descent mins
|
|
304 ; Now, do the RTC routine....
|
|
305 RTCisr2:
|
|
306 incf secs,F ; adjusts seconds, minutes, hours, day, month and year. Checks for a leap year and works until 2099!
|
|
307 movlw d'59'
|
|
308 cpfsgt secs
|
|
309 return
|
|
310 clrf secs
|
|
311 bsf oneminupdate
|
|
312 incf mins,F
|
|
313 movlw d'59'
|
|
314 cpfsgt mins
|
|
315 return
|
|
316 clrf mins
|
|
317 incf hours,F
|
|
318 movlw d'23'
|
|
319 cpfsgt hours
|
|
320 return
|
|
321 clrf hours
|
13
|
322 incf day,F
|
43
|
323 movff time_correction_value,secs ; Correct too slow clock
|
13
|
324
|
0
|
325 check_date:
|
|
326 movff month,isr_divB ; new month?
|
|
327 dcfsnz isr_divB,F
|
|
328 movlw .31
|
|
329 dcfsnz isr_divB,F
|
|
330 movlw .28
|
|
331 dcfsnz isr_divB,F
|
|
332 movlw .31
|
|
333 dcfsnz isr_divB,F
|
|
334 movlw .30
|
|
335 dcfsnz isr_divB,F
|
|
336 movlw .31
|
|
337 dcfsnz isr_divB,F
|
|
338 movlw .30
|
|
339 dcfsnz isr_divB,F
|
|
340 movlw .31
|
|
341 dcfsnz isr_divB,F
|
|
342 movlw .31
|
|
343 dcfsnz isr_divB,F
|
|
344 movlw .30
|
|
345 dcfsnz isr_divB,F
|
|
346 movlw .31
|
|
347 dcfsnz isr_divB,F
|
|
348 movlw .30
|
|
349 dcfsnz isr_divB,F
|
|
350 movlw .31
|
|
351 cpfsgt day,1
|
|
352 return
|
|
353 movlw .1
|
|
354 movwf day
|
|
355 incf month,F
|
|
356 movlw .12
|
|
357 cpfsgt month,1
|
|
358 return
|
|
359 movlw .1
|
|
360 movwf month
|
|
361 incf year,F
|
|
362 return |