Mercurial > public > hwos_code
annotate src/isr.asm @ 632:0347acdf6d8e
changelog updates
author | heinrichsweikamp |
---|---|
date | Sat, 29 Feb 2020 16:57:45 +0100 |
parents | 185ba2f91f59 |
children | 4050675965ea |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
631 | 3 ; File isr.asm combined next generation V3.08.8 |
0 | 4 ; |
5 ; INTERUPT subroutines | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code. | |
11 | |
275 | 12 #include "hwos.inc" |
582 | 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c |
0 | 14 #include "ms5541.inc" |
15 #include "adc_lightsensor.inc" | |
623 | 16 |
17 extern restore_flash | |
0 | 18 |
19 ;============================================================================= | |
623 | 20 ; Code to be placed at fixed position |
21 ; | |
604 | 22 isr_high CODE 0x0008 ; high priority interrupts |
582 | 23 bra HighInt |
24 nop | |
25 nop | |
26 nop | |
27 nop | |
28 nop | |
29 nop | |
30 bra HighInt | |
623 | 31 ; *** low priority interrupts are not used *** |
604 | 32 isr_low CODE 0x00018 ; low priority interrupts |
623 | 33 retfie FAST ; do an immediate return with restore of BSR, STATUS and WREG |
34 | |
0 | 35 |
623 | 36 ;============================================================================= |
37 ; Interrupt Dispatcher | |
38 ; | |
0 | 39 HighInt: |
623 | 40 ; initialize interrupt code |
41 banksel isr_backup ; default bank for all ISR code is bank ISR data | |
629 | 42 movff PRODL,PROD_backup+0 ; back-up PRODL |
43 movff PRODH,PROD_backup+1 ; back-up PRODH | |
623 | 44 ; serve buttons |
45 btfsc PIR1,TMR1IF ; timer 1 interrupt (button hold-down timer)? | |
46 rcall timer1int ; YES - reset timer | |
47 btfsc INTCON,INT0IF ; right button activity? | |
48 rcall isr_switch_right ; YES - check right switch | |
49 btfsc INTCON3,INT1IF ; left button activity? | |
50 rcall isr_switch_left ; YES - check left switch | |
0 | 51 |
623 | 52 IFDEF _external_sensor |
53 ; serve IR/S8 link timer | |
54 btfsc PIR3,RC2IF ; UART 2 interrupt? | |
55 rcall isr_uart2 ; YES - get a byte from the IR/S8 link | |
56 btfsc PIR2,TMR3IF ; timer 3 interrupt? | |
57 rcall isr_timer3 ; YES - check bytes received from IR/S8 link for being a valid telegram | |
629 | 58 ELSE |
59 bcf PIR3,RC2IF ; clear UART 2 interrupt | |
60 bcf PIR2,TMR3IF ; clear timer 3 interrupt | |
61 ; fill-up to keep code size identical to _external_sensor variant, see "Attention" below | |
62 nop | |
63 nop | |
623 | 64 ENDIF |
65 | |
66 ; serve pressure and temperature sensor | |
67 btfsc PIR5,TMR7IF ; timer 7 interrupt? | |
68 rcall isr_tmr7 ; YES - do every 62.5 ms tasks: read sensors, set CPU speed | |
69 | |
70 ; serve real-time clock (RTCC) | |
71 btfsc PIR3,RTCCIF ; real-time-clock interrupt? | |
72 rcall isr_rtcc ; YES - do every 1/2 s tasks: read RTC, trigger timed tasks, adjust CPU speed, gauge battery, etc. | |
113 | 73 |
623 | 74 ; clean up and exit |
629 | 75 movff PROD_backup+0,PRODL ; restore PRODL |
76 movff PROD_backup+1,PRODH ; restore PRODH | |
623 | 77 bsf trigger_isr_updates ; signal that the ISR had kicked in |
78 retfie FAST ; return from interrupt restoring BSR, STATUS and WREG | |
79 | |
113 | 80 |
623 | 81 ;============================================================================= |
82 ; CPU speed adjustment | |
83 ; | |
84 isr_adjust_speed: | |
85 movff cpu_speed_request,cpu_speed_state ; acknowledge CPU speed request | |
0 | 86 |
623 | 87 btfsc speed_is_eco ; speed 'eco' requested? |
88 bra isr_set_speed_to_eco ; YES - set eco speed | |
89 btfsc speed_is_fastest ; NO - speed 'fastest' requested? | |
90 bra isr_set_speed_to_fastest ; YES - set fastest speed | |
91 ;bra isr_set_speed_to_normal ; NO - default to normal speed | |
0 | 92 |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
93 isr_set_speed_to_normal: |
629 | 94 clrf OSCTUNE ; switch off x4 PLL |
623 | 95 movlw b'01110010' ; select 16 MHz |
96 movwf OSCCON ; set prescaler | |
97 movlw T2CON_NORMAL ; PWM1 dimming factor for speed 'normal' | |
98 bra isr_adjust_speed_exit | |
99 | |
100 isr_set_speed_to_eco: | |
629 | 101 clrf OSCTUNE ; switch off x4 PLL |
623 | 102 movlw b'00110010' ; select 1 MHz |
103 movwf OSCCON ; set prescaler | |
104 movlw T2CON_ECO ; PWM1 dimming factor for speed 'eco' | |
105 bra isr_adjust_speed_exit | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
106 |
623 | 107 isr_set_speed_to_fastest: |
108 movlw b'01110010' ; select 16 MHz by default | |
109 btfsc lv_core ; on OSTC with low voltage core? | |
110 movlw b'01100010' ; YES - reduce to 8 MHz | |
111 movwf OSCCON ; set prescaler | |
629 | 112 bsf OSCTUNE,6 ; switch on x4 PLL -> 64 MHz on high voltage core, 32 MHz on low voltage core |
623 | 113 movlw T2CON_FASTEST ; PWM1 dimming factor for speed 'fastest' |
114 ;bra isr_adjust_speed_exit | |
115 | |
116 isr_adjust_speed_exit: | |
629 | 117 movwf T2CON ; adjust PWM1 for LED dimming |
623 | 118 btfss OSCCON,HFIOFS ; PLL stabilized? |
119 bra isr_adjust_speed_exit ; NO - loop to give it some more time | |
120 return ; YES - done | |
121 | |
122 ; Attention: fill-up the gap between the end of this section | |
123 ; and the next section which starts at 0x00080 !! | |
629 | 124 ;nop |
623 | 125 |
126 block_0_code_end: ; marker to find end of code in block 0 in linker report file | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
127 |
623 | 128 ;============================================================================= |
129 ; jump vector for the bootloader, placed at an appointed position here | |
130 ; | |
604 | 131 isr_restore CODE 0x00080 ; restore first flash page from EEPROM |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
132 restore_flash_0x00080: |
582 | 133 goto restore_flash |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
134 |
623 | 135 ;============================================================================= |
136 ; routines for handling digital-attached external sensors | |
137 ; | |
138 IFDEF _external_sensor | |
139 | |
140 ; Take a byte received on IR/S8 link and slot it into the RX buffer | |
141 ; | |
142 isr_uart2: | |
628 | 143 bcf PIR3,RC2IF ; Clear UART 2 interrupt flag |
623 | 144 banksel RCREG2 ; RC*2 is outside access RAM |
145 movff RCREG2,isr_lo ; copy received byte to isr_lo | |
146 bcf RCSTA2,CREN ; clear receiver status | |
147 bsf RCSTA2,CREN ; ... | |
148 banksel isr_backup ; back to default ISR bank | |
149 movlw .18 ; size of the buffer | |
150 cpfslt ir_s8_counter ; number of received bytes < buffer size? | |
151 bra isr_uart2_1 ; NO - buffer full, do not store the byte | |
152 movf ir_s8_counter,W ; YES - copy number of received bytes to WREG | |
153 MOVII FSR0L,FSR0_backup ; - back-up FSR0 | |
154 lfsr FSR0,ir_s8_buffer ; - load base address of buffer | |
155 movff isr_lo,PLUSW0 ; - store received byte | |
156 MOVII FSR0_backup,FSR0L ; - restore FSR0 | |
157 incf ir_s8_counter,F ; - increment number of received bytes by 1 | |
158 isr_uart2_1: | |
159 clrf TMR3L ; reload timer 3 | |
160 movlw .253 ; ... | |
161 movwf TMR3H ; ... | |
162 bsf T3CON,TMR3ON ; (re)start timeout timer 3 | |
163 return | |
164 | |
165 | |
166 ; Timeout on IR/S8 link: check the checksum and gather the received data | |
167 ; | |
168 isr_timer3: | |
604 | 169 bcf T3CON,TMR3ON ; stop timer 3 |
582 | 170 movlw .15 |
604 | 171 cpfseq ir_s8_counter ; got exactly 15 bytes? |
623 | 172 bra isr_timer3_1 ; NO - test for 16 bytes |
604 | 173 bra isr_timer3_ir ; YES - got 15 bytes, compute local checksum |
0 | 174 isr_timer3_1: |
582 | 175 movlw .16 |
604 | 176 cpfseq ir_s8_counter ; got exactly 16 bytes? |
623 | 177 bra isr_timer3_2 ; NO - test for 17 bytes |
604 | 178 tstfsz ir_s8_buffer+.15 ; YES - last byte = 0x00 ? |
179 bra isr_timer3_exit ; No - exit | |
180 bra isr_timer3_ir ; YES - got 16 bytes, compute local checksum | |
113 | 181 isr_timer3_2: |
582 | 182 movlw .17 |
604 | 183 cpfseq ir_s8_counter ; got exactly 17 bytes? |
184 bra isr_timer3_exit ; NO - exit | |
185 bra isr_timer3_s8 ; YES - S8 data | |
0 | 186 |
623 | 187 ; Process telegram received on IR link |
188 isr_timer3_ir: | |
189 movlw .12 ; checksum shall be computed for 1st and next 12 bytes | |
190 rcall compute_IR_S8_checksum ; compute checksum | |
191 movf ir_s8_buffer+.13,W ; get low byte of the received checksum | |
192 cpfseq isr_mpr+0 ; = low byte of the calculated local checksum? | |
193 bra isr_timer3_exit ; NO - exit | |
194 movf ir_s8_buffer+.14,W ; get high byte of the received checksum | |
195 cpfseq isr_mpr+1 ; = high byte of the calculated local checksum? | |
196 bra isr_timer3_exit ; NO - exit | |
197 ; YES to both - received telegram valid, copy data | |
0 | 198 |
623 | 199 movff ir_s8_buffer+.1, hud_status_byte |
200 movff ir_s8_buffer+.2, sensor1_mv+0 | |
201 movff ir_s8_buffer+.3, sensor1_mv+1 | |
202 movff ir_s8_buffer+.4, sensor2_mv+0 | |
203 movff ir_s8_buffer+.5, sensor2_mv+1 | |
204 movff ir_s8_buffer+.6, sensor3_mv+0 | |
205 movff ir_s8_buffer+.7, sensor3_mv+1 | |
206 movff ir_s8_buffer+.8, sensor1_ppO2 | |
207 movff ir_s8_buffer+.9, sensor2_ppO2 | |
208 movff ir_s8_buffer+.10,sensor3_ppO2 | |
582 | 209 movff ir_s8_buffer+.11,hud_battery_mv+0 |
210 movff ir_s8_buffer+.12,hud_battery_mv+1 | |
0 | 211 |
623 | 212 bsf hud_connection_ok ; set manually for hwHUD w/o the HUD module |
213 bra isr_timer3_reload ; reload timer and exit | |
214 | |
215 ; Process telegram received on S8 link | |
216 isr_timer3_s8: | |
217 movlw .14 ; checksum shall be computed for 1st and next 14 bytes | |
218 rcall compute_IR_S8_checksum ; compute checksum | |
219 | |
220 movf ir_s8_buffer+.15,W ; get low byte of the received checksum | |
221 cpfseq isr_mpr+0 ; = low byte of the calculated local checksum? | |
222 bra isr_timer3_exit ; NO - exit | |
223 movf ir_s8_buffer+.16,W ; get high byte of the received checksum | |
224 cpfseq isr_mpr+1 ; = high byte of the calculated local checksum? | |
225 bra isr_timer3_exit ; NO - exit | |
226 ; YES to both - received telegram valid, copy data | |
227 movff ir_s8_buffer+.3, hud_status_byte | |
228 movff ir_s8_buffer+.13,hud_battery_mv+0 | |
229 movff ir_s8_buffer+.14,hud_battery_mv+1 | |
227
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
204
diff
changeset
|
230 |
623 | 231 btfsc trigger_S8_data_update ; last data already processed? |
628 | 232 bra isr_timer3_exit ; NO - skip copying new results (And not reload the timeout) |
623 | 233 bsf trigger_S8_data_update ; YES - set flag for new data available |
582 | 234 |
628 | 235 ; - copy more data |
623 | 236 movff ir_s8_buffer+.4, s8_rawdata_sensor1+0 |
237 movff ir_s8_buffer+.5, s8_rawdata_sensor1+1 | |
238 movff ir_s8_buffer+.6, s8_rawdata_sensor1+2 | |
239 movff ir_s8_buffer+.7, s8_rawdata_sensor2+0 | |
240 movff ir_s8_buffer+.8, s8_rawdata_sensor2+1 | |
241 movff ir_s8_buffer+.9, s8_rawdata_sensor2+2 | |
242 movff ir_s8_buffer+.10,s8_rawdata_sensor3+0 | |
243 movff ir_s8_buffer+.11,s8_rawdata_sensor3+1 | |
244 movff ir_s8_buffer+.12,s8_rawdata_sensor3+2 | |
245 | |
246 isr_timer3_reload: | |
247 movlw ir_timeout_value ; in multiples of 62.5 ms | |
248 movwf ir_s8_timeout ; reload timeout | |
0 | 249 isr_timer3_exit: |
604 | 250 clrf ir_s8_counter ; clear pointer |
251 bcf PIR2,TMR3IF ; clear flag | |
582 | 252 return |
0 | 253 |
254 | |
623 | 255 ; compute checksum on data in RX buffer |
256 ; | |
257 compute_IR_S8_checksum: | |
258 movwf ir_s8_counter ; initialize loop counter from WREG | |
259 movff ir_s8_buffer+0,isr_mpr+0 ; initialize low byte of the local checksum with first byte in buffer | |
260 clrf isr_mpr+1 ; clear the high byte of the local checksum | |
261 lfsr FSR0,ir_s8_buffer ; load base address of the buffer | |
262 compute_IR_S8_checksum_loop: | |
263 movf PREINC0,W ; get next byte | |
264 addwf isr_mpr+0,F ; add it to the to checksum, low byte | |
265 movlw .0 ; no explicit data to add to the high byte... | |
266 addwfc isr_mpr+1,F ; ... besides the carry | |
267 decfsz ir_s8_counter ; decrement number of bytes yet to do, all done? | |
268 bra compute_IR_S8_checksum_loop ; NO - loop | |
269 return ; YES - done | |
113 | 270 |
623 | 271 ENDIF ; _external_sensor |
113 | 272 |
0 | 273 ;============================================================================= |
274 | |
623 | 275 ;============================================================================= |
276 ; Tasks every 62.5 ms: buttons, dimming, pressure/temp sensor and CPU speed | |
277 ; | |
278 isr_tmr7: | |
582 | 279 bcf PIR5,TMR7IF ; clear flag |
623 | 280 movlw .248 ; rollover after 248 cycles -> 62.5 ms |
281 movff WREG,TMR7H ; timer 7 is outside access RAM | |
0 | 282 |
623 | 283 call get_analog_switches ; get analog readings, CAUTION: returns in bank common |
284 banksel isr_backup ;back to ISR default bank | |
285 | |
448 | 286 btfss INTCON3,INT1IE |
582 | 287 bra isr_tmr7_a |
448 | 288 btfsc analog_sw2_pressed |
623 | 289 rcall isr_switch_left ; get digital readings of left switch |
448 | 290 isr_tmr7_a: |
291 btfss INTCON,INT0IE | |
582 | 292 bra isr_tmr7_b |
448 | 293 btfsc analog_sw1_pressed |
623 | 294 rcall isr_switch_right ; get digital readings of right switch |
448 | 295 isr_tmr7_b: |
623 | 296 btfss block_sensor_interrupt ; sensor interrupts disabled? |
604 | 297 bra isr_tmr7_c ; NO - continue |
623 | 298 return ; YES - done |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
469
diff
changeset
|
299 isr_tmr7_c: |
623 | 300 movf max_CCPR1L,W ; dim value |
582 | 301 cpfseq CCPR1L ; = current PWM value? |
623 | 302 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L |
0 | 303 |
623 | 304 IFDEF _external_sensor |
305 decfsz ir_s8_timeout,F ; IR / S8 digital data still valid? | |
306 bra isr_tmr7_2 ; YES - continue | |
307 movlw ir_timeout_value ; NO - get timer reload in multiples of 62.5 ms | |
308 movwf ir_s8_timeout ; - reload the timer | |
309 btfss analog_o2_input ; - analog input available? | |
310 bra isr_tmr7_1a ; NO - clear data | |
311 btfss s8_digital_avail ; YES - S8 digital interface available? | |
312 bra isr_tmr7_2 ; NO - must be analog interface in use, keep data | |
113 | 313 isr_tmr7_1a: |
623 | 314 clrf hud_status_byte ; S8/IR timeout clears all analog input readings to zero -> fallback will be triggered when in sensor mode |
315 CLRI hud_battery_mv ; clear battery voltage | |
582 | 316 |
623 | 317 banksel sensor1_mv ; select bank where sensor data are stored |
318 CLRI sensor1_mv ; clear all sensor data | |
319 CLRI sensor2_mv ; ... | |
320 CLRI sensor3_mv ; ... | |
321 clrf sensor1_ppO2 ; ... | |
322 clrf sensor2_ppO2 ; ... | |
323 clrf sensor3_ppO2 ; ... | |
628 | 324 banksel s8_rawdata_sensor1 |
325 CLRI s8_rawdata_sensor1 ; clear all sensor data (raw data) | |
326 clrf s8_rawdata_sensor1+2 | |
327 CLRI s8_rawdata_sensor2 ; clear all sensor data (raw data) | |
328 clrf s8_rawdata_sensor2+2 | |
329 CLRI s8_rawdata_sensor3 ; clear all sensor data (raw data) | |
330 clrf s8_rawdata_sensor3+2 | |
623 | 331 banksel isr_backup ; back to ISR default bank |
332 | |
333 bsf trigger_S8_data_update ; signal a data update | |
334 ENDIF | |
582 | 335 |
0 | 336 isr_tmr7_2: |
623 | 337 btfsc block_sensor_interrupt ; sensor interrupts disabled? |
338 return ; YES - abort | |
0 | 339 |
340 isr_sensor_state2: | |
623 | 341 btfss sensor_state_counter,0 ; every 1/4 second |
342 bsf trigger_quarter_second ; set flag | |
343 | |
344 btfss speed_is_normal ; CPU running on normal speed? | |
345 rcall isr_set_speed_to_normal ; NO - set CPU speed to normal | |
582 | 346 |
623 | 347 ; update surface pressure |
348 btfss update_surface_pressure ; shall update the surface pressure? | |
349 bra isr_sensor_state2_1 ; NO | |
350 bcf update_surface_pressure ; YES - clear request flag | |
351 MOVII pressure_abs_ref,pressure_surf ; - update surface pressure | |
352 | |
353 isr_sensor_state2_1: | |
354 incf sensor_state_counter,F ; counts to eight for state machine | |
0 | 355 |
623 | 356 ; State 1: clear flags and average registers, get temperature (51 us) and start pressure integration (73.5 us) |
357 ; State 2: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) | |
358 ; State 3: get temperature (51 us) and start pressure integration (73.5 us) | |
359 ; State 4: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) | |
360 ; State 5: get temperature (51 us) and start pressure integration (73.5 us) | |
361 ; State 6: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) | |
362 ; State 7: get temperature (51 us) and start pressure integration (73.5 us) | |
363 ; State 8: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) and build average for half-second update of temperature and pressure | |
582 | 364 |
623 | 365 movff sensor_state_counter,WREG ; WREG used as temp here... |
582 | 366 dcfsnz WREG,F |
623 | 367 bra sensor_int_state1_plus_restart ; do state 1 |
582 | 368 dcfsnz WREG,F |
623 | 369 bra sensor_int_state2 ; do state 2 |
582 | 370 dcfsnz WREG,F |
623 | 371 bra sensor_int_state1 ; do state 3 |
582 | 372 dcfsnz WREG,F |
623 | 373 bra sensor_int_state2 ; do state 4 |
582 | 374 dcfsnz WREG,F |
623 | 375 bra sensor_int_state1 ; do state 5 |
582 | 376 dcfsnz WREG,F |
623 | 377 bra sensor_int_state2 ; do state 6 |
582 | 378 dcfsnz WREG,F |
623 | 379 bra sensor_int_state1 ; do state 7 |
380 | |
381 ; first, do state 2: | |
382 call get_pressure_value ; state 2: get pressure (51 us) | |
383 call get_temperature_start ; and start temperature integration (73.5 us) | |
384 call calculate_compensation ; calculate temperature compensated pressure (27 us) | |
0 | 385 |
623 | 386 ; build average for pressure |
387 bcf STATUS,C ; clear carry bit | |
388 rrcf pressure_abs_avg+1 ; divide by 2 | |
389 rrcf pressure_abs_avg+0 | |
390 bcf STATUS,C ; clear carry bit | |
391 rrcf pressure_abs_avg+1 ; divide by 2, again | |
392 rrcf pressure_abs_avg+0 | |
393 | |
629 | 394 ; copy into result register and set update flag |
623 | 395 MOVII pressure_abs_avg,pressure_abs |
629 | 396 ; bsf trigger_pres_update ; signal a pressure update |
0 | 397 |
623 | 398 ; build average for temperature |
399 bcf STATUS,C ; clear carry bit by default | |
400 btfsc temperature_avg+1,7 ; sign bit set? | |
401 bsf STATUS,C ; YES - copy sign bit to carry bit | |
402 rrcf temperature_avg+1 ; divide signed temperature by 2 | |
403 rrcf temperature_avg+0 ; ... | |
404 bcf STATUS,C ; clear carry bit by default | |
405 btfsc temperature_avg+1,7 ; sign bit set? | |
406 bsf STATUS,C ; YES - copy sign bit to carry bit | |
407 rrcf temperature_avg+1 ; divide signed temperature by 2 again (by 4 in total now) | |
408 rrcf temperature_avg+0 ; ... | |
409 MOVII temperature_avg,temperature_cur ; store final result | |
0 | 410 |
623 | 411 ; check for temperature change |
412 movf temperature_cur+0,W ; get current temperature, low byte | |
413 cpfseq temperature_last+0 ; compare with last temperature, equal? | |
414 bra isr_sensor_state2_2 ; NO - temperature has changed | |
415 movf temperature_cur+1,W ; get current temperature, high byte | |
416 cpfseq temperature_last+1 ; compare with last temperature, equal? | |
417 bra isr_sensor_state2_2 ; NO - temperature has changed | |
418 bra isr_sensor_state2_3 ; YES to both - no change | |
0 | 419 |
420 isr_sensor_state2_2: | |
623 | 421 MOVII temperature_cur,temperature_last ; store current temperature as last temperature for next round |
422 bsf trigger_temp_changed ; set flag for temperature change | |
423 | |
0 | 424 isr_sensor_state2_3: |
629 | 425 ; reset state counter |
623 | 426 clrf sensor_state_counter ; reset state counter |
427 btfss reset_max_pressure ; shall clear the max pressure? | |
428 bra isr_sensor_state2_3a ; NO - continue with checking for pressure change | |
429 bcf reset_max_pressure ; YES - clear request flag | |
430 CLRI pressure_rel_max ; - clear max. pressure | |
0 | 431 |
623 | 432 isr_sensor_state2_3a: |
433 ; check for pressure change | |
434 movf pressure_abs+0,W ; get current pressure, low byte | |
435 cpfseq pressure_abs_last+0 ; compare with last pressure, equal? | |
436 bra isr_sensor_state2_4 ; NO - pressure has changed | |
437 movf pressure_abs+1,W ; YES - get current pressure, high byte | |
438 cpfseq pressure_abs_last+1 ; - compare with last pressure, equal? | |
439 bra isr_sensor_state2_4 ; NO - pressure has changed | |
440 bra isr_sensor_state2_5 ; YES - no change | |
441 | |
442 isr_sensor_state2_4: | |
443 MOVII pressure_abs,pressure_abs_last ; store current pressure as last pressure for next round | |
444 bsf trigger_pres_cur_changed ; signal a pressure change | |
445 | |
446 isr_sensor_state2_5: | |
447 ; compute relative pressure | |
448 movf pressure_surf+0,W ; get surface pressure, low byte | |
449 subwf pressure_abs+0,W ; WREG = pressure_abs - pressure_surf (low byte) | |
450 movwf pressure_rel_cur+0 ; store relative pressure, low byte | |
451 movf pressure_surf+1,W ; get surface pressure, high byte | |
452 subwfb pressure_abs+1,W ; WREG = pressure_abs - pressure_surf (high byte) | |
453 movwf pressure_rel_cur+1 ; store relative pressure, high byte | |
454 btfss STATUS,N ; relative pressure < 0 ? | |
455 bra isr_sensor_state2_6 ; NO - OK, keep result | |
456 CLRI pressure_rel_cur ; YES - set relative pressure to zero | |
0 | 457 |
623 | 458 isr_sensor_state2_6: |
459 ; check for new max relative pressure | |
460 movf pressure_rel_cur+0,W ; get current relative pressure, low byte | |
461 subwf pressure_rel_max+0,W ; WREG = pressure_rel_max - pressure_rel_cur (low byte) | |
462 movf pressure_rel_cur+1,W ; get current relative pressure, high byte | |
463 subwfb pressure_rel_max+1,W ; WREG = pressure_rel_max - pressure_rel_cur (high byte) | |
464 btfss STATUS,N ; result < 0, i.e. new max rel pressure? | |
465 bra isr_sensor_state2_6a ; NO | |
466 MOVII pressure_rel_cur,pressure_rel_max ; YES - set new max rel pressure | |
467 bsf trigger_pres_max_changed ; - signal a pressure max change | |
468 | |
469 isr_sensor_state2_6a: | |
0 | 470 |
623 | 471 IFDEF _min_depth_option |
472 ; check if min/max pressures shall be reset | |
473 btfss reset_trip_pressure ; shall reset the resettable min/max pressures? | |
474 bra isr_sensor_state2_6b ; NO | |
475 bcf reset_trip_pressure ; YES - clear request flag | |
476 CLRI pressure_rel_max_trip ; - set max pressure to zero | |
477 SETI pressure_rel_min_trip ; - set min pressure to biggest value possible | |
478 isr_sensor_state2_6b: | |
479 ; check for new resettable max relative pressure | |
480 movf pressure_rel_cur+0,W ; get current relative pressure, low byte | |
481 subwf pressure_rel_max_trip+0,W ; WREG = pressure_rel_max - pressure_rel_cur (low byte) | |
482 movf pressure_rel_cur+1,W ; get current relative pressure, high byte | |
483 subwfb pressure_rel_max_trip+1,W ; WREG = pressure_rel_max - pressure_rel_cur (high byte) | |
484 btfss STATUS,N ; result < 0, i.e. new max rel pressure? | |
485 bra isr_sensor_state2_6c ; NO - continue checking for min depth | |
486 MOVII pressure_rel_cur,pressure_rel_max_trip ; YES - set new max rel pressure | |
487 isr_sensor_state2_6c: | |
488 ; check for new resettable min relative pressure | |
489 movf pressure_rel_cur+0,W ; get current relative pressure, low byte | |
490 subwf pressure_rel_min_trip+0,W ; WREG = pressure_rel_min - pressure_rel_cur (low byte) | |
491 movf pressure_rel_cur+1,W ; get current relative pressure, high byte | |
492 subwfb pressure_rel_min_trip+1,W ; WREG = pressure_rel_min - pressure_rel_cur (high byte) | |
493 btfss STATUS,C ; result > 0, i.e. new min rel pressure? | |
494 bra sensor_int_state_exit ; NO - done | |
495 MOVII pressure_rel_cur,pressure_rel_min_trip ; YES - set new min rel pressure | |
496 ENDIF ; _min_depth_option | |
497 bra sensor_int_state_exit ; done | |
0 | 498 |
499 | |
500 sensor_int_state1_plus_restart: | |
623 | 501 ; clear average registers |
502 CLRI pressure_abs_avg | |
503 CLRI temperature_avg | |
0 | 504 |
505 sensor_int_state1: | |
604 | 506 call get_temperature_value ; state 1: get temperature... |
507 call get_pressure_start ; ...and start pressure integration | |
582 | 508 bra sensor_int_state_exit |
0 | 509 |
510 sensor_int_state2: | |
604 | 511 call get_pressure_value ; state 2: get pressure (51 us)... |
512 call get_temperature_start ; ...and start temperature integration (73.5 us) | |
513 call calculate_compensation ; .. and calculate temperature compensated pressure (233 us) | |
582 | 514 |
0 | 515 sensor_int_state_exit: |
623 | 516 bra isr_adjust_speed ; set/restore CPU speed and return |
517 | |
518 | |
519 isr_dimm_tft: ; adjust until max_CCPR1L = CCPR1L | |
628 | 520 btfsc screen_type3 ; screen type 3 ? |
521 return ; YES - ignore, no dimming function with screen type 3 | |
623 | 522 btfsc tft_is_dimming ; is the display dimming? |
523 return ; YES - ignore | |
524 movf max_CCPR1L,W ; NO - proceed | |
628 | 525 cpfsgt CCPR1L ; - CCPR1L > max_CCPR1L ? |
526 bra isr_dimm_tft2 ; NO - dim up | |
527 decf CCPR1L,F ; YES - dim down | |
528 return ; - done | |
623 | 529 isr_dimm_tft2: |
628 | 530 movf max_CCPR1L,W ; |
531 sublw ambient_light_min_eco ; | |
623 | 532 cpfsgt CCPR1L ; CCPR1L > max_CCPR1L - ambient_light_min_eco ? |
533 bra isr_dimm_tft3 ; NO - dim up slow | |
628 | 534 movlw .10 ; YES - dim up faster (+10) |
535 addwf CCPR1L,F ; - add to dimming value | |
623 | 536 isr_dimm_tft3: |
628 | 537 incf CCPR1L,F ; - dim up (+1) |
538 return ; - done | |
623 | 539 |
582 | 540 |
0 | 541 ;============================================================================= |
623 | 542 ; RTC interrupt on every 1/2 second |
543 ; | |
544 isr_rtcc: | |
545 bcf PIR3,RTCCIF ; clear flag | |
546 bsf trigger_half_second ; set flag for a new 1/2 second has begun | |
547 btfsc reset_timebase ; shall reset the timebase? | |
548 bra isr_rtcc_1 ; YES - warp to new full second | |
549 btg timebase_0sec ; NO - toggle the 1/2 second timebase | |
550 btfsc timebase_0sec ; - did it toggled 1 -> 0 ? | |
551 return ; NO - on half second, done | |
0 | 552 |
623 | 553 isr_rtcc_1: |
554 ; new full second | |
555 bsf trigger_full_second ; set flag for a new 1/1 second has begun | |
556 | |
557 btfsc block_rtc_access ; ISR suspended from accessing the RTC? | |
558 bra isr_rtcc_2 ; YES | |
559 | |
560 banksel RTCCFG ; RTC registers are outside access RAM | |
582 | 561 bsf RTCCFG,RTCPTR1 |
623 | 562 bsf RTCCFG,RTCPTR0 |
563 banksel isr_backup ; back to ISR default bank | |
564 | |
565 movff RTCVALL,rtc_year ; read year in BCD | |
566 movff RTCVALH,rtc_day ; dummy read | |
567 movff RTCVALL,rtc_day ; read day in BCD | |
568 movff RTCVALH,rtc_month ; read month in BCD | |
569 movff RTCVALL,rtc_hour ; read hour in BCD | |
570 movff RTCVALH,rtc_secs ; dummy read | |
571 movff RTCVALL,rtc_secs ; read seconds in BCD | |
572 movff RTCVALH,rtc_mins ; read minutes in BCD | |
582 | 573 |
574 ; Convert BCD to DEC and set registers | |
623 | 575 movf rtc_mins,W |
576 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
577 movwf rtc_mins | |
578 movf rtc_secs,W | |
579 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
580 movwf rtc_secs | |
581 movf rtc_hour,W | |
582 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
583 movwf rtc_hour | |
584 movf rtc_month,W | |
585 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
586 movwf rtc_month | |
587 movf rtc_day,W | |
588 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
589 movwf rtc_day | |
590 movf rtc_year,W | |
591 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
592 movwf rtc_year | |
593 | |
594 isr_rtcc_2: | |
629 | 595 ; every full second - get ambient light level and set max_CCPR1L |
623 | 596 call get_ambient_level ; get ambient light level and set max_CCPR1L |
597 banksel isr_backup ; back to ISR default bank (for safety only) | |
598 | |
599 rcall isr_battery_gauge ; calculate the current charge consumption and add it to the battery gauge | |
600 rcall isr_update_uptime ; increment overall OSTC uptime | |
601 rcall isr_update_timeout ; process the timeout timer | |
602 | |
603 btfsc divemode ; in dive mode? | |
604 rcall isr_divemode_1sec ; YES - do the every second dive mode tasks | |
605 | |
629 | 606 ; increment surface interval counted in seconds |
623 | 607 btfsc divemode ; in dive mode? |
608 btfsc simulatormode ; YES - in simulator mode? | |
629 | 609 rcall inc_surface_interval_secs ; NO - YES - increment the surface interval (seconds timer) |
610 | |
611 ; reset the surface interval timers if requested | |
612 btfsc reset_surface_interval ; shall reset both surface interval timers? | |
631 | 613 call rst_surface_interval ; YES |
0 | 614 |
623 | 615 ; reset the timebase if requested |
616 btfss reset_timebase ; shall reset the timebase? | |
617 bra isr_rtcc_3 ; NO | |
618 bcf reset_timebase ; YES - clear request flag | |
619 clrf eventbase ; - clear all pending events | |
620 clrf timebase ; - clear all timebase flags | |
621 clrf timebase_secs ; - clear seconds timer | |
622 clrf timebase_mins ; - clear minutes timer | |
623 clrf simulator_time ; - clear minutes timer of simulator runtime as well | |
624 bsf trigger_half_second ; - set flag for a new 1/2 second has begun | |
625 bsf trigger_full_second ; - set flag for a new 1/1 second has begun | |
626 return ; - done | |
627 | |
628 isr_rtcc_3: | |
629 ; count-up the 2 seconds timebase timer | |
630 btg timebase_1sec ; toggle the 1 second timer bit | |
631 btfss timebase_1sec ; did it toggled 1 -> 0 ? | |
632 btg timebase_2sec ; YES - toggle the 2 seconds timer bit | |
633 | |
634 ; count-up the seconds timer | |
635 incf timebase_secs,F ; increment seconds timer (may temporary become 60 here) | |
636 movlw .59 ; max. for seconds timer | |
637 cpfsgt timebase_secs ; seconds timer > max.? | |
638 return ; NO - done | |
0 | 639 |
623 | 640 ; new full minute |
629 | 641 clrf timebase_secs ; reset timer |
642 bsf trigger_full_minute ; set flag for a new minute has begun | |
623 | 643 |
629 | 644 ; increment surface interval counted in minutes |
645 btfsc divemode ; in dive mode? | |
646 btfsc simulatormode ; YES - in simulator mode? | |
647 rcall inc_surface_interval_mins ; NO - YES - increment surface interval (minutes timer) | |
623 | 648 |
629 | 649 btfss simulatormode ; in simulator mode? |
650 bra isr_rtcc_4 ; NO | |
651 infsnz simulator_time,F ; YES - increment real runtime of the simulator, did wrap around (became zero)? | |
652 setf simulator_time ; YES - disallow wrap-around, keep at 255 instead | |
0 | 653 |
623 | 654 isr_rtcc_4: |
629 | 655 incf timebase_mins,F ; increment minutes timer |
656 movlw .59 ; max. for minutes timer | |
657 cpfsgt timebase_mins ; minutes timer > max.? | |
658 return ; NO - done | |
623 | 659 |
660 ; new full hour | |
629 | 661 clrf timebase_mins ; YES - reset timer |
662 bsf trigger_full_hour ; - set flag for a new hour has begun | |
663 return ; - done | |
623 | 664 |
665 | |
666 ; increment overall OSTC uptime | |
667 isr_update_uptime: | |
582 | 668 incf uptime+0,F |
623 | 669 clrf WREG |
582 | 670 addwfc uptime+1,F |
671 addwfc uptime+2,F | |
672 addwfc uptime+3,F | |
623 | 673 return |
0 | 674 |
582 | 675 |
623 | 676 ; process the timeout timer |
677 isr_update_timeout: | |
678 btfsc reset_timeout ; shall reset the timeout? | |
679 bra isr_update_timeout_1 ; YES | |
680 tstfsz isr_timeout_timer ; NO - timeout timer already at zero? | |
681 decfsz isr_timeout_timer ; NO - decrement timer, reached zero now? | |
682 return ; YES / NO - nothing further to do | |
683 bsf trigger_timeout ; YES - set timeout flag | |
684 return ; - done | |
685 isr_update_timeout_1: | |
686 bcf reset_timeout ; clear request flag | |
687 bcf trigger_timeout ; clear pending timeout trigger, if any | |
688 movff isr_timeout_reload,isr_timeout_timer ; reload timer | |
689 return ; done | |
0 | 690 |
623 | 691 ;============================================================================= |
692 ; Calculate charge drawn from the battery | |
693 ; | |
694 isr_battery_gauge: | |
695 btfsc block_battery_gauge ; access to battery gauge suspended? | |
696 return ; YES - done | |
697 MOVLI current_sleepmode,isr_mpr ; NO - default to sleep mode with 100µA/3600 -> nAs | |
698 btfss sleepmode ; - in sleep mode? | |
699 rcall isr_battery_gauge2 ; NO - compute current consumption value into isr_lo and isr_hi | |
700 movf isr_mpr+0,W ; - 48 bit add of isr_mpr:2 with battery_gauge:6 | |
582 | 701 addwf battery_gauge+0,F |
623 | 702 movf isr_mpr+1,W |
582 | 703 addwfc battery_gauge+1,F |
623 | 704 clrf WREG |
582 | 705 addwfc battery_gauge+2,F |
706 addwfc battery_gauge+3,F | |
707 addwfc battery_gauge+4,F | |
708 addwfc battery_gauge+5,F | |
709 return | |
710 | |
0 | 711 isr_battery_gauge2: |
623 | 712 ; set consumption rate in nAs - nano Ampere per second |
0 | 713 ; Example: |
623 | 714 ; MOVLI .55556,isr_mpr ; 0.2 Ah / 3600 seconds per hour * 1e9s = nAs |
715 ; | |
716 ; Remark: although all the constants are named current_xxxx, in reality they mean charge! | |
0 | 717 |
623 | 718 ; Calculate current consumption for LED backlight: 47*CCPR1L+272 (according to values in hwos.inc: 115*CCPR1L+216) |
631 | 719 movlw .70 ; screen type 3 has a fix backlight current slope |
720 btfss screen_type3 ; does the OSTC have a screen type 3 ? | |
721 movf CCPR1L,W ; NO - for screen types 0, 1 and 2 get the slope from CCPR1L | |
722 mullw current_backlight_multi ; multiply with backlight factor current_backlight_multi | |
723 ADDLI current_backlight_offset,PRODL ; add backlight offset current_backlight_offset | |
623 | 724 MOVII PRODL,isr_mpr ; copy result to isr_mpr |
0 | 725 |
623 | 726 ; Add current for CPU and GPU |
727 ; cpu_speed_state = ECO 3.10 mA -> 861 nAs | |
728 ; = NORMAL 5.50 mA -> 1528 nAs | |
729 ; = FASTEST 8.04 mA -> 2233 nAs | |
730 btfss speed_is_eco ; speed = eco ? | |
731 bra isr_battery_gauge3 ; NO | |
732 ADDLI current_speed_eco,isr_mpr ; YES - add current_speed_eco to isr_mpr | |
582 | 733 bra isr_battery_gauge5 |
0 | 734 isr_battery_gauge3: |
623 | 735 btfss speed_is_normal ; speed = normal? |
736 bra isr_battery_gauge4 ; NO | |
737 ADDLI current_speed_normal,isr_mpr ; YES - add current_speed_normal to isr_mpr | |
582 | 738 bra isr_battery_gauge5 |
0 | 739 isr_battery_gauge4: |
623 | 740 ADDLI current_speed_fastest,isr_mpr ; speed is fastest, add current_speed_fastest to isr_mpr |
0 | 741 isr_battery_gauge5: |
623 | 742 btfss ir_power ; IR enabled? |
743 bra isr_battery_gauge6 ; NO | |
744 ADDLI current_ir_receiver,isr_mpr ; YES - add current_ir_receiver to isr_mpr | |
0 | 745 isr_battery_gauge6: |
623 | 746 btfss compass_enabled ; compass active? |
747 bra isr_battery_gauge7 ; NO | |
748 ADDLI current_compass,isr_mpr ; YES - add current_compass to isr_mpr | |
0 | 749 isr_battery_gauge7: |
582 | 750 return |
0 | 751 |
623 | 752 |
753 ;============================================================================= | |
754 ; Every second tasks while in dive mode | |
755 ; | |
0 | 756 isr_divemode_1sec: |
623 | 757 decfsz sampling_timer,F ; decrement sampling timer, became zero? |
758 bra isr_divemode_1sec_1 ; NO | |
759 bsf trigger_sample_divedata ; YES - set trigger flag for sampling dive data | |
760 movff sampling_rate,sampling_timer; - reload timer | |
0 | 761 |
623 | 762 isr_divemode_1sec_1: |
763 btfss reset_timebase ; shall reset the timebase? (request flag will be cleared later) | |
764 bra isr_divemode_1sec_2 ; NO | |
765 CLRI total_divetime_secs ; YES - reset total dive time, seconds (2 byte) | |
766 clrf counted_divetime_secs ; - reset counted dive time, seconds (1 byte) | |
767 CLRI counted_divetime_mins ; - reset counted dive time, minutes (2 byte) | |
768 clrf apnoe_dive_secs ; - reset apnoe dive time, seconds (1 byte) | |
769 clrf apnoe_dive_mins ; - reset apnoe dive time, minutes (1 byte) | |
770 bcf apnoe_at_surface ; - apnoe mode starts in submerged state | |
771 return ; - done | |
582 | 772 |
623 | 773 isr_divemode_1sec_2: |
774 INCI total_divetime_secs ; increase total dive time (regardless of start_dive_threshold) | |
775 btfss count_divetime ; shall the dive time be counted (regarding start_dive_threshold)? | |
629 | 776 bra isr_divemode_1sec_4 ; NO - too shallow / apnoe at surface |
623 | 777 incf counted_divetime_secs,F ; YES - increase dive time (displayed dive time) |
778 movlw d'59' ; - 60 seconds make a minute | |
779 cpfsgt counted_divetime_secs ; - next full minute reached? | |
629 | 780 bra isr_divemode_1sec_3 ; NO - continue |
623 | 781 clrf counted_divetime_secs ; YES - reset seconds to 0 |
782 INCI counted_divetime_mins ; - increase dive minutes | |
783 bsf divetime_longer_1min ; - set flag for dive time exceeding 1 minute | |
629 | 784 ;bra isr_divemode_1sec_3 ; - continue |
0 | 785 |
623 | 786 isr_divemode_1sec_3: ; submerged |
787 btfss FLAG_apnoe_mode ; in apnoe mode? | |
788 return ; NO - done | |
789 btfss apnoe_at_surface ; - been at surface before? | |
790 bra isr_divemode_1sec_3a ; NO - increment the dive time | |
791 bcf apnoe_at_surface ; YES - a new dive has begun | |
792 bsf apnoe_new_dive ; - signal a new dive has begun | |
793 clrf apnoe_surface_secs ; - clear surface seconds | |
794 clrf apnoe_surface_mins ; - clear surface minutes | |
795 clrf apnoe_dive_secs ; - clear dive seconds | |
796 clrf apnoe_dive_mins ; - clear dive minutes | |
797 MOVII pressure_rel_cur,pressure_rel_max ; - reset max pressure to current pressure | |
798 bsf trigger_pres_max_changed ; - signal a new maximum pressure | |
799 isr_divemode_1sec_3a: | |
800 incf apnoe_dive_secs,F ; increment dive time, seconds | |
801 movlw d'59' ; 60 seconds make a minute | |
802 cpfsgt apnoe_dive_secs ; next full minute reached? | |
803 return ; NO - done | |
804 clrf apnoe_dive_secs ; YES - reset seconds to 0 | |
805 incf apnoe_dive_mins,F ; - increment dive time, minutes | |
806 return ; - done | |
0 | 807 |
623 | 808 isr_divemode_1sec_4: ; at surface |
809 btfss FLAG_apnoe_mode ; in apnoe mode? | |
810 return ; NO - done | |
811 bsf apnoe_at_surface ; YES - memorize been at the surface | |
812 incf apnoe_surface_secs,F ; - increment surface time, seconds | |
813 movlw d'59' ; - 60 seconds make a minute | |
814 cpfsgt apnoe_surface_secs ; - next full minute reached? | |
815 return ; NO - done | |
816 clrf apnoe_surface_secs ; YES - reset seconds to 0 | |
817 incf apnoe_surface_mins,F ; - increment surface time, minutes | |
818 return ; - done | |
819 | |
820 | |
821 ;============================================================================= | |
822 ; BCD to Binary conversion | |
823 ; Input WREG = value in BCD | |
824 ; Output WREG = value in binary | |
825 ; | |
826 isr_rtcc_convert_BCD_DEC: | |
827 movwf isr_lo | |
828 swapf isr_lo, W | |
829 andlw 0x0F ; W = tens | |
830 rlncf WREG, W ; W = 2 * tens | |
831 subwf isr_lo, F ; 16 * tens + ones - 2*tens | |
832 subwf isr_lo, F ; 14 * tens + ones - 2*tens | |
833 subwf isr_lo, W ; 12 * tens + ones - 2*tens | |
582 | 834 return |
0 | 835 |
836 | |
837 ;============================================================================= | |
623 | 838 ; Check buttons |
839 ; | |
582 | 840 isr_switch_right: |
604 | 841 bcf INTCON,INT0IE ; disable INT0 |
582 | 842 btfss flip_screen ; 180° flipped? |
604 | 843 bsf switch_right ; set flag |
582 | 844 btfsc flip_screen ; 180° flipped? |
604 | 845 bsf switch_left ; set flag |
846 bra isr_switch_common ; continue... | |
0 | 847 |
582 | 848 isr_switch_left: |
604 | 849 bcf INTCON3,INT1IE ; disable INT1 |
582 | 850 btfss flip_screen ; 180° flipped? |
604 | 851 bsf switch_left ; set flag |
582 | 852 btfsc flip_screen ; 180° flipped? |
604 | 853 bsf switch_right ; set flag |
623 | 854 ;bra isr_switch_common ; continue... |
855 | |
0 | 856 isr_switch_common: |
623 | 857 clrf TMR1L ; load timer1 for first press |
604 | 858 movlw TMR1H_VALUE_FIRST ; in steps of 7.8125 ms |
623 | 859 movwf TMR1H ; ... |
604 | 860 bsf T1CON,TMR1ON ; start timer 1 |
861 bcf INTCON3,INT1IF ; clear flag | |
862 bcf INTCON,INT0IF ; clear flag | |
582 | 863 return |
0 | 864 |
623 | 865 |
866 ;============================================================================= | |
867 ; Button hold-down interrupt | |
868 ; | |
0 | 869 timer1int: |
604 | 870 bcf PIR1,TMR1IF ; clear flag |
871 bcf INTCON,INT0IF ; clear flag | |
872 bcf INTCON3,INT1IF ; clear flag | |
451 | 873 ; digital |
604 | 874 btfss switch_left1 ; left button hold-down? |
875 bra timer1int_left ; YES | |
876 btfss switch_right2 ; right button hold-down? | |
877 bra timer1int_right ; YES | |
582 | 878 |
623 | 879 ; analog |
604 | 880 btfsc analog_sw2_pressed ; left button hold-down? |
881 bra timer1int_left ; YES | |
882 btfsc analog_sw1_pressed ; right button hold-down? | |
883 bra timer1int_right ; YES | |
582 | 884 |
623 | 885 ; no button hold-down, stop Timer 1 |
604 | 886 bcf T1CON,TMR1ON ; stop timer 1 |
887 bsf INTCON,INT0IE ; enable INT0 | |
888 bsf INTCON3,INT1IE ; enable INT1 | |
451 | 889 return |
0 | 890 |
891 timer1int_left: | |
582 | 892 btfss flip_screen ; 180° flipped? |
604 | 893 bsf switch_left ; (re-)set flag |
582 | 894 btfsc flip_screen ; 180° flipped? |
604 | 895 bsf switch_right ; (re-)set flag |
896 bra timer1int_common ; continue | |
623 | 897 |
0 | 898 timer1int_right: |
582 | 899 btfss flip_screen ; 180° flipped? |
604 | 900 bsf switch_right ; set flag |
582 | 901 btfsc flip_screen ; 180° flipped? |
623 | 902 bsf switch_left ; (re-)set flag |
903 ;bra timer1int_common ; continue | |
904 | |
905 timer1int_common: ; load timer1 for next pressure | |
906 clrf TMR1L ; clear timer, low byte | |
907 movlw TMR1H_VALUE_CONT ; default to surface mode value | |
908 btfsc divemode ; in dive mode? | |
909 movlw TMR1H_VALUE_CONT_DIVE ; YES - overwrite with dive mode value | |
910 movwf TMR1H ; write value to timer, high byte | |
604 | 911 return ; return from timer1int with timer1 kept running |
0 | 912 |
623 | 913 |
0 | 914 ;============================================================================= |
629 | 915 ; Increment surface interval (counted in minutes and in seconds) |
623 | 916 ; |
917 ; int_O_desaturation_time is only computed while in start, surface mode, | |
629 | 918 ; menue_tree or ghostwriter. So the ISR may clock surface_interval_mins |
919 ; past the actual surface interval time. But TFT_surface_lastdive will | |
920 ; check int_O_desaturation_time and in case int_O_desaturation_time is | |
921 ; zero it will not show surface_interval_mins but surface_interval_secs instead. | |
922 ; Thus the glitch will remain invisible. | |
623 | 923 ; |
629 | 924 |
925 inc_surface_interval_secs: ; called every second when not in dive mode | |
926 incf surface_interval_secs+0,F ; increment the lowest byte | |
927 clrf WREG ; clear WREG | |
928 addwfc surface_interval_secs+1,F ; add carry from byte before, if it did wrap-around | |
929 addwfc surface_interval_secs+2,F ; add carry from byte before, if it did wrap-around | |
930 addwfc surface_interval_secs+3,F ; add carry from byte before, if it did wrap-around | |
623 | 931 return ; done |
0 | 932 |
629 | 933 inc_surface_interval_mins: ; called every minute when not in dive mode |
934 movff int_O_desaturation_time+0,isr_lo ; get desaturation time, low byte | |
935 movff int_O_desaturation_time+1,WREG ; get desaturation time, high byte | |
936 iorwf isr_lo,W ; inclusive-or low & high byte, desaturation time = 0 ? | |
937 bz clr_surface_interval_mins ; YES - reset surface interval minutes counter | |
938 INCI surface_interval_mins ; NO - increment surface interval | |
939 return ; - done | |
940 | |
631 | 941 rst_surface_interval: |
629 | 942 bcf reset_surface_interval ; reset request flag |
631 | 943 ; reset the surface interval counted in seconds |
629 | 944 clrf surface_interval_secs+0 ; reset surface interval (seconds), lowest byte |
945 clrf surface_interval_secs+1 ; ... | |
946 clrf surface_interval_secs+2 ; ... | |
947 clrf surface_interval_secs+3 ; reset surface interval (seconds), highest byte | |
631 | 948 ; reset the surface interval counted in minutes |
629 | 949 movff opt_diveTimeout,surface_interval_mins+0 ; set surface interval (minutes), low byte, to dive timeout offset |
950 clrf surface_interval_mins+1 ; reset surface interval (minutes), high byte | |
631 | 951 return ; done |
629 | 952 |
631 | 953 clr_surface_interval_mins: |
954 clrf surface_interval_mins+0 ; reset surface interval (minutes), low byte | |
955 clrf surface_interval_mins+1 ; reset surface interval (minutes), high byte | |
629 | 956 return ; done |
957 | |
631 | 958 |
0 | 959 ;============================================================================= |
960 | |
582 | 961 END |