annotate src/isr.asm @ 40:1e2d2b0bca5b

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