Mercurial > public > hwos_code
annotate src/isr.asm @ 452:55dcf1b248f2
changelog
author | heinrichsweikamp |
---|---|
date | Thu, 01 Sep 2016 13:28:15 +0200 |
parents | 66049b6f2c0b |
children | b4f28ab23b87 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File isr.asm | |
4 ; | |
5 ; INTERUPT subroutines | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code. | |
11 | |
275 | 12 #include "hwos.inc" |
0 | 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c |
14 #include "ms5541.inc" | |
15 #include "adc_lightsensor.inc" | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
16 #include "eeprom_rs232.inc" |
0 | 17 |
18 ;============================================================================= | |
19 | |
20 extern start | |
21 | |
22 isr_high CODE 0x0008 ;High Priority Interrups | |
23 bra HighInt | |
24 nop | |
25 nop | |
26 nop | |
27 nop | |
28 nop | |
29 nop | |
30 bra HighInt | |
31 | |
32 isr_low CODE 0x00018 ;Low Priority Interrups | |
33 ; *** low priority interrupts not used | |
34 retfie FAST ; Restores BSR, STATUS and WREG | |
35 | |
36 HighInt: | |
37 movff PRODL,isr_prod+0 | |
38 movff PRODH,isr_prod+1 | |
39 | |
40 ; Buttons | |
41 btfsc PIR1,TMR1IF ; Timer1 INT (Button hold-down Timer) | |
42 rcall timer1int | |
43 btfsc INTCON,INT0IF ; Buttons | |
44 rcall isr_switch_right | |
45 btfsc INTCON3,INT1IF ; Buttons | |
46 rcall isr_switch_left | |
47 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
48 ; IR/S8-Link |
113 | 49 btfsc PIR3,RC2IF ; UART2 |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
50 rcall isr_uart2 ; IR/S8-Link |
0 | 51 btfsc PIR2,TMR3IF ; Timer 3 |
52 rcall isr_timer3 ; IR-Link Timeout | |
113 | 53 |
54 ; Pressure sensor and others | |
55 btfsc PIR5,TMR7IF ; Timer 7 | |
56 rcall isr_tmr7 ; Every 62,5ms | |
57 | |
0 | 58 ; RTCC |
59 btfsc PIR3,RTCCIF ; Real-time-clock interrupt | |
60 rcall isr_rtcc ; May return in bank common! | |
61 | |
62 movff isr_prod+1,PRODH | |
63 movff isr_prod+0,PRODL | |
64 retfie FAST ; Restores BSR, STATUS and WREG | |
65 | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
66 isr_set_speed_to_normal: |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
67 ; Set Speed to normal |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
68 movlw b'01110010' |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
69 movwf OSCCON ; 16MHz INTOSC |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
70 movlw b'00000000' |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
71 movwf OSCTUNE ; 4x PLL Disable (Bit6) - only works with 8 or 16MHz (=32 or 64MHz) |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
72 movlw b'00001101' ; 1:2 Postscaler, 1:4 Prescaler, Timer 2 start -> 1960Hz (no-flicker) |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
73 movwf T2CON |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
74 btfss OSCCON,HFIOFS |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
75 bra $-2 ; Wait until clock is stable |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
76 return |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
77 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
78 isr_dimm_tft: ; Adjust until max_CCPR1L=CCPR1L ! |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
79 banksel common |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
80 btfsc tft_is_dimming ; Ignore while dimming |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
81 return |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
82 banksel isr_backup |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
83 movf max_CCPR1L,W |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
84 cpfsgt CCPR1L ; CCPR1L>max_CCPR1L? |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
85 bra isr_dimm_tft2 ; No, dimm up |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
86 ; dimm down |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
87 decf CCPR1L,F ; -1 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
88 return |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
89 isr_dimm_tft2: |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
90 movf max_CCPR1L,W |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
91 sublw ambient_light_min_eco |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
92 cpfsgt CCPR1L ; CCPR1L>max_CCPR1L-ambient_light_min_eco? |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
93 bra isr_dimm_tft3 ; No, dimm up slow |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
94 ; dimm up faster |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
95 movlw .10 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
96 addwf CCPR1L,F |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
97 isr_dimm_tft3: |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
98 incf CCPR1L,F ; +1 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
99 return |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
100 nop |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
101 nop ; block flash here |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
102 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
103 isr_restore CODE 0x00080 ; Restore first flash page from EEPROM |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
104 restore_flash_0x00080: |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
105 goto restore_flash |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
106 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
107 |
0 | 108 ;============================================================================= |
109 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
110 isr_uart2: ; IR/S8-Link |
0 | 111 banksel RCREG2 |
112 movf RCREG2,W | |
113 bcf RCSTA2,CREN ; Clear receiver status | |
114 bsf RCSTA2,CREN | |
115 banksel isr_backup | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
116 incf ir_s8_counter,F ; Increase counter |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
117 movff ir_s8_counter,isr1_temp ; Copy |
0 | 118 dcfsnz isr1_temp,F |
204 | 119 movwf ir_s8_buffer+.0 |
0 | 120 dcfsnz isr1_temp,F |
204 | 121 movwf ir_s8_buffer+.1 |
0 | 122 dcfsnz isr1_temp,F |
204 | 123 movwf ir_s8_buffer+.2 |
0 | 124 dcfsnz isr1_temp,F |
204 | 125 movwf ir_s8_buffer+.3 |
0 | 126 dcfsnz isr1_temp,F |
204 | 127 movwf ir_s8_buffer+.4 |
0 | 128 dcfsnz isr1_temp,F |
204 | 129 movwf ir_s8_buffer+.5 |
0 | 130 dcfsnz isr1_temp,F |
204 | 131 movwf ir_s8_buffer+.6 |
0 | 132 dcfsnz isr1_temp,F |
204 | 133 movwf ir_s8_buffer+.7 |
0 | 134 dcfsnz isr1_temp,F |
204 | 135 movwf ir_s8_buffer+.8 |
0 | 136 dcfsnz isr1_temp,F |
204 | 137 movwf ir_s8_buffer+.9 |
0 | 138 dcfsnz isr1_temp,F |
204 | 139 movwf ir_s8_buffer+.10 |
0 | 140 dcfsnz isr1_temp,F |
204 | 141 movwf ir_s8_buffer+.11 |
0 | 142 dcfsnz isr1_temp,F |
204 | 143 movwf ir_s8_buffer+.12 |
0 | 144 dcfsnz isr1_temp,F |
204 | 145 movwf ir_s8_buffer+.13 |
0 | 146 dcfsnz isr1_temp,F |
204 | 147 movwf ir_s8_buffer+.14 |
0 | 148 dcfsnz isr1_temp,F |
204 | 149 movwf ir_s8_buffer+.15 |
113 | 150 dcfsnz isr1_temp,F |
204 | 151 movwf ir_s8_buffer+.16 |
113 | 152 dcfsnz isr1_temp,F |
204 | 153 movwf ir_s8_buffer+.17 |
113 | 154 |
0 | 155 clrf TMR3L ; Preload timer |
156 movlw .253 | |
157 movwf TMR3H | |
158 bsf T3CON,TMR3ON ; (Re)Start Timeout counter | |
159 return | |
160 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
161 isr_timer3: ; IR/S8-Link Timeout |
0 | 162 bcf T3CON,TMR3ON ; Stop Timer3 |
163 banksel isr_backup ; Select Bank0 for ISR data. | |
164 movlw .15 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
165 cpfseq ir_s8_counter ; Got exact 15bytes? |
0 | 166 bra isr_timer3_1 ; No, test for 16bytes |
113 | 167 bra isr_timer3_ir ; Got 15 bytes, compute local checksum |
0 | 168 isr_timer3_1: |
169 movlw .16 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
170 cpfseq ir_s8_counter ; Got exact 16bytes? |
113 | 171 bra isr_timer3_2 ; No, test for 17bytes |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
172 tstfsz ir_s8_buffer+.15 ; Last byte=0x00 |
0 | 173 bra isr_timer3_exit ; No, exit |
113 | 174 bra isr_timer3_ir ; Got 16 bytes, compute local checksum |
175 isr_timer3_2: | |
176 movlw .17 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
177 cpfseq ir_s8_counter ; Got exact 17bytes? |
113 | 178 bra isr_timer3_exit ; No, exit |
179 bra isr_timer3_s8 ; S8 data | |
0 | 180 |
113 | 181 isr_timer3_ir: ; IR input |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
182 movff ir_s8_buffer+.0,PRODL |
0 | 183 clrf PRODH |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
184 movf ir_s8_buffer+.1,W |
0 | 185 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
186 movf ir_s8_buffer+.2,W |
0 | 187 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
188 movf ir_s8_buffer+.3,W |
0 | 189 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
190 movf ir_s8_buffer+.4,W |
0 | 191 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
192 movf ir_s8_buffer+.5,W |
0 | 193 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
194 movf ir_s8_buffer+.6,W |
0 | 195 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
196 movf ir_s8_buffer+.7,W |
0 | 197 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
198 movf ir_s8_buffer+.8,W |
0 | 199 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
200 movf ir_s8_buffer+.9,W |
0 | 201 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
202 movf ir_s8_buffer+.10,W |
0 | 203 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
204 movf ir_s8_buffer+.11,W |
0 | 205 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
206 movf ir_s8_buffer+.12,W |
0 | 207 rcall isr_timer3_checksum |
208 | |
209 ; Compare checksum | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
210 movf ir_s8_buffer+.13,W |
0 | 211 cpfseq PRODL ; Checksum ok? |
212 bra isr_timer3_exit ; No, exit | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
213 movf ir_s8_buffer+.14,W |
0 | 214 cpfseq PRODH ; Checksum ok? |
215 bra isr_timer3_exit ; No, exit | |
216 | |
217 ; Checksum OK, copy results | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
218 movff ir_s8_buffer+.1,hud_status_byte |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
219 movff ir_s8_buffer+.2,o2_mv_sensor1+0 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
220 movff ir_s8_buffer+.3,o2_mv_sensor1+1 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
221 movff ir_s8_buffer+.4,o2_mv_sensor2+0 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
222 movff ir_s8_buffer+.5,o2_mv_sensor2+1 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
223 movff ir_s8_buffer+.6,o2_mv_sensor3+0 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
224 movff ir_s8_buffer+.7,o2_mv_sensor3+1 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
225 movff ir_s8_buffer+.8,o2_ppo2_sensor1 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
226 movff ir_s8_buffer+.9,o2_ppo2_sensor2 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
227 movff ir_s8_buffer+.10,o2_ppo2_sensor3 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
228 movff ir_s8_buffer+.11,hud_battery_mv+0 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
229 movff ir_s8_buffer+.12,hud_battery_mv+1 |
0 | 230 |
231 movlw ir_timeout_value ; multiples of 62,5ms | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
232 movwf ir_S8_timeout ; Reload timeout |
227
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
204
diff
changeset
|
233 |
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
204
diff
changeset
|
234 banksel hud_status_byte |
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
204
diff
changeset
|
235 bsf hud_connection_ok ; Set manually for hwHUD w/o the HUD module... |
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
204
diff
changeset
|
236 banksel isr_backup ; Select Bank0 for ISR data. |
0 | 237 |
238 isr_timer3_exit: | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
239 clrf ir_s8_counter ; Clear pointer |
0 | 240 bcf PIR2,TMR3IF ; Clear flag |
241 return | |
242 | |
243 isr_timer3_checksum: | |
244 addwf PRODL,F | |
245 movlw .0 | |
246 addwfc PRODH,F | |
247 return | |
248 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
249 isr_timer3_s8: ; S8 input |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
250 movff ir_s8_buffer+.0,PRODL |
113 | 251 clrf PRODH |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
252 movf ir_s8_buffer+.1,W |
113 | 253 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
254 movf ir_s8_buffer+.2,W |
113 | 255 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
256 movf ir_s8_buffer+.3,W |
113 | 257 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
258 movf ir_s8_buffer+.4,W |
113 | 259 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
260 movf ir_s8_buffer+.5,W |
113 | 261 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
262 movf ir_s8_buffer+.6,W |
113 | 263 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
264 movf ir_s8_buffer+.7,W |
113 | 265 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
266 movf ir_s8_buffer+.8,W |
113 | 267 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
268 movf ir_s8_buffer+.9,W |
113 | 269 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
270 movf ir_s8_buffer+.10,W |
113 | 271 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
272 movf ir_s8_buffer+.11,W |
113 | 273 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
274 movf ir_s8_buffer+.12,W |
113 | 275 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
276 movf ir_s8_buffer+.13,W |
113 | 277 rcall isr_timer3_checksum |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
278 movf ir_s8_buffer+.14,W |
113 | 279 rcall isr_timer3_checksum |
280 | |
281 ; Compare checksum | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
282 movf ir_s8_buffer+.15,W |
113 | 283 cpfseq PRODL ; Checksum ok? |
284 bra isr_timer3_exit ; No, exit | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
285 movf ir_s8_buffer+.16,W |
113 | 286 cpfseq PRODH ; Checksum ok? |
287 bra isr_timer3_exit ; No, exit | |
288 | |
289 ; Checksum OK, copy results | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
290 movff ir_s8_buffer+.3,hud_status_byte |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
291 movff ir_s8_buffer+.13,hud_battery_mv+0 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
292 movff ir_s8_buffer+.14,hud_battery_mv+1 |
113 | 293 |
294 banksel common | |
271 | 295 btfsc new_s8_data_available ; =1: Old data already processed? |
268
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
296 bra isr_timer3_skip ; No, skip copying new results |
113 | 297 |
268
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
298 movff ir_s8_buffer+.6,s8_rawdata_sensor1+2 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
299 movff ir_s8_buffer+.5,s8_rawdata_sensor1+1 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
300 movff ir_s8_buffer+.4,s8_rawdata_sensor1+0 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
301 movff ir_s8_buffer+.9,s8_rawdata_sensor2+2 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
302 movff ir_s8_buffer+.8,s8_rawdata_sensor2+1 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
303 movff ir_s8_buffer+.7,s8_rawdata_sensor2+0 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
304 movff ir_s8_buffer+.12,s8_rawdata_sensor3+2 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
305 movff ir_s8_buffer+.11,s8_rawdata_sensor3+1 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
306 movff ir_s8_buffer+.10,s8_rawdata_sensor3+0 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
307 banksel common |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
308 bsf new_s8_data_available ; set flag |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
309 |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
310 isr_timer3_skip: |
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
311 banksel ir_S8_timeout |
113 | 312 movlw ir_timeout_value ; multiples of 62,5ms |
268
29acdb601548
BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents:
236
diff
changeset
|
313 movwf ir_S8_timeout ; Reload timeout |
113 | 314 bra isr_timer3_exit ; Exit |
315 | |
316 | |
0 | 317 ;============================================================================= |
318 | |
319 isr_tmr7: ; each 62,5ms | |
320 bcf PIR5,TMR7IF ; clear flag | |
321 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
322 movlw .248 | |
323 movwf TMR7H ; -> Rollover after 2048 cycles -> 62,5ms | |
324 | |
325 banksel isr_backup | |
326 movf max_CCPR1L,W ; Dimm value | |
327 cpfseq CCPR1L ; = current PWM value? | |
328 rcall isr_dimm_tft ; No, adjust until max_CCPR1L=CCPR1L ! | |
329 | |
448 | 330 banksel common |
331 call get_analog_switches ; Get analog readings | |
332 btfss INTCON3,INT1IE | |
333 bra isr_tmr7_a | |
334 btfsc analog_sw2_pressed | |
335 rcall isr_switch_left | |
336 isr_tmr7_a: | |
337 banksel common | |
338 btfss INTCON,INT0IE | |
339 bra isr_tmr7_b | |
340 btfsc analog_sw1_pressed | |
341 rcall isr_switch_right | |
342 isr_tmr7_b: | |
343 | |
0 | 344 banksel isr_backup |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
345 decfsz ir_S8_timeout,F ; IR Data still valid? |
0 | 346 bra isr_tmr7_2 ; Yes, continue |
347 ; timeout, clear IR-Data | |
348 | |
349 movlw ir_timeout_value ; multiples of 62,5ms | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
178
diff
changeset
|
350 movwf ir_S8_timeout ; Reload timeout |
0 | 351 |
352 banksel common | |
236 | 353 btfss analog_o2_input |
113 | 354 bra isr_tmr7_1a ; Always with normal ostc3 hardware |
355 btfss s8_digital | |
356 bra isr_tmr7_2 ; only when digital | |
357 isr_tmr7_1a: | |
0 | 358 clrf o2_mv_sensor1+0 |
359 clrf o2_mv_sensor1+1 | |
360 clrf o2_mv_sensor2+0 | |
361 clrf o2_mv_sensor2+1 | |
362 clrf o2_mv_sensor3+0 | |
363 clrf o2_mv_sensor3+1 | |
378 | 364 banksel hud_battery_mv |
0 | 365 clrf hud_battery_mv+0 |
366 clrf hud_battery_mv+1 | |
378 | 367 banksel hud_status_byte |
0 | 368 clrf hud_status_byte |
369 clrf o2_ppo2_sensor1 | |
370 clrf o2_ppo2_sensor2 | |
371 clrf o2_ppo2_sensor3 | |
372 | |
373 isr_tmr7_2: | |
374 banksel common | |
375 btfss no_sensor_int ; No sensor interrupt (because it's addressed during sleep) | |
376 bra isr_sensor_state2 ; No, continue | |
377 banksel isr_backup ; Back to Bank0 ISR data | |
378 return | |
379 | |
380 isr_sensor_state2: | |
381 banksel common | |
382 movff sensor_state_counter,WREG | |
383 btfss WREG,0 ; every 1/4 second | |
384 bsf quarter_second_update ; Set flag | |
319 | 385 banksel isr_backup ; Back to Bank0 ISR data |
0 | 386 movlw d'2' |
387 cpfseq speed_setting ; Set to normal in case it's not already in normal speed mode | |
388 rcall isr_set_speed_to_normal | |
319 | 389 |
0 | 390 incf sensor_state_counter,F ; counts to eight for state maschine |
391 | |
392 ; State 1: Clear flags and average registers, get temperature (51us) and start pressure integration (73,5us) | |
393 ; State 2: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
394 ; State 3: Get temperature (51us) and start pressure integration (73,5us) | |
395 ; State 4: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
396 ; State 5: Get temperature (51us) and start pressure integration (73,5us) | |
397 ; State 6: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
398 ; State 7: Get temperature (51us) and start pressure integration (73,5us) | |
399 ; State 8: Get pressure (51us), start temperature integration (73,5us), calculate temperature compensated pressure (233us) and build average for half-second update of tempperature and pressure | |
400 | |
401 movff sensor_state_counter,WREG ; WREG used as temp here... | |
402 dcfsnz WREG,F | |
403 bra sensor_int_state1_plus_restart ; Do State 1 | |
404 dcfsnz WREG,F | |
405 bra sensor_int_state2 ; Do State 2 | |
406 dcfsnz WREG,F | |
407 bra sensor_int_state1 ; Do State 3 | |
408 dcfsnz WREG,F | |
409 bra sensor_int_state2 ; Do State 4 | |
410 dcfsnz WREG,F | |
411 bra sensor_int_state1 ; Do State 5 | |
412 dcfsnz WREG,F | |
413 bra sensor_int_state2 ; Do State 6 | |
414 dcfsnz WREG,F | |
415 bra sensor_int_state1 ; Do State 7 | |
416 ; bra sensor_int2_plus_average ; Do State 8 | |
417 ;sensor_int2_plus_average: | |
418 ; First, do state2: | |
419 call get_pressure_value ; State2: Get pressure (51us) | |
420 call get_temperature_start ; and start temperature integration (73,5us) | |
421 call calculate_compensation ; calculate temperature compensated pressure (27us) | |
422 ; Build average | |
423 bcf STATUS,C ; clear carry bit. | |
424 rrcf amb_pressure_avg+1 ; amb_pressure sum / 2 | |
425 rrcf amb_pressure_avg+0 | |
426 bcf STATUS,C ; clear carry bit, twice. | |
427 rrcf amb_pressure_avg+1 ; amb_pressure sum / 4 | |
428 rrcf amb_pressure_avg+0 | |
429 | |
430 movff amb_pressure_avg+1,amb_pressure+1 ; copy into actual register | |
431 movff amb_pressure_avg+0,amb_pressure+0 | |
432 | |
433 bcf STATUS,C | |
434 btfsc temperature_avg+1,7 ; Copy sign bit to carry | |
435 bsf STATUS,C | |
436 rrcf temperature_avg+1 ; Signed temperature /2 | |
437 rrcf temperature_avg+0 | |
438 bcf STATUS,C | |
439 btfsc temperature_avg+1,7 ; Copy sign bit to carry | |
440 bsf STATUS,C | |
441 rrcf temperature_avg+1 ; Signed temperature /4 | |
442 rrcf temperature_avg+0 | |
443 | |
444 movff temperature_avg+1,temperature+1 ; copy into actual register | |
445 movff temperature_avg+0,temperature+0 | |
446 | |
447 banksel common ; flag1 is in Bank1 | |
448 bcf temp_changed ; Clear flag for temperature update | |
449 bcf pressure_refresh ; Clear flag for pressure update | |
450 banksel isr_backup ; Back to Bank0 ISR data | |
451 | |
452 ; Temp changed? | |
453 movf temperature+0,W | |
454 cpfseq last_temperature+0 | |
455 bra isr_sensor_state2_2 ; Yes | |
456 movf temperature+1,W | |
457 cpfseq last_temperature+1 | |
458 bra isr_sensor_state2_2 ; Yes | |
459 | |
460 bra isr_sensor_state2_3 ; no change | |
461 | |
462 isr_sensor_state2_2: | |
463 banksel common ; flag1 is in Bank1 | |
464 bsf temp_changed ; Yes | |
465 banksel isr_backup ; Back to Bank0 ISR data | |
466 isr_sensor_state2_3: | |
467 movff temperature+0,last_temperature+0 ; Copy for compare | |
468 movff temperature+1,last_temperature+1 | |
469 | |
470 movf amb_pressure+0,W | |
471 cpfseq last_pressure+0 | |
472 bra isr_sensor_state2_4 ; Yes | |
473 movf amb_pressure+1,W | |
474 cpfseq last_pressure+1 | |
475 bra isr_sensor_state2_4 ; Yes | |
476 | |
477 bra isr_sensor_state2_5 ; No change | |
478 isr_sensor_state2_4: | |
479 banksel common ; flag1 is in Bank1 | |
480 bsf pressure_refresh ; Yes | |
481 banksel isr_backup ; Back to Bank0 ISR data | |
482 isr_sensor_state2_5: | |
483 movff amb_pressure+0,last_pressure+0 ; Copy for compare | |
484 movff amb_pressure+1,last_pressure+1 | |
485 | |
486 clrf sensor_state_counter ; Then reset State counter | |
176 | 487 banksel common ; flag2 is in Bank1 |
0 | 488 btfss simulatormode_active ; are we in simulator mode? |
489 bra comp_air_pressure ; no | |
176 | 490 ; Always set pressure_refresh flag in simulator mode |
491 bsf pressure_refresh ; Yes | |
492 banksel isr_backup ; Back to Bank0 ISR data | |
0 | 493 movlw LOW d'1000' ; yes, so simulate 1000mbar surface pressure |
494 movwf last_surfpressure+0 | |
495 movlw HIGH d'1000' | |
496 movwf last_surfpressure+1 | |
497 | |
498 comp_air_pressure: | |
176 | 499 banksel isr_backup ; Back to Bank0 ISR data |
0 | 500 movf last_surfpressure+0,W ; compensate airpressure |
501 subwf amb_pressure+0,W | |
502 movwf rel_pressure+0 ; rel_pressure stores depth! | |
503 | |
504 movf last_surfpressure+1,W | |
505 subwfb amb_pressure+1,W | |
506 movwf rel_pressure+1 | |
507 btfss STATUS,N ; result is below zero? | |
508 bra sensor_int_state_exit | |
509 clrf rel_pressure+0 ; Yes, do not display negative depths | |
510 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive | |
511 bra sensor_int_state_exit | |
512 | |
513 sensor_int_state1_plus_restart: | |
514 clrf amb_pressure_avg+0 ; pressure average registers | |
515 clrf amb_pressure_avg+1 | |
516 clrf temperature_avg+0 | |
517 clrf temperature_avg+1 | |
518 | |
519 sensor_int_state1: | |
520 call get_temperature_value ; State 1: Get temperature | |
521 call get_pressure_start ; and start pressure integration. | |
522 bra sensor_int_state_exit | |
523 | |
524 sensor_int_state2: | |
525 call get_pressure_value ; State2: Get pressure (51us) | |
526 call get_temperature_start ; and start temperature integration (73,5us) | |
527 call calculate_compensation ; calculate temperature compensated pressure (233us) | |
528 ; bra sensor_int_state_exit | |
529 sensor_int_state_exit: | |
530 rcall isr_restore_clock ; Restore clock | |
531 return | |
532 ;============================================================================= | |
533 | |
534 | |
535 | |
536 isr_rtcc: ; each second | |
537 bcf PIR3,RTCCIF ; clear flag | |
538 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
539 bsf RTCCFG,RTCPTR1 | |
540 bsf RTCCFG,RTCPTR0 ; year | |
541 movff RTCVALL,year ; format is BCD! | |
542 movff RTCVALH,day ; dummy read | |
543 movff RTCVALL,day ; format is BCD! | |
544 movff RTCVALH,month ; format is BCD! | |
545 movff RTCVALL,hours ; format is BCD! | |
546 movff RTCVALH,secs ; format is BCD! | |
547 movff RTCVALL,secs ; format is BCD! | |
548 movff RTCVALH,mins ; format is BCD! | |
549 banksel isr_backup ; Back to Bank0 ISR data | |
550 | |
551 ; Convert BCD to DEC and set registers | |
552 movff mins, isr1_temp | |
553 rcall isr_rtcc_convert ; Converts to dec with result in WREG | |
554 movff WREG,mins | |
555 movff secs, isr1_temp | |
556 rcall isr_rtcc_convert ; Converts to dec with result in WREG | |
557 movff WREG,secs | |
558 movff hours, isr1_temp | |
559 rcall isr_rtcc_convert ; Converts to dec with result in WREG | |
560 movff WREG,hours | |
561 movff month, isr1_temp | |
562 rcall isr_rtcc_convert ; Converts to dec with result in WREG | |
563 movff WREG,month | |
564 movff day, isr1_temp | |
565 rcall isr_rtcc_convert ; Converts to dec with result in WREG | |
566 movff WREG,day | |
567 movff year, isr1_temp | |
568 rcall isr_rtcc_convert ; Converts to dec with result in WREG | |
569 movff WREG,year | |
570 | |
571 ; Place once/second tasks for ISR here (Be sure of the right bank!) | |
572 banksel common ; flag1 is in Bank1 | |
573 btfss sleepmode ; in Sleepmode? | |
574 call get_ambient_level ; No, get ambient light level and set max_CCPR1L | |
575 | |
576 rcall isr_battery_gauge ; Add amount of battery consumption to battery_gauge:6 | |
577 | |
578 banksel common ; flag1 is in Bank1 | |
579 bsf onesecupdate ; A new second has begun | |
580 btfsc divemode ; in divemode? | |
581 rcall isr_divemode_1sec ; Yes, do some divemode stuff in bank common | |
582 | |
583 tstfsz secs ; Secs == 0 ? | |
584 return ; No, Done. | |
585 | |
586 bsf oneminupdate ; A new minute has begun | |
587 | |
588 btfss divemode ; In Divemode? | |
589 rcall check_nofly_desat_time ; No, so reduce NoFly and Desat and increase interval | |
590 | |
591 ; Check if a new hour has just begun | |
592 tstfsz mins ; mins=0? | |
593 bra isr_rtcc2 ; No | |
594 bsf onehourupdate ; Yes, set flag | |
595 | |
596 isr_rtcc2: | |
597 banksel isr_backup ; Back to Bank0 ISR data | |
598 return ; Done. | |
599 | |
600 isr_battery_gauge: | |
601 banksel isr_backup ; Bank0 ISR data | |
602 movlw current_sleepmode ; 100µA/3600 -> nAs (Sleepmode current) | |
603 movwf isr1_temp ; Store value (low byte) | |
604 clrf isr2_temp ; High byte | |
605 | |
606 banksel common ; flag1 is in Bank1 | |
607 btfss sleepmode ; in Sleepmode? | |
608 rcall isr_battery_gauge2 ; No, compute current consumtion value into isr1_temp and isr2_temp | |
609 | |
610 banksel isr_backup ; Bank0 ISR data | |
611 movf isr1_temp,W ; 48Bit add of isr1_temp and isr2_temp into battery_gauge:6 | |
612 addwf battery_gauge+0,F | |
613 movf isr2_temp,W | |
614 addwfc battery_gauge+1,F | |
615 movlw .0 | |
616 addwfc battery_gauge+2,F | |
617 addwfc battery_gauge+3,F | |
618 addwfc battery_gauge+4,F | |
619 addwfc battery_gauge+5,F | |
620 return | |
621 | |
622 isr_battery_gauge2: | |
623 ; set consumtion rate in nAs for an one second interval | |
624 ; Example: | |
625 ; movlw LOW .55556 ; 0,2A/3600*1e9s = nAs | |
626 ; movwf isr1_temp ; Low byte | |
627 ; movlw HIGH .55556 ; 0,2A/3600*1e9s = nAs | |
628 ; movwf isr2_temp ; High byte | |
629 | |
630 ; Current consumption for LED backlight is 47*CCPR1L+272 | |
631 movf CCPR1L,W | |
632 mullw current_backlight_multi | |
633 movlw LOW current_backlight_offset | |
634 addwf PRODL,F | |
635 movlw HIGH current_backlight_offset | |
636 addwfc PRODH,F | |
637 movff PRODL,isr1_temp | |
638 movff PRODH,isr2_temp ; isr1_temp and isr2_temp hold value for backlight | |
639 | |
640 ; Add current for CPU and GPU | |
641 ; speed_setting=1: ECO (3,1mA -> 861nAs), =2: NORMAL (5,50mA -> 1528nAs) or =3: FASTEST (8,04mA -> 2233nAs) | |
319 | 642 banksel isr_backup ; Bank0 ISR data |
0 | 643 movlw .1 |
644 cpfseq speed_setting | |
645 bra isr_battery_gauge3 | |
646 movlw LOW current_speed_eco | |
647 addwf isr1_temp,F | |
648 movlw HIGH current_speed_eco | |
649 addwfc isr2_temp,F | |
650 bra isr_battery_gauge5 | |
651 isr_battery_gauge3: | |
652 movlw .2 | |
653 cpfseq speed_setting | |
654 bra isr_battery_gauge4 | |
655 movlw LOW current_speed_normal | |
656 addwf isr1_temp,F | |
657 movlw HIGH current_speed_normal | |
658 addwfc isr2_temp,F | |
659 bra isr_battery_gauge5 | |
660 isr_battery_gauge4: | |
661 movlw LOW current_speed_fastest | |
662 addwf isr1_temp,F | |
663 movlw HIGH current_speed_fastest | |
664 addwfc isr2_temp,F | |
665 isr_battery_gauge5: | |
666 ; Add current if IR reciever is on | |
667 btfss ir_power ; IR enabled? | |
668 bra isr_battery_gauge6 ; no | |
669 movlw LOW current_ir_reciever | |
670 addwf isr1_temp,F | |
671 movlw HIGH current_ir_reciever | |
672 addwfc isr2_temp,F | |
673 isr_battery_gauge6: | |
674 ; Add current for compass/accelerometer | |
675 btfss compass_enabled ; compass active? | |
676 bra isr_battery_gauge7 ; no | |
677 movlw LOW current_compass | |
678 addwf isr1_temp,F | |
679 movlw HIGH current_compass | |
680 addwfc isr2_temp,F | |
681 isr_battery_gauge7: | |
682 return | |
683 | |
684 isr_divemode_1sec: | |
685 incf samplesecs,F ; "samplingrate" diving seconds done | |
686 decf samplesecs_value,W ; holds "samplingrate" value (minus 1 into WREG) | |
687 cpfsgt samplesecs ; Done? | |
688 bra isr_divemode_1sec2 ; no | |
689 | |
690 clrf samplesecs ; clear counter... | |
691 bsf store_sample ; ...and set bit for profile storage | |
692 isr_divemode_1sec2: | |
693 ; Increase re-setable average depth divetime counter | |
176 | 694 infsnz average_divesecs+0,F ; increase stopwatch registers |
0 | 695 incf average_divesecs+1,F ; increase stopwatch registers |
696 ; Increase total divetime (Regardless of start_dive_threshold) | |
148 | 697 infsnz total_divetime_seconds+0,F |
698 incf total_divetime_seconds+1,F ; Total dive time (Regardless of start_dive_threshold) | |
0 | 699 |
700 btfss divemode2 ; displayed divetime is running? | |
701 return ; No (e.g. too shallow) | |
702 | |
703 ; increase divetime registers (Displayed dive time) | |
704 incf divesecs,F | |
705 movlw d'59' | |
706 cpfsgt divesecs | |
707 bra isr_divemode_1sec2a | |
708 | |
709 clrf divesecs | |
710 bsf realdive ; this bit is always set (again) if the dive is longer then one minute | |
148 | 711 infsnz divemins+0,F |
712 incf divemins+1,F ; increase divemins | |
0 | 713 |
714 isr_divemode_1sec2a: | |
715 btfss FLAG_apnoe_mode ; Are we in Apnoe mode? | |
716 return ; No | |
717 | |
718 incf apnoe_secs,F ; increase descent registers | |
719 movlw d'59' | |
720 cpfsgt apnoe_secs ; full minute? | |
721 return ; No | |
722 clrf apnoe_secs | |
723 incf apnoe_mins,F ; increase descent mins | |
724 return | |
725 | |
726 ;============================================================================= | |
727 ; BCD to Binary convertion. | |
728 ; Input: isr1_temp = Value in BCD | |
729 ; Output WREG = value in binary. | |
730 isr_rtcc_convert: | |
731 swapf isr1_temp, W | |
732 andlw 0x0F ; W= tens | |
733 rlncf WREG, W ; W= 2*tens | |
734 subwf isr1_temp, F ; 16*tens + ones - 2*tens | |
735 subwf isr1_temp, F ; 14*tens + ones - 2*tens | |
736 subwf isr1_temp, W ; 12*tens + ones - 2*tens | |
737 return | |
738 | |
739 ;============================================================================= | |
740 | |
741 isr_switch_right: ; | |
742 bcf INTCON,INT0IE ; Disable INT0 | |
743 banksel common ; flag1 is in Bank1 | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
744 btfss flip_screen ; 180° flipped? |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
745 bsf switch_right ; Set flag |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
746 btfsc flip_screen ; 180° flipped? |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
747 bsf switch_left ; Set flag |
0 | 748 bra isr_switch_common ; Continue... |
749 | |
750 isr_switch_left: ; | |
751 bcf INTCON3,INT1IE ; Disable INT1 | |
752 banksel common ; flag1 is in Bank1 | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
753 btfss flip_screen ; 180° flipped? |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
754 bsf switch_left ; Set flag |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
755 btfsc flip_screen ; 180° flipped? |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
756 bsf switch_right ; Set flag |
0 | 757 isr_switch_common: |
758 ; load timer1 for first press | |
759 clrf TMR1L | |
760 movlw TMR1H_VALUE_FIRST ; in steps of 7,8125ms | |
761 movwf TMR1H | |
762 bsf T1CON,TMR1ON ; Start Timer 1 | |
763 banksel isr_backup ; Select Bank0 for ISR data. | |
764 bcf INTCON3,INT1IF ; Clear flag | |
765 bcf INTCON,INT0IF ; Clear flag | |
766 return | |
767 | |
768 timer1int: | |
451 | 769 bcf PIR1,TMR1IF ; Clear flag |
0 | 770 banksel common ; flag1 is in Bank1 |
451 | 771 bcf INTCON,INT0IF ; Clear flag |
772 bcf INTCON3,INT1IF ; Clear flag | |
773 ; digital | |
0 | 774 btfss switch_left1 ; Left button hold-down? |
775 bra timer1int_left ; Yes | |
776 btfss switch_right2 ; Right button hold-down? | |
777 bra timer1int_right ; Yes | |
451 | 778 |
779 ; Analog | |
780 btfsc analog_sw2_pressed ; Left button hold-down? | |
781 bra timer1int_left ; Yes | |
782 btfsc analog_sw1_pressed ; Right button hold-down? | |
783 bra timer1int_right ; Yes | |
784 | |
0 | 785 ; No button hold-down, stop Timer 1 |
786 bcf T1CON,TMR1ON ; Stop Timer 1 | |
787 bsf INTCON,INT0IE ; Enable INT0 | |
788 bsf INTCON3,INT1IE ; Enable INT1 | |
451 | 789 return |
0 | 790 |
791 timer1int_left: | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
792 btfss flip_screen ; 180° flipped? |
0 | 793 bsf switch_left ; (Re-)Set flag |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
794 btfsc flip_screen ; 180° flipped? |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
795 bsf switch_right ; (Re-)Set flag |
0 | 796 bra timer1int_common ; Continue |
797 timer1int_right: | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
798 btfss flip_screen ; 180° flipped? |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
799 bsf switch_right ; Set flag |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
800 btfsc flip_screen ; 180° flipped? |
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
148
diff
changeset
|
801 bsf switch_left ; Set flag |
0 | 802 timer1int_common: |
803 ; load timer1 for next press | |
804 clrf TMR1L | |
805 movlw TMR1H_VALUE_CONT ; Surface mode | |
806 btfsc divemode | |
807 movlw TMR1H_VALUE_CONT_DIVE ; Dive mode | |
808 movwf TMR1H | |
809 return ; Return from timer1int with timer1 kept running | |
810 | |
811 ;============================================================================= | |
812 | |
813 check_nofly_desat_time: | |
814 movf nofly_time+0,W ; Is nofly null ? | |
815 iorwf nofly_time+1,W | |
816 bz check_nofly_desat_time2 ; yes... | |
817 | |
818 movlw d'1' | |
819 subwf nofly_time+0,F | |
820 movlw d'0' | |
821 subwfb nofly_time+1,F ; reduce by one | |
822 | |
823 check_nofly_desat_time2: | |
824 movf desaturation_time+0,W ; Is Desat null ? | |
825 iorwf desaturation_time+1,W | |
826 bz check_nofly_desat_time3 ; yes... | |
827 | |
828 movlw d'1' | |
829 subwf desaturation_time+0,F | |
830 movlw d'0' | |
831 subwfb desaturation_time+1,F ; reduce by one... | |
832 | |
147 | 833 ; Increase surface interval timer |
834 infsnz surface_interval+0,F | |
835 incf surface_interval+1,F | |
0 | 836 return ; Done |
837 | |
838 check_nofly_desat_time3: | |
839 clrf surface_interval+0 | |
840 clrf surface_interval+1 ; Clear surface interval timer | |
841 return ; Done. | |
842 | |
843 ;============================================================================= | |
844 | |
845 isr_restore_clock: | |
846 banksel isr_backup | |
847 movlw d'1' | |
319 | 848 cpfseq speed_setting |
0 | 849 bra isr_restore_speed2 |
850 ; Reset to eco | |
851 movlw b'00000000' | |
852 movwf OSCTUNE ; 4x PLL Disable (Bit6) - only works with 8 or 16MHz (=32 or 64MHz) | |
853 movlw b'00110010' | |
854 movwf OSCCON ; 1MHz INTOSC | |
855 movlw T2CON_ECO | |
856 movwf T2CON | |
857 bra isr_restore_exit | |
858 isr_restore_speed2: | |
859 movlw d'2' | |
319 | 860 cpfseq speed_setting |
0 | 861 bra isr_restore_speed3 |
862 ; Reset to normal | |
863 movlw b'01110010' | |
864 movwf OSCCON ; 16MHz INTOSC | |
865 movlw b'00000000' | |
866 movwf OSCTUNE ; 4x PLL Disable (Bit6) - only works with 8 or 16MHz (=32 or 64MHz) | |
867 movlw T2CON_NORMAL | |
868 movwf T2CON | |
869 bra isr_restore_exit | |
870 | |
871 isr_restore_speed3: | |
872 ; Reset to fastest | |
873 movlw b'01110010' ; 16MHz INTOSC | |
874 movwf OSCCON | |
875 movlw b'01000000' | |
876 movwf OSCTUNE ; 4x PLL Enable (Bit6) - only works with 8 or 16MHz (=32 or 64MHz) | |
877 movlw T2CON_FASTEST | |
878 movwf T2CON | |
879 ; bra isr_restore_exit | |
880 isr_restore_exit: | |
881 btfss OSCCON,HFIOFS | |
882 bra isr_restore_exit ; loop until PLL is stable | |
883 return | |
884 | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
885 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
886 restore_flash: ; Restore first flash page from eeprom |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
887 banksel common |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
888 ; Start address in internal flash |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
889 movlw 0x00 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
890 movwf TBLPTRL |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
891 movwf TBLPTRH |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
892 movwf TBLPTRU |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
893 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
894 movlw b'10010100' ; Setup erase |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
895 rcall Write ; Write! |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
896 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
897 movlw .128 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
898 movwf lo ; Byte counter |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
899 clrf EEADR |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
900 movlw .3 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
901 movwf EEADRH ; Setup backup address |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
902 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
903 TBLRD*- ; Dummy read to be in 128 byte block |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
904 restore_flash_loop: |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
905 call read_eeprom |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
906 incf EEADR,F |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
907 movff EEDATA,TABLAT ; put 1 byte |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
908 tblwt+* ; Table Write with Pre-Increment |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
909 decfsz lo,F ; 128byte done? |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
910 bra restore_flash_loop ; No |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
911 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
912 movlw b'10000100' ; Setup writes |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
913 rcall Write ; Write! |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
914 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
915 reset ; Done, reset CPU |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
916 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
917 Write: |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
918 movwf EECON1 ; Type of memory to write in |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
919 movlw 0x55 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
920 movwf EECON2 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
921 movlw 0xAA |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
922 movwf EECON2 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
923 bsf EECON1,WR ; Write |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
924 nop |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
925 nop |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
926 return |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
927 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
928 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
929 END |