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
|
266
|
90 ; OSTC 2N has flipped screen and exchanged switches...
|
|
91 movff win_flags,WREG ; Get into Bank0
|
|
92 btfss WREG,0
|
0
|
93 bsf switch_left ; Set flag, button press is OK
|
266
|
94 btfsc WREG,0
|
|
95 bsf switch_right ; Set flag, button press is OK
|
0
|
96
|
|
97 bsf T0CON,TMR0ON ; Start Timer 0
|
|
98 return
|
|
99
|
|
100
|
238
|
101 switch_right_int:
|
0
|
102 bcf INTCON3,INT1IF ; Clear flag
|
|
103
|
|
104 btfsc T0CON,TMR0ON ; Timer0 running?
|
|
105 bra timer0_restart ; Yes, restart
|
|
106
|
266
|
107 ; OSTC 2N has flipped screen and exchanged switches...
|
|
108 movff win_flags,WREG ; Get into Bank0
|
|
109 btfsc WREG,0
|
|
110 bsf switch_left ; Set flag, button press is OK
|
|
111 btfss WREG,0
|
0
|
112 bsf switch_right ; Set flag, button press is OK
|
|
113
|
|
114 bsf T0CON,TMR0ON ; Start Timer 0
|
|
115 return
|
|
116
|
|
117 timer0_restart:
|
|
118 bcf INTCON,TMR0IF ; Clear flag
|
|
119 clrf T0CON ; Timer0
|
|
120 clrf TMR0H
|
|
121 clrf TMR0L
|
|
122 bsf T0CON,TMR0ON ; Start Timer 0
|
|
123 return
|
|
124
|
|
125 timer0int:
|
|
126 bcf INTCON,TMR0IF ; Clear flag
|
|
127 bcf T0CON,TMR0ON ; Stop Timer 0
|
|
128 clrf TMR0H
|
|
129 clrf TMR0L
|
|
130 return
|
|
131
|
|
132 timer1int:
|
|
133 bcf PIR1,TMR1IF ; Clear flag
|
|
134
|
|
135 timer1int_debug:
|
21
|
136 bcf LED_red ; LEDr off (For charge indicator)
|
0
|
137
|
|
138 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
|
|
139 cpfslt TMR1H ; Did we miss a 1/16 second?
|
|
140 incf timer1int_counter1,F ; Yes, add extra 1/16 second
|
|
141
|
|
142 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
|
|
143 subwf TMR1H,F
|
|
144
|
238
|
145 incf timer1int_counter1,F ; Increase timer1 counter
|
|
146
|
0
|
147 movlw d'15' ; One second 16
|
|
148 cpfsgt timer1int_counter1
|
|
149 bra sensor_int_pre ; only pressure sensor
|
238
|
150 rcall RTCisr ; adjust time, then query pressure sensor
|
0
|
151
|
|
152 sensor_int_pre:
|
238
|
153 btfsc sleepmode ; In sleepmode?
|
|
154 return ; Yes
|
0
|
155
|
|
156 sensor_int:
|
|
157 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep)
|
|
158 return
|
|
159
|
238
|
160 incf timer1int_counter2,F ; counts to eight for state maschine
|
0
|
161
|
238
|
162 ; State 1: Clear flags and average registers, get temperature (51us) and start pressure integration (73,5us)
|
|
163 ; State 2: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
|
|
164 ; State 3: Get temperature (51us) and start pressure integration (73,5us)
|
|
165 ; State 4: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
|
|
166 ; State 5: Get temperature (51us) and start pressure integration (73,5us)
|
|
167 ; State 6: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
|
|
168 ; State 7: Get temperature (51us) and start pressure integration (73,5us)
|
|
169 ; 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
|
|
170
|
|
171 movff timer1int_counter2,isr_divB ; isr_divB used as temp here...
|
|
172 dcfsnz isr_divB,F
|
|
173 bra sensor_int_state1_plus_restart ; Do State 1
|
|
174 dcfsnz isr_divB,F
|
|
175 bra sensor_int_state2 ; Do State 2
|
|
176 dcfsnz isr_divB,F
|
|
177 bra sensor_int_state1 ; Do State 3
|
|
178 dcfsnz isr_divB,F
|
|
179 bra sensor_int_state2 ; Do State 4
|
|
180 dcfsnz isr_divB,F
|
|
181 bra sensor_int_state1 ; Do State 5
|
|
182 dcfsnz isr_divB,F
|
|
183 bra sensor_int_state2 ; Do State 6
|
|
184 dcfsnz isr_divB,F
|
|
185 bra sensor_int_state1 ; Do State 7
|
|
186 ; bra sensor_int2_plus_average ; Do State 8
|
|
187
|
|
188 ;sensor_int2_plus_average:
|
|
189 rcall sensor_int_state2
|
|
190 sensor_int2_plus_average2:
|
0
|
191 bcf STATUS,C
|
|
192 rrcf isr3_temp+1 ; isr3_temp / 2
|
|
193 rrcf isr3_temp+0
|
|
194 bcf STATUS,C
|
|
195 rrcf temperature_temp+1 ; temperature_temp /2
|
|
196 rrcf temperature_temp+0
|
238
|
197
|
|
198 bcf STATUS,C
|
|
199 rrcf isr3_temp+1 ; isr3_temp / 4
|
|
200 rrcf isr3_temp+0
|
|
201 bcf STATUS,C
|
|
202 rrcf temperature_temp+1 ; temperature_temp /4
|
|
203 rrcf temperature_temp+0
|
|
204
|
0
|
205 movff isr3_temp+1,amb_pressure+1 ; copy into actual register
|
|
206 movff isr3_temp+0,amb_pressure+0
|
|
207
|
|
208 movff temperature_temp+1,temperature+1
|
|
209 movff temperature_temp+0,temperature+0
|
|
210
|
|
211 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
|
238
|
212 clrf timer1int_counter2 ; Then reset State counter
|
0
|
213
|
|
214 btfss simulatormode_active ; are we in simulator mode?
|
|
215 bra comp_air_pressure ; no
|
|
216
|
|
217 comp_air_pressure0:
|
|
218 movlw LOW d'1000' ; yes, so simulate 1Bar surface pressure
|
|
219 movwf last_surfpressure+0
|
|
220 movlw HIGH d'1000'
|
|
221 movwf last_surfpressure+1
|
|
222
|
|
223 comp_air_pressure:
|
|
224 bcf neg_flag
|
|
225 movf last_surfpressure+0,W ; compensate airpressure
|
|
226 subwf amb_pressure+0,W
|
238
|
227 movwf rel_pressure+0 ; rel_pressure stores depth!
|
0
|
228
|
|
229 movf last_surfpressure+1,W
|
|
230 subwfb amb_pressure+1,W
|
|
231 movwf rel_pressure+1
|
238
|
232 btfss STATUS,N ; result is below zero?
|
|
233 return
|
|
234 clrf rel_pressure+0 ; Yes, do not display negative depths
|
|
235 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
|
0
|
236 return
|
238
|
237
|
|
238
|
|
239 sensor_int_state1_plus_restart:
|
|
240 bcf pressure_refresh ; clear flags
|
|
241 clrf isr3_temp+0 ; pressure average registers
|
|
242 clrf isr3_temp+1
|
|
243 clrf temperature_temp+0
|
|
244 clrf temperature_temp+1
|
|
245
|
|
246 sensor_int_state1:
|
|
247 call get_temperature_value ; State 1: Get temperature
|
|
248 call get_pressure_start ; and start pressure integration.
|
|
249 return ; Done.
|
|
250
|
|
251 sensor_int_state2:
|
|
252 call get_pressure_value ; State2: Get pressure (51us)
|
|
253 call get_temperature_start ; and start temperature integration (73,5us)
|
|
254 call calculate_compensation ; calculate temperature compensated pressure (233us)
|
|
255 movf amb_pressure+0,W
|
|
256 addwf isr3_temp+0 ; average pressure
|
|
257 movf amb_pressure+1,W
|
|
258 addwfc isr3_temp+1
|
|
259 movf temperature+0,W
|
|
260 addwf temperature_temp+0 ; average temperature
|
|
261 movf temperature+1,W
|
|
262 addwfc temperature_temp+1
|
|
263 return
|
|
264
|
0
|
265
|
|
266 RTCisr:
|
|
267 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms)
|
|
268 bsf onesecupdate ; we have a new second!
|
|
269
|
|
270 bcf STATUS,Z ; are we in dive mode?
|
|
271 btfss divemode
|
238
|
272 bra RTCisr2 ; No, must be surface or sleepmode
|
0
|
273
|
|
274 incf samplesecs,F ; CF20 diving seconds done
|
|
275 decf samplesecs_value,W ; holds CF20 value (minus 1 into WREG)
|
|
276 cpfsgt samplesecs
|
238
|
277 bra RTCisr1 ; no
|
0
|
278
|
|
279 clrf samplesecs ; clear counter...
|
|
280 bsf store_sample ; ...and set bit for profile storage
|
238
|
281
|
0
|
282 RTCisr1:
|
|
283 ; Increase re-setable average depth divetime counter
|
111
|
284 incf average_divesecs+0,F ; increase stopwatch registers
|
0
|
285 btfsc STATUS,Z
|
111
|
286 incf average_divesecs+1,F ; increase stopwatch registers
|
0
|
287
|
|
288 btfss divemode2 ; displayed divetime is running?
|
|
289 bra RTCisr2 ; No (e.g. too shallow)
|
|
290
|
|
291 incf divesecs,F ; increase divetime registers
|
|
292 movlw d'59'
|
|
293 cpfsgt divesecs
|
|
294 bra RTCisr1a
|
238
|
295
|
0
|
296 clrf divesecs
|
|
297 bsf realdive ; this bit is always set (again) if the dive is longer then one minute
|
|
298
|
|
299 incf divemins+0,F ; increase divemins
|
|
300 btfsc STATUS,Z
|
|
301 incf divemins+1,F ; and now do the realtime clock routine anyway
|
|
302
|
|
303 RTCisr1a:
|
|
304 btfss FLAG_apnoe_mode ; Are we in Apnoe mode?
|
|
305 bra RTCisr2 ; No, skip the following
|
|
306
|
|
307 incf apnoe_secs,F ; increase descent registers
|
|
308 movlw d'59'
|
|
309 cpfsgt apnoe_secs
|
|
310 bra RTCisr2
|
|
311 clrf apnoe_secs
|
|
312
|
|
313 incf apnoe_mins,F ; increase descent mins
|
|
314 ; Now, do the RTC routine....
|
|
315 RTCisr2:
|
|
316 incf secs,F ; adjusts seconds, minutes, hours, day, month and year. Checks for a leap year and works until 2099!
|
|
317 movlw d'59'
|
|
318 cpfsgt secs
|
|
319 return
|
|
320 clrf secs
|
|
321 bsf oneminupdate
|
|
322 incf mins,F
|
|
323 movlw d'59'
|
|
324 cpfsgt mins
|
|
325 return
|
|
326 clrf mins
|
|
327 incf hours,F
|
|
328 movlw d'23'
|
|
329 cpfsgt hours
|
|
330 return
|
|
331 clrf hours
|
13
|
332 incf day,F
|
43
|
333 movff time_correction_value,secs ; Correct too slow clock
|
13
|
334
|
0
|
335 check_date:
|
|
336 movff month,isr_divB ; new month?
|
|
337 dcfsnz isr_divB,F
|
|
338 movlw .31
|
|
339 dcfsnz isr_divB,F
|
|
340 movlw .28
|
|
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 dcfsnz isr_divB,F
|
|
352 movlw .31
|
|
353 dcfsnz isr_divB,F
|
|
354 movlw .30
|
|
355 dcfsnz isr_divB,F
|
|
356 movlw .31
|
|
357 dcfsnz isr_divB,F
|
|
358 movlw .30
|
|
359 dcfsnz isr_divB,F
|
|
360 movlw .31
|
|
361 cpfsgt day,1
|
|
362 return
|
|
363 movlw .1
|
|
364 movwf day
|
|
365 incf month,F
|
|
366 movlw .12
|
|
367 cpfsgt month,1
|
|
368 return
|
|
369 movlw .1
|
|
370 movwf month
|
|
371 incf year,F
|
|
372 return |