Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/isr.asm @ 831:0cf00ecf3532
CHANGE: Color-code battery % display in surface mode (Charge, Full, Normal)
author | heinrichsweikamp |
---|---|
date | Tue, 08 Dec 2015 13:44:39 +0100 |
parents | 2a0e5d884fc3 |
children |
rev | line source |
---|---|
402 | 1 |
815 | 2 ; OSTC Mk.2, 2N and 2C - diving computer code |
807
c50296c3059e
BUGFIX: Divetime had unwanted "." behind the minutes
heinrichsweikamp
parents:
789
diff
changeset
|
3 ; Copyright (C) 2015 HeinrichsWeikamp GbR |
0 | 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 | |
398
ab962c4b19d6
Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents:
392
diff
changeset
|
28 ; and provides accurate pressure (+/-1mbar stable) and temperature (0.1C stable) |
0 | 29 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
30 ;============================================================================= |
341
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
31 ; Copy a 16bit value from ISR modified registers to main registers. |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
32 ; |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
33 ; Because the ISR can happend at any time, the read should be redone if bytes |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
34 ; changed inbetween. |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
35 ; |
343
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
36 ; Trashes: WREG and TABLAT |
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
37 ; NOTE: Destination might be in any bank, so be BANK SAFE. |
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
38 ; |
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
39 SAFE_2BYTE_COPY MACRO from, to |
341
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
40 local retry |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
41 retry: |
343
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
42 movff from+1,WREG ; High byte in W. |
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
43 movff WREG,to+1 ; and destination. |
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
44 movff from+0,to+0 ; Copy low byte. |
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
45 movff from+1,TABLAT ; another bank-safe read. |
d5240792be51
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).
JeanDo
parents:
341
diff
changeset
|
46 xorwf TABLAT,W ; High byte changed ? |
341
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
47 bnz retry |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
48 ENDM |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
49 |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
50 ;============================================================================= |
0 | 51 uartint: |
52 btfsc simulatormode_active ; are we in simulatormode? | |
53 bra simulator_int ; Yes, reading is depth in m! | |
54 | |
55 movff RCREG,uart1_temp | |
56 movlw d'96' | |
57 subwf uart1_temp,F | |
58 dcfsnz uart1_temp,F ; "a" | |
59 bsf dump_external_eeprom ; set flag | |
60 dcfsnz uart1_temp,F ; "b" | |
61 bsf uart_settime ; set flag | |
62 dcfsnz uart1_temp,F ; "c" | |
63 bsf simulatormode_active ; set flag | |
64 dcfsnz uart1_temp,F ; "d" | |
65 bsf internal_eeprom_write ; set flag | |
66 dcfsnz uart1_temp,F ; "e" | |
67 bsf uart_send_hash ; set flag | |
68 dcfsnz uart1_temp,F ; "f" | |
297
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
283
diff
changeset
|
69 bsf uart_reset_battery_stats ; set flag |
0 | 70 dcfsnz uart1_temp,F ; "g" |
71 bsf uart_send_int_eeprom ; set flag | |
72 dcfsnz uart1_temp,F ; "h" | |
73 bsf uart_reset_decodata ; set flag | |
74 dcfsnz uart1_temp,F ; "i" | |
75 bsf internal_eeprom_write2 ; set flag | |
76 dcfsnz uart1_temp,F ; "j" | |
77 bsf uart_send_int_eeprom2 ; set flag | |
78 dcfsnz uart1_temp,F ; "k" | |
79 bsf uart_store_tissue_data ; set flag | |
330 | 80 dcfsnz uart1_temp,F ; "l" |
81 bsf uart_dump_screen ; set flag | |
578 | 82 dcfsnz uart1_temp,F ; "m" |
83 bsf uart_send_int_eeprom3 ; set flag | |
84 dcfsnz uart1_temp,F ; "n" | |
85 bsf internal_eeprom_write3 ; set flag | |
283
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
86 movlw 0xC1 |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
87 cpfseq RCREG ; 115200Baud Bootloader request? |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
88 bra uartint1 ; No |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
89 bsf uart_115200_bootloader ; Yes, set Flag |
0 | 90 |
91 uartint1: | |
92 movf RCREG,w ; unload RCREG in stand-alone simulator mode | |
93 bcf PIR1,RCIF ; Clear flag | |
94 bcf RCSTA,CREN ; Clear receiver status | |
95 bsf RCSTA,CREN | |
96 return | |
97 | |
98 simulator_int: | |
345 | 99 movlw 'l' ; Received 'l' dump-screen command ? |
100 xorwf RCREG,W | |
101 bnz simulator_int2 ; NO: skip | |
102 bsf uart_dump_screen ; YES: set flag | |
103 bra uartint1 ; and this is not a depth... | |
104 | |
105 simulator_int2: | |
0 | 106 btfsc standalone_simulator ; ignore in standalone simulator mode |
107 bra uartint1 | |
108 | |
21 | 109 bsf LED_blue |
0 | 110 tstfsz RCREG ; =0x00? |
111 bra simulator_int1 ; No | |
112 incf RCREG,F ; Yes, so force RCREG=1 | |
113 | |
114 simulator_int1: | |
115 movf RCREG,w ; depth in m | |
347 | 116 movwf PRODL ; Copy |
117 | |
118 movlw d'140' ; Limit to 130m | |
119 cpfslt PRODL ; compare with value in UART | |
120 movwf PRODL ; Overwrite reading | |
121 | |
122 movf PRODL,w ; depth in m | |
0 | 123 mullw d'100' ; result will be mbar |
124 movff PRODL,sim_pressure+0 ; stored for pressure overwrite | |
125 movff PRODH,sim_pressure+1 | |
126 bra uartint1 ; exit uart int | |
127 | |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
128 ;============================================================================= |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
129 |
238 | 130 switch_left_int: |
0 | 131 bcf INTCON,INT0IF ; Clear flag |
132 | |
133 btfsc T0CON,TMR0ON ; Timer0 running? | |
134 bra timer0_restart ; Yes, restart | |
135 | |
266 | 136 ; OSTC 2N has flipped screen and exchanged switches... |
137 movff win_flags,WREG ; Get into Bank0 | |
138 btfss WREG,0 | |
0 | 139 bsf switch_left ; Set flag, button press is OK |
266 | 140 btfsc WREG,0 |
141 bsf switch_right ; Set flag, button press is OK | |
0 | 142 |
143 bsf T0CON,TMR0ON ; Start Timer 0 | |
144 return | |
145 | |
146 | |
238 | 147 switch_right_int: |
0 | 148 bcf INTCON3,INT1IF ; Clear flag |
149 | |
150 btfsc T0CON,TMR0ON ; Timer0 running? | |
151 bra timer0_restart ; Yes, restart | |
152 | |
266 | 153 ; OSTC 2N has flipped screen and exchanged switches... |
154 movff win_flags,WREG ; Get into Bank0 | |
155 btfsc WREG,0 | |
156 bsf switch_left ; Set flag, button press is OK | |
157 btfss WREG,0 | |
0 | 158 bsf switch_right ; Set flag, button press is OK |
159 | |
160 bsf T0CON,TMR0ON ; Start Timer 0 | |
161 return | |
162 | |
163 timer0_restart: | |
164 bcf INTCON,TMR0IF ; Clear flag | |
715 | 165 movlw T0CON_VALUE |
166 movwf T0CON ; Timer0 | |
0 | 167 clrf TMR0H |
168 clrf TMR0L | |
169 bsf T0CON,TMR0ON ; Start Timer 0 | |
170 return | |
171 | |
172 timer0int: | |
173 bcf INTCON,TMR0IF ; Clear flag | |
174 bcf T0CON,TMR0ON ; Stop Timer 0 | |
175 clrf TMR0H | |
176 clrf TMR0L | |
177 return | |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
178 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
179 ;============================================================================= |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
180 ; |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
181 |
0 | 182 timer1int: |
183 timer1int_debug: | |
21 | 184 bcf LED_red ; LEDr off (For charge indicator) |
0 | 185 |
390 | 186 btfsc TMR1L,0 ; Wait for low clock cycle |
187 bra $-2 | |
391 | 188 btfss TMR1L,0 ; Still high? |
390 | 189 bra $-2 ; max. loop time: 61µs |
378 | 190 |
0 | 191 movlw 0x08 ; Timer1 int after 62.5ms (=16/second) |
391 | 192 cpfslt TMR1H ; Did we miss a 1/16 second? |
193 incf timer1int_counter1,F ; Yes, add extra 1/16 second | |
194 | |
195 movlw 0x08 ; Timer1 int after 62.5ms (=16/second) | |
0 | 196 subwf TMR1H,F |
391 | 197 bcf PIR1,TMR1IF ; Clear flag |
0 | 198 |
238 | 199 incf timer1int_counter1,F ; Increase timer1 counter |
200 | |
0 | 201 movlw d'15' ; One second 16 |
202 cpfsgt timer1int_counter1 | |
203 bra sensor_int_pre ; only pressure sensor | |
238 | 204 rcall RTCisr ; adjust time, then query pressure sensor |
0 | 205 |
206 sensor_int_pre: | |
238 | 207 btfsc sleepmode ; In sleepmode? |
208 return ; Yes | |
0 | 209 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
210 ; Sensor interput do poll the presure/temperature sensor, download results, |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
211 ; compute compensations, and store results in various shared variables. |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
212 ; |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
213 ; Input: interupt (every 62.5msec == 16Hz), sensor, |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
214 ; last_surfpressure:2. |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
215 ; |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
216 ; Output: amb_pressure:2, |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
217 ; temperature:2, |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
218 ; rel_pressure:2, |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
219 ; and the pressure_refresh flag. |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
220 ; |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
221 ; NOTE: averaging (4 successive value, as recommended in the MS5535 datasheet) |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
222 ; is done on private variables, to avoid trashing data while reading it |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
223 ; from the main code. |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
224 ; |
341
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
225 ; NOTE: Because there is no atomic 16bits load/stores, we need to check twice |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
226 ; the read data is correct. Ie. SAFE_2BYTE_COPY is mandatory to get |
344 | 227 ; amb_pressure, temperature or rel_pressure |
341
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
228 ; |
0 | 229 sensor_int: |
230 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep) | |
231 return | |
232 | |
238 | 233 incf timer1int_counter2,F ; counts to eight for state maschine |
0 | 234 |
238 | 235 ; State 1: Clear flags and average registers, get temperature (51us) and start pressure integration (73,5us) |
236 ; State 2: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
237 ; State 3: Get temperature (51us) and start pressure integration (73,5us) | |
238 ; State 4: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
239 ; State 5: Get temperature (51us) and start pressure integration (73,5us) | |
240 ; State 6: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
241 ; State 7: Get temperature (51us) and start pressure integration (73,5us) | |
242 ; 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 | |
243 | |
244 movff timer1int_counter2,isr_divB ; isr_divB used as temp here... | |
245 dcfsnz isr_divB,F | |
246 bra sensor_int_state1_plus_restart ; Do State 1 | |
247 dcfsnz isr_divB,F | |
248 bra sensor_int_state2 ; Do State 2 | |
249 dcfsnz isr_divB,F | |
250 bra sensor_int_state1 ; Do State 3 | |
251 dcfsnz isr_divB,F | |
252 bra sensor_int_state2 ; Do State 4 | |
253 dcfsnz isr_divB,F | |
254 bra sensor_int_state1 ; Do State 5 | |
255 dcfsnz isr_divB,F | |
256 bra sensor_int_state2 ; Do State 6 | |
257 dcfsnz isr_divB,F | |
258 bra sensor_int_state1 ; Do State 7 | |
259 ; bra sensor_int2_plus_average ; Do State 8 | |
260 | |
261 ;sensor_int2_plus_average: | |
262 rcall sensor_int_state2 | |
263 sensor_int2_plus_average2: | |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
264 bcf STATUS,C ; clear carry bit. |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
265 rrcf amb_pressure_avg+1 ; amb_pressure sum / 2 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
266 rrcf amb_pressure_avg+0 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
267 bcf STATUS,C ; clear carry bit, twice. |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
268 rrcf amb_pressure_avg+1 ; amb_pressure sum / 4 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
269 rrcf amb_pressure_avg+0 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
270 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
271 movff amb_pressure_avg+1,amb_pressure+1 ; copy into actual register |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
272 movff amb_pressure_avg+0,amb_pressure+0 |
238 | 273 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
274 bcf STATUS,C |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
275 btfsc temperature_avg+1,7 ; Copy sign bit to carry |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
276 bsf STATUS,C |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
277 rrcf temperature_avg+1 ; Signed temperature /2 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
278 rrcf temperature_avg+0 |
0 | 279 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
280 bcf STATUS,C |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
281 btfsc temperature_avg+1,7 ; Copy sign bit to carry |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
282 bsf STATUS,C |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
283 rrcf temperature_avg+1 ; Signed temperature /4 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
284 rrcf temperature_avg+0 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
285 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
286 movff temperature_avg+1,temperature+1 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
287 movff temperature_avg+0,temperature+0 |
0 | 288 |
289 bsf pressure_refresh ; Set flag! Temp and pressure were updated! | |
238 | 290 clrf timer1int_counter2 ; Then reset State counter |
0 | 291 |
292 btfss simulatormode_active ; are we in simulator mode? | |
293 bra comp_air_pressure ; no | |
294 | |
295 comp_air_pressure0: | |
398
ab962c4b19d6
Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents:
392
diff
changeset
|
296 movlw LOW d'1000' ; yes, so simulate 1bar surface pressure |
0 | 297 movwf last_surfpressure+0 |
298 movlw HIGH d'1000' | |
299 movwf last_surfpressure+1 | |
300 | |
301 comp_air_pressure: | |
302 movf last_surfpressure+0,W ; compensate airpressure | |
303 subwf amb_pressure+0,W | |
238 | 304 movwf rel_pressure+0 ; rel_pressure stores depth! |
0 | 305 |
306 movf last_surfpressure+1,W | |
307 subwfb amb_pressure+1,W | |
308 movwf rel_pressure+1 | |
238 | 309 btfss STATUS,N ; result is below zero? |
310 return | |
311 clrf rel_pressure+0 ; Yes, do not display negative depths | |
312 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive | |
0 | 313 return |
238 | 314 |
315 sensor_int_state1_plus_restart: | |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
316 clrf amb_pressure_avg+0 ; pressure average registers |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
317 clrf amb_pressure_avg+1 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
318 clrf temperature_avg+0 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
319 clrf temperature_avg+1 |
238 | 320 |
321 sensor_int_state1: | |
322 call get_temperature_value ; State 1: Get temperature | |
323 call get_pressure_start ; and start pressure integration. | |
324 return ; Done. | |
325 | |
326 sensor_int_state2: | |
327 call get_pressure_value ; State2: Get pressure (51us) | |
328 call get_temperature_start ; and start temperature integration (73,5us) | |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
329 goto calculate_compensation ; calculate temperature compensated pressure (233us) |
238 | 330 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
297
diff
changeset
|
331 ;============================================================================= |
0 | 332 |
333 RTCisr: | |
334 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms) | |
335 bsf onesecupdate ; we have a new second! | |
336 | |
789 | 337 btfsc sleepmode ; are we in sleep mode? |
338 bra RTCisr0 ; Yes | |
339 | |
340 movlw .1 | |
341 addwf on_time_seconds+0,F | |
342 movlw .0 | |
343 addwfc on_time_seconds+1,F | |
344 addwfc on_time_seconds+2,F ; Increase counter | |
345 | |
346 RTCisr0: | |
0 | 347 bcf STATUS,Z ; are we in dive mode? |
348 btfss divemode | |
238 | 349 bra RTCisr2 ; No, must be surface or sleepmode |
0 | 350 |
351 incf samplesecs,F ; CF20 diving seconds done | |
352 decf samplesecs_value,W ; holds CF20 value (minus 1 into WREG) | |
353 cpfsgt samplesecs | |
238 | 354 bra RTCisr1 ; no |
0 | 355 |
356 clrf samplesecs ; clear counter... | |
357 bsf store_sample ; ...and set bit for profile storage | |
238 | 358 |
0 | 359 RTCisr1: |
360 ; Increase re-setable average depth divetime counter | |
111 | 361 incf average_divesecs+0,F ; increase stopwatch registers |
0 | 362 btfsc STATUS,Z |
357
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
347
diff
changeset
|
363 incf average_divesecs+1,F ; increase stopwatch registers |
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
347
diff
changeset
|
364 ; Increase total divetime (Regardless of CF01) |
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
347
diff
changeset
|
365 incf total_divetime_seconds+0,F ; increase stopwatch registers |
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
347
diff
changeset
|
366 btfsc STATUS,Z |
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
347
diff
changeset
|
367 incf total_divetime_seconds+1,F ; increase stopwatch registers |
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
347
diff
changeset
|
368 |
0 | 369 btfss divemode2 ; displayed divetime is running? |
370 bra RTCisr2 ; No (e.g. too shallow) | |
371 | |
357
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
347
diff
changeset
|
372 ; increase divetime registers (Displayed dive time) |
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
347
diff
changeset
|
373 incf divesecs,F |
0 | 374 movlw d'59' |
375 cpfsgt divesecs | |
376 bra RTCisr1a | |
238 | 377 |
0 | 378 clrf divesecs |
379 bsf realdive ; this bit is always set (again) if the dive is longer then one minute | |
380 | |
381 incf divemins+0,F ; increase divemins | |
382 btfsc STATUS,Z | |
383 incf divemins+1,F ; and now do the realtime clock routine anyway | |
384 | |
385 RTCisr1a: | |
386 btfss FLAG_apnoe_mode ; Are we in Apnoe mode? | |
387 bra RTCisr2 ; No, skip the following | |
388 | |
389 incf apnoe_secs,F ; increase descent registers | |
390 movlw d'59' | |
391 cpfsgt apnoe_secs | |
392 bra RTCisr2 | |
393 clrf apnoe_secs | |
394 | |
395 incf apnoe_mins,F ; increase descent mins | |
396 ; Now, do the RTC routine.... | |
397 RTCisr2: | |
398 incf secs,F ; adjusts seconds, minutes, hours, day, month and year. Checks for a leap year and works until 2099! | |
356 | 399 movlw d'60' |
359 | 400 cpfseq secs ; Secs == 60 ? |
401 return ; NO : done. | |
402 clrf secs ; YES: increment minutes instead... | |
0 | 403 bsf oneminupdate |
497
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
404 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
405 btfss divemode ; In Divemode? |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
406 rcall check_nofly_desat_time ; No, so reduce NoFly and Desat and increase interval |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
407 |
0 | 408 incf mins,F |
409 movlw d'59' | |
410 cpfsgt mins | |
411 return | |
412 clrf mins | |
413 incf hours,F | |
414 movlw d'23' | |
415 cpfsgt hours | |
416 return | |
417 clrf hours | |
13 | 418 incf day,F |
392 | 419 movff time_correction_value,secs ; Correct too slow clock |
13 | 420 |
0 | 421 check_date: |
422 movff month,isr_divB ; new month? | |
423 dcfsnz isr_divB,F | |
424 movlw .31 | |
425 dcfsnz isr_divB,F | |
426 movlw .28 | |
427 dcfsnz isr_divB,F | |
428 movlw .31 | |
429 dcfsnz isr_divB,F | |
430 movlw .30 | |
431 dcfsnz isr_divB,F | |
432 movlw .31 | |
433 dcfsnz isr_divB,F | |
434 movlw .30 | |
435 dcfsnz isr_divB,F | |
436 movlw .31 | |
437 dcfsnz isr_divB,F | |
438 movlw .31 | |
439 dcfsnz isr_divB,F | |
440 movlw .30 | |
441 dcfsnz isr_divB,F | |
442 movlw .31 | |
443 dcfsnz isr_divB,F | |
444 movlw .30 | |
445 dcfsnz isr_divB,F | |
446 movlw .31 | |
447 cpfsgt day,1 | |
448 return | |
449 movlw .1 | |
450 movwf day | |
451 incf month,F | |
452 movlw .12 | |
453 cpfsgt month,1 | |
454 return | |
455 movlw .1 | |
456 movwf month | |
457 incf year,F | |
497
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
458 return |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
459 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
460 check_nofly_desat_time: |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
461 bcf nofly_active ; Clear flag |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
462 movf nofly_time+0,W ; Is nofly null ? |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
463 iorwf nofly_time+1,W |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
464 bz check_nofly_desat_time2 ; yes... |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
465 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
466 bsf nofly_active ; Set flag (again) |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
467 movlw d'1' |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
468 subwf nofly_time+0,F |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
469 movlw d'0' |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
470 subwfb nofly_time+1,F ; reduce by one |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
471 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
472 check_nofly_desat_time2: |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
473 movff desaturation_time_buffer+0,lo |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
474 movff desaturation_time_buffer+1,hi |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
475 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
476 movf lo,W ; Is Desat null ? |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
477 iorwf hi,W |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
478 bz check_nofly_desat_time3 ; yes... |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
479 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
480 movlw d'1' |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
481 subwf lo,F |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
482 movlw d'0' |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
483 subwfb hi,F ; reduce by one... |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
484 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
485 movff lo,desaturation_time_buffer+0 ; ...and copy back |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
486 movff hi,desaturation_time_buffer+1 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
487 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
488 check_nofly_desat_time3: |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
489 ; Now increase interval timer |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
490 movff desaturation_time_buffer+0,lo |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
491 movff desaturation_time_buffer+1,hi |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
492 tstfsz lo ;=0? |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
493 bra calc_surface_interval2 ; No |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
494 tstfsz hi ;=0? |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
495 bra calc_surface_interval2 ; No |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
496 clrf surface_interval+0 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
497 clrf surface_interval+1 ; Clear surface interval timer |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
498 return ; Done. |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
499 |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
500 calc_surface_interval2: ; Increase surface interval timer |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
501 movlw d'1' |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
502 addwf surface_interval+0,F |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
503 movlw d'0' |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
504 addwfc surface_interval+1,F |
06db5dd9149f
show numeric _and_ graphic velocity, move desat, nofly and interval into isr
heinrichsweikamp
parents:
402
diff
changeset
|
505 return ; Done |