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