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 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
|
|
358 bcf temp_changed ; Clear flag for temperature update
|
|
359 bcf pressure_refresh ; Clear flag for pressure update
|
|
360 banksel isr_backup ; Back to Bank0 ISR data
|
|
361
|
|
362 ; Temp changed?
|
|
363 movf temperature+0,W
|
|
364 cpfseq last_temperature+0
|
|
365 bra isr_sensor_state2_2 ; Yes
|
|
366 movf temperature+1,W
|
|
367 cpfseq last_temperature+1
|
|
368 bra isr_sensor_state2_2 ; Yes
|
|
369
|
|
370 bra isr_sensor_state2_3 ; no change
|
|
371
|
|
372 isr_sensor_state2_2:
|
|
373 banksel common ; flag1 is in Bank1
|
|
374 bsf temp_changed ; Yes
|
|
375 banksel isr_backup ; Back to Bank0 ISR data
|
|
376 isr_sensor_state2_3:
|
|
377 movff temperature+0,last_temperature+0 ; Copy for compare
|
|
378 movff temperature+1,last_temperature+1
|
|
379
|
|
380 movf amb_pressure+0,W
|
|
381 cpfseq last_pressure+0
|
|
382 bra isr_sensor_state2_4 ; Yes
|
|
383 movf amb_pressure+1,W
|
|
384 cpfseq last_pressure+1
|
|
385 bra isr_sensor_state2_4 ; Yes
|
|
386
|
|
387 bra isr_sensor_state2_5 ; No change
|
|
388 isr_sensor_state2_4:
|
|
389 banksel common ; flag1 is in Bank1
|
|
390 bsf pressure_refresh ; Yes
|
|
391 banksel isr_backup ; Back to Bank0 ISR data
|
|
392 isr_sensor_state2_5:
|
|
393 movff amb_pressure+0,last_pressure+0 ; Copy for compare
|
|
394 movff amb_pressure+1,last_pressure+1
|
|
395
|
|
396 clrf sensor_state_counter ; Then reset State counter
|
|
397 btfss simulatormode_active ; are we in simulator mode?
|
|
398 bra comp_air_pressure ; no
|
|
399 comp_air_pressure0:
|
|
400 movlw LOW d'1000' ; yes, so simulate 1000mbar surface pressure
|
|
401 movwf last_surfpressure+0
|
|
402 movlw HIGH d'1000'
|
|
403 movwf last_surfpressure+1
|
|
404 ; Always set pressure_refresh flag in simulator mode
|
|
405 banksel common ; flag1 is in Bank1
|
|
406 bsf pressure_refresh ; Yes
|
|
407 banksel isr_backup ; Back to Bank0 ISR data
|
|
408
|
|
409 comp_air_pressure:
|
|
410 movf last_surfpressure+0,W ; compensate airpressure
|
|
411 subwf amb_pressure+0,W
|
|
412 movwf rel_pressure+0 ; rel_pressure stores depth!
|
|
413
|
|
414 movf last_surfpressure+1,W
|
|
415 subwfb amb_pressure+1,W
|
|
416 movwf rel_pressure+1
|
|
417 btfss STATUS,N ; result is below zero?
|
|
418 bra sensor_int_state_exit
|
|
419 clrf rel_pressure+0 ; Yes, do not display negative depths
|
|
420 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
|
|
421 bra sensor_int_state_exit
|
|
422
|
|
423 sensor_int_state1_plus_restart:
|
|
424 clrf amb_pressure_avg+0 ; pressure average registers
|
|
425 clrf amb_pressure_avg+1
|
|
426 clrf temperature_avg+0
|
|
427 clrf temperature_avg+1
|
|
428
|
|
429 sensor_int_state1:
|
|
430 call get_temperature_value ; State 1: Get temperature
|
|
431 call get_pressure_start ; and start pressure integration.
|
|
432 bra sensor_int_state_exit
|
|
433
|
|
434 sensor_int_state2:
|
|
435 call get_pressure_value ; State2: Get pressure (51us)
|
|
436 call get_temperature_start ; and start temperature integration (73,5us)
|
|
437 call calculate_compensation ; calculate temperature compensated pressure (233us)
|
|
438 ; bra sensor_int_state_exit
|
|
439 sensor_int_state_exit:
|
|
440 rcall isr_restore_clock ; Restore clock
|
|
441 return
|
|
442 ;=============================================================================
|
|
443
|
|
444 isr_dimm_tft: ; Adjust until max_CCPR1L=CCPR1L !
|
|
445 banksel common
|
|
446 btfsc tft_is_dimming ; Ignore while dimming
|
|
447 return
|
|
448 banksel isr_backup
|
|
449 movf max_CCPR1L,W
|
|
450 cpfsgt CCPR1L ; CCPR1L>max_CCPR1L?
|
|
451 bra isr_dimm_tft2 ; No, dimm up
|
|
452 ; dimm down
|
|
453 decf CCPR1L,F ; -1
|
|
454 return
|
|
455 isr_dimm_tft2:
|
|
456 movf max_CCPR1L,W
|
|
457 sublw .20
|
|
458 cpfsgt CCPR1L ; CCPR1L>max_CCPR1L-20?
|
|
459 bra isr_dimm_tft3 ; No, dimm up slow
|
|
460 ; dimm up faster
|
|
461 movlw .5
|
|
462 addwf CCPR1L,F
|
|
463 isr_dimm_tft3:
|
|
464 incf CCPR1L,F ; +1
|
|
465 return
|
|
466
|
|
467
|
|
468 isr_rtcc: ; each second
|
|
469 bcf PIR3,RTCCIF ; clear flag
|
|
470 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM.
|
|
471 bsf RTCCFG,RTCPTR1
|
|
472 bsf RTCCFG,RTCPTR0 ; year
|
|
473 movff RTCVALL,year ; format is BCD!
|
|
474 movff RTCVALH,day ; dummy read
|
|
475 movff RTCVALL,day ; format is BCD!
|
|
476 movff RTCVALH,month ; format is BCD!
|
|
477 movff RTCVALL,hours ; format is BCD!
|
|
478 movff RTCVALH,secs ; format is BCD!
|
|
479 movff RTCVALL,secs ; format is BCD!
|
|
480 movff RTCVALH,mins ; format is BCD!
|
|
481 banksel isr_backup ; Back to Bank0 ISR data
|
|
482
|
|
483 ; Convert BCD to DEC and set registers
|
|
484 movff mins, isr1_temp
|
|
485 rcall isr_rtcc_convert ; Converts to dec with result in WREG
|
|
486 movff WREG,mins
|
|
487 movff secs, isr1_temp
|
|
488 rcall isr_rtcc_convert ; Converts to dec with result in WREG
|
|
489 movff WREG,secs
|
|
490 movff hours, isr1_temp
|
|
491 rcall isr_rtcc_convert ; Converts to dec with result in WREG
|
|
492 movff WREG,hours
|
|
493 movff month, isr1_temp
|
|
494 rcall isr_rtcc_convert ; Converts to dec with result in WREG
|
|
495 movff WREG,month
|
|
496 movff day, isr1_temp
|
|
497 rcall isr_rtcc_convert ; Converts to dec with result in WREG
|
|
498 movff WREG,day
|
|
499 movff year, isr1_temp
|
|
500 rcall isr_rtcc_convert ; Converts to dec with result in WREG
|
|
501 movff WREG,year
|
|
502
|
|
503 ; Place once/second tasks for ISR here (Be sure of the right bank!)
|
|
504 banksel common ; flag1 is in Bank1
|
|
505 btfss sleepmode ; in Sleepmode?
|
|
506 call get_ambient_level ; No, get ambient light level and set max_CCPR1L
|
|
507
|
|
508 rcall isr_battery_gauge ; Add amount of battery consumption to battery_gauge:6
|
|
509
|
|
510 banksel common ; flag1 is in Bank1
|
|
511 bsf onesecupdate ; A new second has begun
|
|
512 btfsc divemode ; in divemode?
|
|
513 rcall isr_divemode_1sec ; Yes, do some divemode stuff in bank common
|
|
514
|
|
515 tstfsz secs ; Secs == 0 ?
|
|
516 return ; No, Done.
|
|
517
|
|
518 ; banksel isr_backup ; Back to Bank0 ISR data
|
|
519 ; movff secs,isr1_temp ; Copy to Bank0
|
|
520 ; movlw d'0'
|
|
521 ; cpfseq isr1_temp ; Secs == 0 ?
|
|
522 ; return ; Done.
|
|
523
|
|
524 ; banksel common ; flag1 is in Bank1
|
|
525 bsf oneminupdate ; A new minute has begun
|
|
526
|
|
527 btfss divemode ; In Divemode?
|
|
528 rcall check_nofly_desat_time ; No, so reduce NoFly and Desat and increase interval
|
|
529
|
|
530 ; Check if a new hour has just begun
|
|
531 ; banksel common ; flag1 is in Bank1
|
|
532 tstfsz mins ; mins=0?
|
|
533 bra isr_rtcc2 ; No
|
|
534 bsf onehourupdate ; Yes, set flag
|
|
535
|
|
536 isr_rtcc2:
|
|
537 banksel isr_backup ; Back to Bank0 ISR data
|
|
538 return ; Done.
|
|
539
|
|
540 isr_battery_gauge:
|
|
541 banksel isr_backup ; Bank0 ISR data
|
|
542 movlw current_sleepmode ; 100µA/3600 -> nAs (Sleepmode current)
|
|
543 movwf isr1_temp ; Store value (low byte)
|
|
544 clrf isr2_temp ; High byte
|
|
545
|
|
546 banksel common ; flag1 is in Bank1
|
|
547 btfss sleepmode ; in Sleepmode?
|
|
548 rcall isr_battery_gauge2 ; No, compute current consumtion value into isr1_temp and isr2_temp
|
|
549
|
|
550 banksel isr_backup ; Bank0 ISR data
|
|
551 movf isr1_temp,W ; 48Bit add of isr1_temp and isr2_temp into battery_gauge:6
|
|
552 addwf battery_gauge+0,F
|
|
553 movf isr2_temp,W
|
|
554 addwfc battery_gauge+1,F
|
|
555 movlw .0
|
|
556 addwfc battery_gauge+2,F
|
|
557 movlw .0
|
|
558 addwfc battery_gauge+3,F
|
|
559 movlw .0
|
|
560 addwfc battery_gauge+4,F
|
|
561 movlw .0
|
|
562 addwfc battery_gauge+5,F
|
|
563 return
|
|
564
|
|
565 isr_battery_gauge2:
|
|
566 ; set consumtion rate in nAs for an one second interval
|
|
567 ; Example:
|
|
568 ; movlw LOW .55556 ; 0,2A/3600*1e9s = nAs
|
|
569 ; movwf isr1_temp ; Low byte
|
|
570 ; movlw HIGH .55556 ; 0,2A/3600*1e9s = nAs
|
|
571 ; movwf isr2_temp ; High byte
|
|
572
|
|
573 ; Current consumption for LED backlight is 47*CCPR1L+272
|
|
574 movf CCPR1L,W
|
|
575 mullw current_backlight_multi
|
|
576 movlw LOW current_backlight_offset
|
|
577 addwf PRODL,F
|
|
578 movlw HIGH current_backlight_offset
|
|
579 addwfc PRODH,F
|
|
580 movff PRODL,isr1_temp
|
|
581 movff PRODH,isr2_temp ; isr1_temp and isr2_temp hold value for backlight
|
|
582
|
|
583 ; Add current for CPU and GPU
|
|
584 ; speed_setting=1: ECO (3,1mA -> 861nAs), =2: NORMAL (5,50mA -> 1528nAs) or =3: FASTEST (8,04mA -> 2233nAs)
|
|
585 movlw .1
|
|
586 cpfseq speed_setting
|
|
587 bra isr_battery_gauge3
|
|
588 banksel isr_backup ; Bank0 ISR data
|
|
589 movlw LOW current_speed_eco
|
|
590 addwf isr1_temp,F
|
|
591 movlw HIGH current_speed_eco
|
|
592 addwfc isr2_temp,F
|
|
593 bra isr_battery_gauge5
|
|
594 isr_battery_gauge3:
|
|
595 movlw .2
|
|
596 cpfseq speed_setting
|
|
597 bra isr_battery_gauge4
|
|
598 banksel isr_backup ; Bank0 ISR data
|
|
599 movlw LOW current_speed_normal
|
|
600 addwf isr1_temp,F
|
|
601 movlw HIGH current_speed_normal
|
|
602 addwfc isr2_temp,F
|
|
603 bra isr_battery_gauge5
|
|
604 isr_battery_gauge4:
|
|
605 ; movlw .3
|
|
606 ; cpfseq speed_setting
|
|
607 ; bra isr_battery_gauge5
|
|
608 banksel isr_backup ; Bank0 ISR data
|
|
609 movlw LOW current_speed_fastest
|
|
610 addwf isr1_temp,F
|
|
611 movlw HIGH current_speed_fastest
|
|
612 addwfc isr2_temp,F
|
|
613 isr_battery_gauge5:
|
|
614 ; Add current if IR reciever is on
|
|
615 btfss ir_power ; IR enabled?
|
|
616 bra isr_battery_gauge6 ; no
|
|
617 movlw LOW current_ir_reciever
|
|
618 addwf isr1_temp,F
|
|
619 movlw HIGH current_ir_reciever
|
|
620 addwfc isr2_temp,F
|
|
621 isr_battery_gauge6:
|
|
622 ; Add current for compass/accelerometer
|
|
623 btfss compass_enabled ; compass active?
|
|
624 bra isr_battery_gauge7 ; no
|
|
625 movlw LOW current_compass
|
|
626 addwf isr1_temp,F
|
|
627 movlw HIGH current_compass
|
|
628 addwfc isr2_temp,F
|
|
629 isr_battery_gauge7:
|
|
630 return
|
|
631
|
|
632 isr_divemode_1sec:
|
|
633 incf samplesecs,F ; "samplingrate" diving seconds done
|
|
634 decf samplesecs_value,W ; holds "samplingrate" value (minus 1 into WREG)
|
|
635 cpfsgt samplesecs ; Done?
|
|
636 bra isr_divemode_1sec2 ; no
|
|
637
|
|
638 clrf samplesecs ; clear counter...
|
|
639 bsf store_sample ; ...and set bit for profile storage
|
|
640 isr_divemode_1sec2:
|
|
641 ; Increase re-setable average depth divetime counter
|
|
642 incf average_divesecs+0,F ; increase stopwatch registers
|
|
643 btfsc STATUS,Z
|
|
644 incf average_divesecs+1,F ; increase stopwatch registers
|
|
645 ; Increase total divetime (Regardless of start_dive_threshold)
|
|
646 incf total_divetime_seconds+0,F
|
|
647 movlw .0
|
|
648 addwfc total_divetime_seconds+1,F ; Total dive time (Regardless of start_dive_threshold)
|
|
649
|
|
650 btfss divemode2 ; displayed divetime is running?
|
|
651 return ; No (e.g. too shallow)
|
|
652
|
|
653 ; increase divetime registers (Displayed dive time)
|
|
654 incf divesecs,F
|
|
655 movlw d'59'
|
|
656 cpfsgt divesecs
|
|
657 bra isr_divemode_1sec2a
|
|
658
|
|
659 clrf divesecs
|
|
660 bsf realdive ; this bit is always set (again) if the dive is longer then one minute
|
|
661 incf divemins+0,F
|
|
662 movlw .0
|
|
663 addwfc divemins+1,F ; increase divemins
|
|
664
|
|
665 isr_divemode_1sec2a:
|
|
666 btfss FLAG_apnoe_mode ; Are we in Apnoe mode?
|
|
667 return ; No
|
|
668
|
|
669 incf apnoe_secs,F ; increase descent registers
|
|
670 movlw d'59'
|
|
671 cpfsgt apnoe_secs ; full minute?
|
|
672 return ; No
|
|
673 clrf apnoe_secs
|
|
674 incf apnoe_mins,F ; increase descent mins
|
|
675 return
|
|
676
|
|
677 ;=============================================================================
|
|
678 ; BCD to Binary convertion.
|
|
679 ; Input: isr1_temp = Value in BCD
|
|
680 ; Output WREG = value in binary.
|
|
681 isr_rtcc_convert:
|
|
682 swapf isr1_temp, W
|
|
683 andlw 0x0F ; W= tens
|
|
684 rlncf WREG, W ; W= 2*tens
|
|
685 subwf isr1_temp, F ; 16*tens + ones - 2*tens
|
|
686 subwf isr1_temp, F ; 14*tens + ones - 2*tens
|
|
687 subwf isr1_temp, W ; 12*tens + ones - 2*tens
|
|
688 return
|
|
689
|
|
690 ;=============================================================================
|
|
691
|
|
692 isr_switch_right: ;
|
|
693 bcf INTCON,INT0IE ; Disable INT0
|
|
694 ; bcf power_sw2 ; Power-down switch circuity
|
|
695 banksel common ; flag1 is in Bank1
|
|
696 bsf switch_right ; Set flag, button press is OK
|
|
697 bra isr_switch_common ; Continue...
|
|
698
|
|
699 isr_switch_left: ;
|
|
700 bcf INTCON3,INT1IE ; Disable INT1
|
|
701 ; bcf power_sw1 ; Power-down switch circuity
|
|
702 banksel common ; flag1 is in Bank1
|
|
703 bsf switch_left ; Set flag, button press is OK
|
|
704
|
|
705 isr_switch_common:
|
|
706 ; load timer1 for first press
|
|
707 clrf TMR1L
|
|
708 movlw TMR1H_VALUE_FIRST ; in steps of 7,8125ms
|
|
709 movwf TMR1H
|
|
710 bsf T1CON,TMR1ON ; Start Timer 1
|
|
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 ; nop
|
|
735
|
|
736 banksel isr_backup ; Select Bank0 for ISR data.
|
|
737 ; bsf power_sw1
|
|
738 bcf INTCON3,INT1IF ; Clear flag
|
|
739 ; bsf power_sw2 ; Power-up switch circuity
|
|
740 bcf INTCON,INT0IF ; Clear flag
|
|
741 return
|
|
742
|
|
743 timer1int:
|
|
744 bcf PIR1,TMR1IF ; Clear flag
|
|
745 banksel common ; flag1 is in Bank1
|
|
746 btfss switch_left1 ; Left button hold-down?
|
|
747 bra timer1int_left ; Yes
|
|
748 btfss switch_right2 ; Right button hold-down?
|
|
749 bra timer1int_right ; Yes
|
|
750
|
|
751 ; No button hold-down, stop Timer 1
|
|
752 bcf T1CON,TMR1ON ; Stop Timer 1
|
|
753 bsf INTCON,INT0IE ; Enable INT0
|
|
754 bsf INTCON3,INT1IE ; Enable INT1
|
|
755 bcf INTCON,INT0IF ; Clear flag
|
|
756 bcf INTCON3,INT1IF ; Clear flag
|
|
757 ; bcf switch_left
|
|
758 ; bcf switch_right
|
|
759 return
|
|
760
|
|
761 timer1int_left:
|
|
762 ; bcf power_sw1 ; Power-down switch circuity
|
|
763 bsf switch_left ; (Re-)Set flag
|
|
764 bra timer1int_common ; Continue
|
|
765 timer1int_right:
|
|
766 ; bcf power_sw2 ; Power-down switch circuity
|
|
767 bsf switch_right ; (Re-)Set flag
|
|
768 timer1int_common:
|
|
769 ; load timer1 for next press
|
|
770 clrf TMR1L
|
|
771 movlw TMR1H_VALUE_CONT ; Surface mode
|
|
772 btfsc divemode
|
|
773 movlw TMR1H_VALUE_CONT_DIVE ; Dive mode
|
|
774 movwf TMR1H
|
|
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 ; nop
|
|
791 ;
|
|
792 ; nop
|
|
793 ; nop
|
|
794 ; nop
|
|
795 ; nop
|
|
796 ; nop
|
|
797 ; nop
|
|
798 ; nop
|
|
799 ; nop
|
|
800 ; bsf power_sw1
|
|
801 bcf INTCON3,INT1IF ; Clear flag
|
|
802 ; bsf power_sw2 ; Power-up switch circuity
|
|
803 bcf INTCON,INT0IF ; Clear flag
|
|
804 return ; Return from timer1int with timer1 kept running
|
|
805
|
|
806 ;=============================================================================
|
|
807
|
|
808 check_nofly_desat_time:
|
|
809 movf nofly_time+0,W ; Is nofly null ?
|
|
810 iorwf nofly_time+1,W
|
|
811 bz check_nofly_desat_time2 ; yes...
|
|
812
|
|
813 movlw d'1'
|
|
814 subwf nofly_time+0,F
|
|
815 movlw d'0'
|
|
816 subwfb nofly_time+1,F ; reduce by one
|
|
817
|
|
818 check_nofly_desat_time2:
|
|
819 movf desaturation_time+0,W ; Is Desat null ?
|
|
820 iorwf desaturation_time+1,W
|
|
821 bz check_nofly_desat_time3 ; yes...
|
|
822
|
|
823 movlw d'1'
|
|
824 subwf desaturation_time+0,F
|
|
825 movlw d'0'
|
|
826 subwfb desaturation_time+1,F ; reduce by one...
|
|
827
|
|
828 ; Increase surface interval timer
|
|
829 movlw d'1'
|
|
830 addwf surface_interval+0,F
|
|
831 movlw d'0'
|
|
832 addwfc surface_interval+1,F
|
|
833 return ; Done
|
|
834
|
|
835 check_nofly_desat_time3:
|
|
836 clrf surface_interval+0
|
|
837 clrf surface_interval+1 ; Clear surface interval timer
|
|
838 return ; Done.
|
|
839
|
|
840 ;=============================================================================
|
|
841
|
|
842 isr_restore_clock:
|
|
843 banksel isr_backup
|
|
844 movff speed_setting,isr1_temp ; Copy to Bank0
|
|
845 movlw d'1'
|
|
846 cpfseq isr1_temp
|
|
847 bra isr_restore_speed2
|
|
848 ; Reset to eco
|
|
849 movlw b'00000000'
|
|
850 movwf OSCTUNE ; 4x PLL Disable (Bit6) - only works with 8 or 16MHz (=32 or 64MHz)
|
|
851 movlw b'00110010'
|
|
852 movwf OSCCON ; 1MHz INTOSC
|
|
853 movlw T2CON_ECO
|
|
854 movwf T2CON
|
|
855 bra isr_restore_exit
|
|
856 isr_restore_speed2:
|
|
857 movlw d'2'
|
|
858 cpfseq isr1_temp
|
|
859 bra isr_restore_speed3
|
|
860 ; Reset to normal
|
|
861 movlw b'01110010'
|
|
862 movwf OSCCON ; 16MHz INTOSC
|
|
863 movlw b'00000000'
|
|
864 movwf OSCTUNE ; 4x PLL Disable (Bit6) - only works with 8 or 16MHz (=32 or 64MHz)
|
|
865 movlw T2CON_NORMAL
|
|
866 movwf T2CON
|
|
867 bra isr_restore_exit
|
|
868
|
|
869 isr_restore_speed3:
|
|
870 ; Reset to fastest
|
|
871 movlw b'01110010' ; 16MHz INTOSC
|
|
872 movwf OSCCON
|
|
873 movlw b'01000000'
|
|
874 movwf OSCTUNE ; 4x PLL Enable (Bit6) - only works with 8 or 16MHz (=32 or 64MHz)
|
|
875 movlw T2CON_FASTEST
|
|
876 movwf T2CON
|
|
877 ; bra isr_restore_exit
|
|
878 isr_restore_exit:
|
|
879 btfss OSCCON,HFIOFS
|
|
880 bra isr_restore_exit ; loop until PLL is stable
|
|
881 return
|
|
882
|
|
883 END |