annotate src/isr.asm @ 645:070528a88715

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