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"
|
|
48 bsf uart_compensate_temp ; set flag
|
|
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
|
|
72 call set_LEDusb
|
|
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
|
|
84 schalter_links: ;
|
|
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
|
|
96 schalter_rechts: ;
|
|
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
|
|
110 clrf T0CON ; Timer0
|
|
111 clrf TMR0H
|
|
112 clrf TMR0L
|
|
113 bsf T0CON,TMR0ON ; Start Timer 0
|
|
114 return
|
|
115
|
|
116 timer0int:
|
|
117 bcf INTCON,TMR0IF ; Clear flag
|
|
118 bcf T0CON,TMR0ON ; Stop Timer 0
|
|
119 clrf TMR0H
|
|
120 clrf TMR0L
|
|
121 return
|
|
122
|
|
123
|
|
124 timer0int_left_reset:
|
|
125 bcf INTCON2, INTEDG0 ; Interrupt on faling edge again
|
|
126 bcf switch_left_isr ; Clear flag, button press is done
|
|
127
|
|
128 movlw T0CON_debounce ; Timer0
|
|
129 movwf T0CON
|
|
130
|
|
131 bsf T0CON,TMR0ON ; Start Timer 0
|
|
132 return
|
|
133
|
|
134 timer0int_left:
|
|
135 bsf INTCON2, INTEDG0 ; Interrupt on rising edge again
|
|
136 return
|
|
137
|
|
138 timer0int_right_reset:
|
|
139 bcf INTCON2, INTEDG1 ; Interrupt on faling edge again
|
|
140 bcf switch_right_isr ; Clear flag, button press is done
|
|
141
|
|
142 movlw T0CON_debounce ; Timer0
|
|
143 movwf T0CON
|
|
144
|
|
145 bsf T0CON,TMR0ON ; Start Timer 0
|
|
146 return
|
|
147
|
|
148 timer0int_right:
|
|
149 bsf INTCON2, INTEDG1 ; Interrupt on rising edge again
|
|
150 return
|
|
151
|
|
152 timer3int:
|
|
153 bcf PIR2,TMR3IF ; Clear flag
|
|
154 bcf T3CON,TMR0ON ; Stop Timer 3
|
|
155 bcf T2CON,2 ; stop Timer 2
|
|
156 return
|
|
157
|
|
158 timer1int:
|
|
159 bcf PIR1,TMR1IF ; Clear flag
|
|
160
|
|
161 timer1int_debug:
|
|
162
|
|
163 call clear_LEDr ; LEDr off (For charge indicator)
|
|
164
|
|
165 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
|
|
166 cpfslt TMR1H ; Did we miss a 1/16 second?
|
|
167 incf timer1int_counter1,F ; Yes, add extra 1/16 second
|
|
168
|
|
169 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
|
|
170 subwf TMR1H,F
|
|
171
|
|
172 incf timer1int_counter1,F
|
|
173 movlw d'15' ; One second 16
|
|
174 cpfsgt timer1int_counter1
|
|
175 bra sensor_int_pre ; only pressure sensor
|
|
176 call RTCisr ; adjust time, then query pressure sensor
|
|
177
|
|
178 sensor_int_pre:
|
|
179 btfss sleepmode ; In sleepmode?
|
|
180 bra sensor_int ; No
|
|
181 return
|
|
182
|
|
183 sensor_int:
|
|
184 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep)
|
|
185 return
|
|
186
|
|
187 incf timer1int_counter2,F ; counts to eight for state maschine
|
|
188
|
|
189 movlw d'1'
|
|
190 cpfseq timer1int_counter2 ; State 1?
|
|
191 bra sensor_int1 ; No
|
|
192
|
|
193 bcf pressure_refresh ; clear flags
|
|
194 clrf isr3_temp+0 ; pressure average registers
|
|
195 clrf isr3_temp+1
|
|
196 clrf temperature_temp+0
|
|
197 clrf temperature_temp+1
|
|
198 sensor_int0:
|
|
199 call get_temperature_value ; State 1: Get temperature
|
|
200 call get_pressure_start ; and start pressure integration.
|
|
201 return ; Done.
|
|
202 sensor_int1:
|
|
203 movlw d'2'
|
|
204 cpfseq timer1int_counter2 ; State 2?
|
|
205 bra sensor_int2 ; No
|
|
206
|
|
207 sensor_int1_1:
|
|
208 call get_pressure_value ; State2: Get pressure (51us)
|
|
209 call get_temperature_start ; and start temperature integration (73,5us)
|
|
210 call calculate_compensation ; calculate temperature compensated pressure (233us)
|
|
211 movf amb_pressure+0,W
|
|
212 addwf isr3_temp+0 ; average pressure
|
|
213 movf amb_pressure+1,W
|
|
214 addwfc isr3_temp+1
|
|
215 movf temperature+0,W
|
|
216 addwf temperature_temp+0 ; average temperature
|
|
217 movf temperature+1,W
|
|
218 addwfc temperature_temp+1
|
|
219 return
|
|
220 sensor_int2:
|
|
221 movlw d'3'
|
|
222 cpfseq timer1int_counter2 ; State 3?
|
|
223 bra sensor_int3 ; No
|
|
224 bra sensor_int0 ; Yes, but same as State 1!
|
|
225 sensor_int3:
|
|
226 movlw d'4'
|
|
227 cpfseq timer1int_counter2 ; State 4?
|
|
228 bra sensor_int4 ; No
|
|
229 bra sensor_int1_1 ; Yes, but same as State 2!
|
|
230 sensor_int4:
|
|
231 movlw d'5'
|
|
232 cpfseq timer1int_counter2 ; State 5?
|
|
233 bra sensor_int5 ; No
|
|
234 bra sensor_int0 ; Yes, but same as State 1!
|
|
235 sensor_int5:
|
|
236 movlw d'6'
|
|
237 cpfseq timer1int_counter2 ; State 6?
|
|
238 bra sensor_int6 ; No
|
|
239 bra sensor_int1_1 ; Yes, but same as State 2!
|
|
240 sensor_int6:
|
|
241 movlw d'7'
|
|
242 cpfseq timer1int_counter2 ; State 7?
|
|
243 bra sensor_int7 ; No
|
|
244 bra sensor_int0 ; Yes, but same as State 1!
|
|
245 sensor_int7:
|
|
246 rcall sensor_int1_1 ; Do State 2...
|
|
247 clrf timer1int_counter2 ; ..then reset State counter...
|
|
248 movlw d'2' ; and calculate average!
|
|
249 movwf isr2_temp
|
|
250 sensor_int8:
|
|
251 bcf STATUS,C
|
|
252 rrcf isr3_temp+1 ; isr3_temp / 2
|
|
253 rrcf isr3_temp+0
|
|
254 bcf STATUS,C
|
|
255 rrcf temperature_temp+1 ; temperature_temp /2
|
|
256 rrcf temperature_temp+0
|
|
257 decfsz isr2_temp,F
|
|
258 bra sensor_int8 ; once more
|
|
259
|
|
260 movff isr3_temp+1,amb_pressure+1 ; copy into actual register
|
|
261 movff isr3_temp+0,amb_pressure+0
|
|
262
|
|
263 movff temperature_temp+1,temperature+1
|
|
264 movff temperature_temp+0,temperature+0
|
|
265
|
|
266 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
|
|
267
|
|
268 btfss simulatormode_active ; are we in simulator mode?
|
|
269 bra comp_air_pressure ; no
|
|
270
|
|
271 comp_air_pressure0:
|
|
272 movlw LOW d'1000' ; yes, so simulate 1Bar surface pressure
|
|
273 movwf last_surfpressure+0
|
|
274 movlw HIGH d'1000'
|
|
275 movwf last_surfpressure+1
|
|
276
|
|
277 comp_air_pressure:
|
|
278 bcf neg_flag
|
|
279 movf last_surfpressure+0,W ; compensate airpressure
|
|
280 subwf amb_pressure+0,W
|
|
281 movwf rel_pressure+0 ; rel_pressure stores depth!
|
|
282
|
|
283 movf last_surfpressure+1,W
|
|
284 subwfb amb_pressure+1,W
|
|
285 movwf rel_pressure+1
|
|
286 btfss STATUS,N ; result is below zero?
|
|
287 return
|
|
288 clrf rel_pressure+0 ; Yes, do not display negative depths
|
|
289 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
|
|
290 return
|
|
291
|
|
292 RTCisr:
|
|
293 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms)
|
|
294 bsf onesecupdate ; we have a new second!
|
|
295
|
|
296 bcf STATUS,Z ; are we in dive mode?
|
|
297 btfss divemode
|
|
298 bra RTCisr2 ; No, must be surface or sleepmode
|
|
299
|
|
300 incf samplesecs,F ; CF20 diving seconds done
|
|
301 decf samplesecs_value,W ; holds CF20 value (minus 1 into WREG)
|
|
302 cpfsgt samplesecs
|
|
303 bra RTCisr1 ; no
|
|
304
|
|
305 clrf samplesecs ; clear counter...
|
|
306 bsf store_sample ; ...and set bit for profile storage
|
|
307 RTCisr1:
|
|
308 ; Increase re-setable average depth divetime counter
|
|
309 incf average_divesecs+0,F ; increase divetime registers
|
|
310 btfsc STATUS,Z
|
|
311 incf average_divesecs+1,F ; increase divetime registers
|
|
312
|
|
313 btfss divemode2 ; displayed divetime is running?
|
|
314 bra RTCisr2 ; No (e.g. too shallow)
|
|
315
|
|
316 incf divesecs,F ; increase divetime registers
|
|
317 movlw d'59'
|
|
318 cpfsgt divesecs
|
|
319 bra RTCisr1a
|
|
320 clrf divesecs
|
|
321 bsf realdive ; this bit is always set (again) if the dive is longer then one minute
|
|
322
|
|
323 incf divemins+0,F ; increase divemins
|
|
324 btfsc STATUS,Z
|
|
325 incf divemins+1,F ; and now do the realtime clock routine anyway
|
|
326
|
|
327 RTCisr1a:
|
|
328 btfss FLAG_apnoe_mode ; Are we in Apnoe mode?
|
|
329 bra RTCisr2 ; No, skip the following
|
|
330
|
|
331 incf apnoe_secs,F ; increase descent registers
|
|
332 movlw d'59'
|
|
333 cpfsgt apnoe_secs
|
|
334 bra RTCisr2
|
|
335 clrf apnoe_secs
|
|
336
|
|
337 incf apnoe_mins,F ; increase descent mins
|
|
338 ; Now, do the RTC routine....
|
|
339 RTCisr2:
|
|
340 incf secs,F ; adjusts seconds, minutes, hours, day, month and year. Checks for a leap year and works until 2099!
|
|
341 movlw d'59'
|
|
342 cpfsgt secs
|
|
343 return
|
|
344 clrf secs
|
|
345 bsf oneminupdate
|
|
346 incf mins,F
|
|
347 movlw d'59'
|
|
348 cpfsgt mins
|
|
349 return
|
|
350 clrf mins
|
|
351 incf hours,F
|
|
352 movlw d'23'
|
|
353 cpfsgt hours
|
|
354 return
|
|
355 clrf hours
|
13
|
356 incf day,F
|
|
357 movlw plus_time_correction ; Correct too slow clock
|
|
358 movwf secs
|
|
359
|
|
360
|
0
|
361 check_date:
|
|
362 movff month,isr_divB ; new month?
|
|
363 dcfsnz isr_divB,F
|
|
364 movlw .31
|
|
365 dcfsnz isr_divB,F
|
|
366 movlw .28
|
|
367 dcfsnz isr_divB,F
|
|
368 movlw .31
|
|
369 dcfsnz isr_divB,F
|
|
370 movlw .30
|
|
371 dcfsnz isr_divB,F
|
|
372 movlw .31
|
|
373 dcfsnz isr_divB,F
|
|
374 movlw .30
|
|
375 dcfsnz isr_divB,F
|
|
376 movlw .31
|
|
377 dcfsnz isr_divB,F
|
|
378 movlw .31
|
|
379 dcfsnz isr_divB,F
|
|
380 movlw .30
|
|
381 dcfsnz isr_divB,F
|
|
382 movlw .31
|
|
383 dcfsnz isr_divB,F
|
|
384 movlw .30
|
|
385 dcfsnz isr_divB,F
|
|
386 movlw .31
|
|
387 cpfsgt day,1
|
|
388 return
|
|
389 movlw .1
|
|
390 movwf day
|
|
391 incf month,F
|
|
392 movlw .12
|
|
393 cpfsgt month,1
|
|
394 return
|
|
395 movlw .1
|
|
396 movwf month
|
|
397 incf year,F
|
|
398 return |