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