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