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