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