Mercurial > public > hwos_code
comparison src/isr.asm @ 656:8af5aefbcdaf default tip
Update to 3.31 beta
| author | heinrichsweikamp |
|---|---|
| date | Thu, 27 Nov 2025 18:32:58 +0100 |
| parents | 75e90cd0c2c3 |
| children |
comparison
equal
deleted
inserted
replaced
| 655:c7b7b8a358cd | 656:8af5aefbcdaf |
|---|---|
| 18 | 18 |
| 19 | 19 |
| 20 ;============================================================================= | 20 ;============================================================================= |
| 21 ; Code to be placed at a fixed Position | 21 ; Code to be placed at a fixed Position |
| 22 ; | 22 ; |
| 23 isr_high CODE 0x0008 ; high priority interrupts | 23 isr_high CODE 0x00008 ; high priority interrupts |
| 24 bra HighInt ; jump to ISR | 24 bra HighInt ; jump to ISR |
| 25 | 25 |
| 26 isr_low CODE 0x00018 ; low priority interrupts *** not used *** | 26 isr_low CODE 0x00018 ; low priority interrupts *** not used *** |
| 27 retfie FAST ; do an immediate return from IRQ | 27 retfie FAST ; do an immediate return from IRQ |
| 28 ; | 28 ; |
| 45 btfsc INTCON,INT0IF ; right button activity? | 45 btfsc INTCON,INT0IF ; right button activity? |
| 46 rcall isr_switch_right ; YES - check right switch | 46 rcall isr_switch_right ; YES - check right switch |
| 47 btfsc INTCON3,INT1IF ; left button activity? | 47 btfsc INTCON3,INT1IF ; left button activity? |
| 48 rcall isr_switch_left ; YES - check left switch | 48 rcall isr_switch_left ; YES - check left switch |
| 49 | 49 |
| 50 IFDEF _external_sensor | 50 IFDEF _external_sensor_eccr |
| 51 ; serve IR/S8 link timer | 51 ; serve IR/S8 link timer |
| 52 btfsc PIR3,RC2IF ; UART 2 interrupt? | 52 btfsc PIR3,RC2IF ; UART 2 interrupt? |
| 53 rcall isr_uart2 ; YES - get a byte from the IR/S8 link | 53 rcall isr_uart2 ; YES - get a byte from the IR/S8 link |
| 54 btfsc PIR2,TMR3IF ; timer 3 interrupt? | 54 btfsc PIR2,TMR3IF ; timer 3 interrupt? |
| 55 rcall isr_timer3 ; YES - check bytes received from IR/S8 link for being a valid telegram | 55 rcall isr_timer3 ; YES - check bytes received from IR/S8 link for being a valid telegram |
| 56 ELSE | 56 ELSE |
| 57 bcf PIR3,RC2IF ; clear UART 2 interrupt | 57 bcf PIR3,RC2IF ; clear UART 2 interrupt |
| 58 bcf PIR2,TMR3IF ; clear timer 3 interrupt | 58 bcf PIR2,TMR3IF ; clear timer 3 interrupt |
| 59 ; fill-up to keep code size identical to _external_sensor variant, see "Attention" below | 59 ; fill-up to keep code size identical to _external_sensor_eccr variant, see "Attention" below |
| 60 nop | 60 nop |
| 61 nop | 61 nop |
| 62 ENDIF | 62 ENDIF |
| 63 | 63 |
| 64 ; serve pressure and temperature sensor | 64 ; serve pressure and temperature sensor |
| 111 movlw T2CON_FASTEST ; PWM1 dimming factor for speed 'fastest' | 111 movlw T2CON_FASTEST ; PWM1 dimming factor for speed 'fastest' |
| 112 bra isr_adjust_speed_exit | 112 bra isr_adjust_speed_exit |
| 113 | 113 |
| 114 ; Attention: fill-up the gap between the end of this section | 114 ; Attention: fill-up the gap between the end of this section |
| 115 ; and the next section which starts at 0x00080 !! | 115 ; and the next section which starts at 0x00080 !! |
| 116 nop | 116 ; nop |
| 117 | 117 |
| 118 block_0_code_end: ; marker to find end of code in block 0 in linker report file | 118 block_0_code_end: ; marker to find end of code in block 0 in linker report file |
| 119 | 119 |
| 120 | 120 |
| 121 ;============================================================================= | 121 ;============================================================================= |
| 142 ;----------------------------------------------------------------------------- | 142 ;----------------------------------------------------------------------------- |
| 143 ; Handle digitally-attached external Sensors | 143 ; Handle digitally-attached external Sensors |
| 144 ; | 144 ; |
| 145 ; take a byte received on IR/S8 link and slot it into the RX buffer | 145 ; take a byte received on IR/S8 link and slot it into the RX buffer |
| 146 ; | 146 ; |
| 147 IFDEF _external_sensor | 147 IFDEF _external_sensor_eccr |
| 148 | 148 |
| 149 isr_uart2: | 149 isr_uart2: |
| 150 bcf PIR3,RC2IF ; clear UART 2 interrupt flag | 150 bcf PIR3,RC2IF ; clear UART 2 interrupt flag |
| 151 banksel RCREG2 ; RC*2 is outside access RAM | 151 banksel RCREG2 ; RC*2 is outside access RAM |
| 152 movff RCREG2,isr_lo ; copy received byte to isr_lo | 152 movff RCREG2,isr_lo ; copy received byte to isr_lo |
| 153 bcf RCSTA2,CREN ; clear receiver status | 153 bcf RCSTA2,CREN ; clear receiver status |
| 154 bsf RCSTA2,CREN ; ... | 154 bsf RCSTA2,CREN ; ... |
| 155 ; movff RCREG2,TXREG2 ;mH | |
| 155 banksel isr_backup ; back to default ISR bank | 156 banksel isr_backup ; back to default ISR bank |
| 156 movlw .18 ; size of the buffer | 157 movlw .64 ; size of the buffer |
| 157 cpfslt ir_s8_counter ; number of received bytes < buffer size? | 158 cpfslt ir_s8_counter ; number of received bytes < buffer size? |
| 158 bra isr_uart2_1 ; NO - buffer full, do not store the byte | 159 bra isr_uart2_1 ; NO - buffer full, do not store the byte |
| 159 movf ir_s8_counter,W ; YES - copy number of received bytes to WREG | 160 movf ir_s8_counter,W ; YES - copy number of received bytes to WREG |
| 160 MOVII FSR0L,FSR0_backup ; - back-up FSR0 | 161 MOVII FSR0L,FSR0_backup ; - back-up FSR0 |
| 161 lfsr FSR0,ir_s8_buffer ; - load base address of buffer | 162 lfsr FSR0,ir_s8_buffer ; - load base address of buffer |
| 181 bra isr_timer3_ir ; YES - got 15 bytes, compute local checksum | 182 bra isr_timer3_ir ; YES - got 15 bytes, compute local checksum |
| 182 isr_timer3_1: | 183 isr_timer3_1: |
| 183 movlw .16 ; a IR telegram may also have 16 bytes, with last byte 0x00 | 184 movlw .16 ; a IR telegram may also have 16 bytes, with last byte 0x00 |
| 184 cpfseq ir_s8_counter ; got exactly 16 bytes? | 185 cpfseq ir_s8_counter ; got exactly 16 bytes? |
| 185 bra isr_timer3_2 ; NO - test for 17 bytes | 186 bra isr_timer3_2 ; NO - test for 17 bytes |
| 187 banksel common2 ; ir_s8_buffer is in common2 | |
| 186 tstfsz ir_s8_buffer+.15 ; YES - last byte = 0x00 ? | 188 tstfsz ir_s8_buffer+.15 ; YES - last byte = 0x00 ? |
| 187 bra isr_timer3_exit ; NO - exit | 189 bra isr_timer3_exit ; NO - exit |
| 188 bra isr_timer3_ir ; YES - got 16 bytes, compute local checksum | 190 bra isr_timer3_ir ; YES - got 16 bytes, compute local checksum |
| 189 isr_timer3_2: | 191 isr_timer3_2: |
| 190 movlw .17 ; a S8 telegram has 17 bytes | 192 movlw .17 ; a S8 telegram has 17 bytes |
| 191 cpfseq ir_s8_counter ; got exactly 17 bytes? | 193 cpfseq ir_s8_counter ; got exactly 17 bytes? |
| 194 bra isr_timer3_3 ; NO - test for 57 bytes | |
| 195 bra isr_timer3_s8 ; YES - S8 data | |
| 196 isr_timer3_3: | |
| 197 movlw .57 ; an eccr telegram has 57 bytes | |
| 198 cpfseq ir_s8_counter ; got exactly 17 bytes? | |
| 192 bra isr_timer3_exit ; NO - exit | 199 bra isr_timer3_exit ; NO - exit |
| 193 bra isr_timer3_s8 ; YES - S8 data | 200 bra isr_timer3_eccr ; YES - eccr data |
| 194 | 201 |
| 202 isr_timer3_eccr: | |
| 203 ; ; process telegram received on S8 link | |
| 204 banksel isr_backup ; default bank for all ISR code is bank ISR data | |
| 205 movlw .55 ; compute checksum over 1st and next 55 bytes | |
| 206 rcall compute_IR_S8_checksum ; compute checksum | |
| 207 | |
| 208 | |
| 209 ; tstfsz ir_s8_counter ; checksum ok? | |
| 210 ; bra isr_timer3_exit ; NO - discard data | |
| 211 | |
| 212 ; copy received data to respective variables | |
| 213 ; movff ir_s8_buffer+.1,hud_status_byte | |
| 214 movff ir_s8_buffer+.9,s8_rawdata_sensor1+0 | |
| 215 movff ir_s8_buffer+.10,s8_rawdata_sensor1+1 | |
| 216 movff ir_s8_buffer+.11,s8_rawdata_sensor1+2 | |
| 217 movff ir_s8_buffer+.12,sensor1_ppO2 | |
| 218 movff ir_s8_buffer+.13,s8_rawdata_sensor2+0 | |
| 219 movff ir_s8_buffer+.14,s8_rawdata_sensor2+1 | |
| 220 movff ir_s8_buffer+.15,s8_rawdata_sensor2+2 | |
| 221 movff ir_s8_buffer+.16,sensor2_ppO2 | |
| 222 movff ir_s8_buffer+.17,s8_rawdata_sensor3+0 | |
| 223 movff ir_s8_buffer+.18,s8_rawdata_sensor3+1 | |
| 224 movff ir_s8_buffer+.19,s8_rawdata_sensor3+2 | |
| 225 movff ir_s8_buffer+.20,sensor3_ppO2 | |
| 226 movff ir_s8_buffer+.27,hud_battery_mv+0 | |
| 227 movff ir_s8_buffer+.28,hud_battery_mv+1 ; External battery voltage in mV | |
| 228 movff ir_s8_buffer+.29,ccr_status_byte+0 | |
| 229 movff ir_s8_buffer+.30,ccr_status_byte+1 | |
| 230 | |
| 231 clrf hud_status_byte | |
| 232 | |
| 233 ; manually build HUD status byte for ccr testing | |
| 234 btfsc ccr_status_byte+0,0 | |
| 235 bsf sensor1_active | |
| 236 btfsc ccr_status_byte+0,0 | |
| 237 bsf sensor1_calibrated_ok | |
| 238 | |
| 239 | |
| 240 | |
| 241 btfsc ccr_status_byte+0,1 | |
| 242 bsf sensor2_active | |
| 243 btfsc ccr_status_byte+0,1 | |
| 244 bsf sensor2_calibrated_ok | |
| 245 | |
| 246 btfsc ccr_status_byte+0,2 | |
| 247 bsf sensor3_active | |
| 248 btfsc ccr_status_byte+0,2 | |
| 249 bsf sensor3_calibrated_ok | |
| 250 | |
| 251 bsf trigger_S8_data_update ; YES - set flag for new data available | |
| 252 ;bsf ext_input_optical | |
| 253 bsf ext_s8_full_digital ; Set flag for external S8 full digital mode | |
| 254 bsf hud_connection_ok ; set manually for eccr | |
| 255 bra isr_timer3_reload ; reload timer and exit | |
| 256 | |
| 195 ; process telegram received on IR link | 257 ; process telegram received on IR link |
| 196 isr_timer3_ir: | 258 isr_timer3_ir: |
| 259 banksel isr_backup ; default bank for all ISR code is bank ISR data | |
| 197 movlw .12 ; compute checksum over 1st and next 12 bytes | 260 movlw .12 ; compute checksum over 1st and next 12 bytes |
| 198 rcall compute_IR_S8_checksum ; compute checksum | 261 rcall compute_IR_S8_checksum ; compute checksum |
| 199 tstfsz ir_s8_counter ; checksum ok? | 262 tstfsz ir_s8_counter ; checksum ok? |
| 200 bra isr_timer3_exit ; NO - discard data | 263 bra isr_timer3_exit ; NO - discard data |
| 201 | 264 |
| 202 ; copy received data to respective variables | 265 ; copy received data to respective variables |
| 203 movff ir_s8_buffer+.1, hud_status_byte | 266 movff ir_s8_buffer+.1,hud_status_byte |
| 204 movff ir_s8_buffer+.2, sensor1_mv+0 | 267 movff ir_s8_buffer+.2,sensor1_mv+0 |
| 205 movff ir_s8_buffer+.3, sensor1_mv+1 | 268 movff ir_s8_buffer+.3,sensor1_mv+1 |
| 206 movff ir_s8_buffer+.4, sensor2_mv+0 | 269 movff ir_s8_buffer+.4,sensor2_mv+0 |
| 207 movff ir_s8_buffer+.5, sensor2_mv+1 | 270 movff ir_s8_buffer+.5,sensor2_mv+1 |
| 208 movff ir_s8_buffer+.6, sensor3_mv+0 | 271 movff ir_s8_buffer+.6,sensor3_mv+0 |
| 209 movff ir_s8_buffer+.7, sensor3_mv+1 | 272 movff ir_s8_buffer+.7,sensor3_mv+1 |
| 210 movff ir_s8_buffer+.8, sensor1_ppO2 | 273 movff ir_s8_buffer+.8,sensor1_ppO2 |
| 211 movff ir_s8_buffer+.9, sensor2_ppO2 | 274 movff ir_s8_buffer+.9,sensor2_ppO2 |
| 212 movff ir_s8_buffer+.10,sensor3_ppO2 | 275 movff ir_s8_buffer+.10,sensor3_ppO2 |
| 213 movff ir_s8_buffer+.11,hud_battery_mv+0 | 276 movff ir_s8_buffer+.11,hud_battery_mv+0 |
| 214 movff ir_s8_buffer+.12,hud_battery_mv+1 | 277 movff ir_s8_buffer+.12,hud_battery_mv+1 |
| 215 | 278 |
| 216 bsf hud_connection_ok ; set manually for hwHUD w/o the HUD module | 279 bsf hud_connection_ok ; set manually for hwHUD w/o the HUD module |
| 231 ; btfsc trigger_S8_data_update ; last data already processed? | 294 ; btfsc trigger_S8_data_update ; last data already processed? |
| 232 ; bra isr_timer3_exit ; NO - skip copying new data (and not reload the timeout) | 295 ; bra isr_timer3_exit ; NO - skip copying new data (and not reload the timeout) |
| 233 bsf trigger_S8_data_update ; YES - set flag for new data available | 296 bsf trigger_S8_data_update ; YES - set flag for new data available |
| 234 | 297 |
| 235 ; copy more received data to respective variables | 298 ; copy more received data to respective variables |
| 236 movff ir_s8_buffer+.4, s8_rawdata_sensor1+0 | 299 movff ir_s8_buffer+.4,s8_rawdata_sensor1+0 |
| 237 movff ir_s8_buffer+.5, s8_rawdata_sensor1+1 | 300 movff ir_s8_buffer+.5,s8_rawdata_sensor1+1 |
| 238 movff ir_s8_buffer+.6, s8_rawdata_sensor1+2 | 301 movff ir_s8_buffer+.6,s8_rawdata_sensor1+2 |
| 239 movff ir_s8_buffer+.7, s8_rawdata_sensor2+0 | 302 movff ir_s8_buffer+.7,s8_rawdata_sensor2+0 |
| 240 movff ir_s8_buffer+.8, s8_rawdata_sensor2+1 | 303 movff ir_s8_buffer+.8,s8_rawdata_sensor2+1 |
| 241 movff ir_s8_buffer+.9, s8_rawdata_sensor2+2 | 304 movff ir_s8_buffer+.9,s8_rawdata_sensor2+2 |
| 242 movff ir_s8_buffer+.10,s8_rawdata_sensor3+0 | 305 movff ir_s8_buffer+.10,s8_rawdata_sensor3+0 |
| 243 movff ir_s8_buffer+.11,s8_rawdata_sensor3+1 | 306 movff ir_s8_buffer+.11,s8_rawdata_sensor3+1 |
| 244 movff ir_s8_buffer+.12,s8_rawdata_sensor3+2 | 307 movff ir_s8_buffer+.12,s8_rawdata_sensor3+2 |
| 245 | 308 |
| 246 isr_timer3_reload: | 309 isr_timer3_reload: |
| 247 movlw ir_timeout_value ; get timeout value (in multiples of 62.5 ms) | 310 movlw ir_timeout_value ; get timeout value (in multiples of 62.5 ms) |
| 248 movwf ir_s8_timeout ; reload timeout counter | 311 movwf ir_s8_timeout ; reload timeout counter |
| 249 isr_timer3_exit: | 312 isr_timer3_exit: |
| 313 banksel isr_backup ; default bank for all ISR code is bank ISR data | |
| 250 clrf ir_s8_counter ; clear number of received bytes | 314 clrf ir_s8_counter ; clear number of received bytes |
| 251 bcf PIR2,TMR3IF ; clear IRQ flag | 315 bcf PIR2,TMR3IF ; clear IRQ flag |
| 252 return ; done | 316 return ; done |
| 253 | 317 |
| 254 | 318 |
| 258 compute_IR_S8_checksum: | 322 compute_IR_S8_checksum: |
| 259 movwf ir_s8_counter ; initialize loop counter from WREG | 323 movwf ir_s8_counter ; initialize loop counter from WREG |
| 260 MOVII FSR0L,FSR0_backup ; back-up FSR0 | 324 MOVII FSR0L,FSR0_backup ; back-up FSR0 |
| 261 lfsr FSR0,ir_s8_buffer ; load base address of the receive buffer | 325 lfsr FSR0,ir_s8_buffer ; load base address of the receive buffer |
| 262 movff POSTINC0,isr_mpr+0 ; initialize low byte of the calculated checksum with first byte in buffer | 326 movff POSTINC0,isr_mpr+0 ; initialize low byte of the calculated checksum with first byte in buffer |
| 263 clrf isr_mpr+1 ; clear the high byte of the calculated checksum | 327 clrf isr_mpr+1 ; clear the high byte of the calculated checksum |
| 264 compute_IR_S8_checksum_loop: | 328 compute_IR_S8_checksum_loop: |
| 265 movf POSTINC0,W ; read next byte | 329 movf POSTINC0,W ; read next byte |
| 266 addwf isr_mpr+0,F ; add it to the to checksum, low byte | 330 addwf isr_mpr+0,F ; add it to the to checksum, low byte |
| 267 movlw .0 ; no explicit data to add to the high byte... | 331 movlw .0 ; no explicit data to add to the high byte... |
| 268 addwfc isr_mpr+1,F ; ... besides the carry | 332 addwfc isr_mpr+1,F ; ... besides the carry |
| 269 decfsz ir_s8_counter,F ; decrement number of bytes yet to do, all done? | 333 decfsz ir_s8_counter,F ; decrement number of bytes yet to do, all done? |
| 270 bra compute_IR_S8_checksum_loop ; NO - loop | 334 bra compute_IR_S8_checksum_loop ; NO - loop |
| 271 movf POSTINC0,W ; YES - read low byte of the received checksum | 335 movf POSTINC0,W ; YES - read low byte of the received checksum |
| 272 cpfseq isr_mpr+0 ; - equal to low byte of the calculated checksum? | 336 cpfseq isr_mpr+0 ; - equal to low byte of the calculated checksum? |
| 273 incf ir_s8_counter,F ; NO - mark a checksum error | 337 incf ir_s8_counter,F ; NO - mark a checksum error |
| 274 movf POSTINC0,W ; - read high byte of the received checksum | 338 movf POSTINC0,W ; - read high byte of the received checksum |
| 275 cpfseq isr_mpr+1 ; - equal to high byte of the calculated checksum? | 339 cpfseq isr_mpr+1 ; - equal to high byte of the calculated checksum? |
| 276 incf ir_s8_counter,F ; NO - mark a checksum error | 340 incf ir_s8_counter,F ; NO - mark a checksum error |
| 277 MOVII FSR0_backup,FSR0L ; - restore FSR0 | 341 MOVII FSR0_backup,FSR0L ; - restore FSR0 |
| 278 return ; - done | 342 return ; - done |
| 279 | 343 |
| 280 ENDIF ; _external_sensor | 344 ENDIF ; _external_sensor_eccr |
| 281 | 345 |
| 282 | 346 |
| 283 ;----------------------------------------------------------------------------- | 347 ;----------------------------------------------------------------------------- |
| 284 ; Timer 4 - Button debounce (For new digital piezo circuit) | 348 ; Timer 4 - Button debounce (For new digital piezo circuit) |
| 285 | 349 |
| 360 isr_tmr7_4: | 424 isr_tmr7_4: |
| 361 movf max_CCPR1L,W ; dim value | 425 movf max_CCPR1L,W ; dim value |
| 362 cpfseq CCPR1L ; = current PWM value? | 426 cpfseq CCPR1L ; = current PWM value? |
| 363 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L | 427 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L |
| 364 | 428 |
| 365 IFDEF _external_sensor | 429 IFDEF _external_sensor_eccr |
| 366 | 430 |
| 367 decfsz ir_s8_timeout,F ; decrement IR/S8 timeout counter, became zero? | 431 decfsz ir_s8_timeout,F ; decrement IR/S8 timeout counter, became zero? |
| 368 bra isr_sensor_state2 ; NO - continue with sensor | 432 bra isr_sensor_state2 ; NO - continue with sensor |
| 369 movlw ir_timeout_value ; YES - get timeout value (in multiples of 62.5 ms) | 433 movlw ir_timeout_value ; YES - get timeout value (in multiples of 62.5 ms) |
| 370 movwf ir_s8_timeout ; - reload timeout timer | 434 movwf ir_s8_timeout ; - reload timeout timer |
| 371 btfsc ext_input_optical ; - optical input in use? | 435 btfsc ext_input_optical ; - optical input in use? |
| 436 bra isr_tmr7_5 ; YES - clear data | |
| 437 btfsc ext_s8_full_digital ; are we in external S8 full digital mode? | |
| 372 bra isr_tmr7_5 ; YES - clear data | 438 bra isr_tmr7_5 ; YES - clear data |
| 373 TSTOSS opt_s8_mode ; NO - S8 input in use? | 439 TSTOSS opt_s8_mode ; NO - S8 input in use? |
| 374 bra isr_sensor_state2 ; NO - must be analog interface in use, keep data | 440 bra isr_sensor_state2 ; NO - must be analog interface in use, keep data |
| 375 ;bra isr_tmr7_5 ; YES - clear data | 441 ;bra isr_tmr7_5 ; YES - clear data |
| 376 | 442 |
| 394 clrf s8_rawdata_sensor3+2 | 460 clrf s8_rawdata_sensor3+2 |
| 395 banksel isr_backup ; back to ISR default bank | 461 banksel isr_backup ; back to ISR default bank |
| 396 | 462 |
| 397 bsf trigger_S8_data_update ; signal a data update | 463 bsf trigger_S8_data_update ; signal a data update |
| 398 | 464 |
| 399 ENDIF ; _external_sensor | 465 ENDIF ; _external_sensor_eccr |
| 400 | 466 |
| 401 isr_sensor_state2: | 467 isr_sensor_state2: |
| 402 btfss speed_is_normal ; CPU running on normal speed? | 468 btfss speed_is_normal ; CPU running on normal speed? |
| 403 rcall isr_set_speed_to_normal ; NO - set CPU speed to normal | 469 rcall isr_set_speed_to_normal ; NO - set CPU speed to normal |
| 404 | 470 |
| 433 call get_pressure_value ; state 2: get pressure (51 us) | 499 call get_pressure_value ; state 2: get pressure (51 us) |
| 434 call get_temperature_start ; and start temperature integration (73.5 us) | 500 call get_temperature_start ; and start temperature integration (73.5 us) |
| 435 call calculate_compensation ; calculate temperature compensated pressure (27 us) | 501 call calculate_compensation ; calculate temperature compensated pressure (27 us) |
| 436 | 502 |
| 437 ; build average for pressure | 503 ; build average for pressure |
| 438 ;bcf STATUS,C ; clear carry bit - not needed since we don't use the +2 register later | 504 bcf STATUS,C ; clear carry bit |
| 439 rrcf pressure_abs_avg+2 ; divide by 2 | 505 rrcf pressure_abs_avg+2 ; divide by 2 |
| 440 rrcf pressure_abs_avg+1 ; ... | 506 rrcf pressure_abs_avg+1 ; ... |
| 441 rrcf pressure_abs_avg+0 ; ... | 507 rrcf pressure_abs_avg+0 ; ... |
| 442 ;bcf STATUS,C ; clear carry bit - not needed since we don't use the +2 register later | 508 bcf STATUS,C ; clear carry bit |
| 443 rrcf pressure_abs_avg+2 ; divide by 2, again | 509 rrcf pressure_abs_avg+2 ; divide by 2, again |
| 444 rrcf pressure_abs_avg+1 ; ... | 510 rrcf pressure_abs_avg+1 ; ... |
| 445 rrcf pressure_abs_avg+0 ; ... | 511 rrcf pressure_abs_avg+0 ; ... |
| 446 | 512 |
| 447 ; export averaged pressure | 513 ; export averaged pressure |
| 514 tstfsz pressure_abs_avg+2 ; must be zero for all depths < 262m | |
| 515 bra isr_sensor_state_sensor_error ; assume a false reading if <> 0 | |
| 516 | |
| 448 MOVII pressure_abs_avg,pressure_abs ; export result (Which is 16 bit for all depths < 262m) | 517 MOVII pressure_abs_avg,pressure_abs ; export result (Which is 16 bit for all depths < 262m) |
| 449 | 518 |
| 519 isr_sensor_state_sensor_resume: | |
| 450 ; build average for temperature | 520 ; build average for temperature |
| 451 bcf STATUS,C ; clear carry bit by default | 521 bcf STATUS,C ; clear carry bit by default |
| 452 btfsc temperature_avg+1,7 ; sign bit set? | 522 btfsc temperature_avg+1,7 ; sign bit set? |
| 453 bsf STATUS,C ; YES - copy sign bit to carry bit | 523 bsf STATUS,C ; YES - copy sign bit to carry bit |
| 454 rrcf temperature_avg+1 ; divide signed temperature by 2 | 524 rrcf temperature_avg+1 ; divide signed temperature by 2 |
| 456 bcf STATUS,C ; clear carry bit by default | 526 bcf STATUS,C ; clear carry bit by default |
| 457 btfsc temperature_avg+1,7 ; sign bit set? | 527 btfsc temperature_avg+1,7 ; sign bit set? |
| 458 bsf STATUS,C ; YES - copy sign bit to carry bit | 528 bsf STATUS,C ; YES - copy sign bit to carry bit |
| 459 rrcf temperature_avg+1 ; divide signed temperature by 2 again (by 4 in total now) | 529 rrcf temperature_avg+1 ; divide signed temperature by 2 again (by 4 in total now) |
| 460 rrcf temperature_avg+0 ; ... | 530 rrcf temperature_avg+0 ; ... |
| 531 | |
| 532 btfsc i2c_reinit_sensor2 ; Sensor ok? | |
| 533 bra isr_sensor_state_skip_temp ; likely not, skip updating the temperature | |
| 534 | |
| 461 MOVII temperature_avg,temperature_cur ; store final result | 535 MOVII temperature_avg,temperature_cur ; store final result |
| 462 | 536 |
| 537 isr_sensor_state_skip_temp: | |
| 463 ; check for temperature change | 538 ; check for temperature change |
| 464 movf temperature_cur+0,W ; get current temperature, low byte | 539 movf temperature_cur+0,W ; get current temperature, low byte |
| 465 cpfseq temperature_last+0 ; compare with last temperature, equal? | 540 cpfseq temperature_last+0 ; compare with last temperature, equal? |
| 466 bra isr_sensor_state2_2 ; NO - temperature has changed | 541 bra isr_sensor_state2_2 ; NO - temperature has changed |
| 467 movf temperature_cur+1,W ; get current temperature, high byte | 542 movf temperature_cur+1,W ; get current temperature, high byte |
| 567 sensor_int_state_exit: | 642 sensor_int_state_exit: |
| 568 bcf PIR5,TMR7IF ; clear IRQ flag | 643 bcf PIR5,TMR7IF ; clear IRQ flag |
| 569 bsf PIE5,TMR7IE ; re-enable IRQs by TMR7 | 644 bsf PIE5,TMR7IE ; re-enable IRQs by TMR7 |
| 570 bra isr_adjust_speed ; set/restore CPU speed and return | 645 bra isr_adjust_speed ; set/restore CPU speed and return |
| 571 | 646 |
| 572 | 647 isr_sensor_state_sensor_error: |
| 648 bsf i2c_reinit_sensor2 ; Do an I2C reset and reinitialize the pressure sensor type 2 | |
| 649 ; Done in I2C_get_press_val_MS5837 and I2C_get_temp_val_MS5837 | |
| 650 bra isr_sensor_state_sensor_resume ; Ignore the reading and continue | |
| 573 ;----------------------------------------------------------------------------- | 651 ;----------------------------------------------------------------------------- |
| 574 ; Helper Function for Display Dimming | 652 ; Helper Function for Display Dimming |
| 575 ; | 653 ; |
| 576 isr_dimm_tft: ; adjust until max_CCPR1L = CCPR1L | 654 isr_dimm_tft: ; adjust until max_CCPR1L = CCPR1L |
| 577 btfsc screen_type3 ; screen type 3 ? | 655 btfsc screen_type3 ; screen type 3 ? |
