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