Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/isr.asm @ 330:447390289f47 ScreenDump
NEW screen_dump serial command (l)
author | JeanDo |
---|---|
date | Tue, 10 May 2011 03:18:20 +0200 |
parents | ceedf078b2d8 |
children | 797e2ac42d24 |
rev | line source |
---|---|
0 | 1 |
2 ; OSTC - diving computer code | |
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
4 | |
5 ; This program is free software: you can redistribute it and/or modify | |
6 ; it under the terms of the GNU General Public License as published by | |
7 ; the Free Software Foundation, either version 3 of the License, or | |
8 ; (at your option) any later version. | |
9 | |
10 ; This program is distributed in the hope that it will be useful, | |
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ; GNU General Public License for more details. | |
14 | |
15 ; You should have received a copy of the GNU General Public License | |
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | |
18 | |
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
20 ; written: 10/30/05 | |
21 ; last updated: 05/16/08 | |
22 ; known bugs: | |
23 ; ToDo: | |
24 | |
25 ; the timer1 module interrupts every 62.5ms (16x/second) | |
26 ; temperature and pressure is averaged over 4 measurements | |
27 ; flag pressure_refresh is set every 500ms | |
28 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable) | |
29 | |
30 uartint: | |
31 btfsc simulatormode_active ; are we in simulatormode? | |
32 bra simulator_int ; Yes, reading is depth in m! | |
33 | |
34 movff RCREG,uart1_temp | |
35 movlw d'96' | |
36 subwf uart1_temp,F | |
37 dcfsnz uart1_temp,F ; "a" | |
38 bsf dump_external_eeprom ; set flag | |
39 dcfsnz uart1_temp,F ; "b" | |
40 bsf uart_settime ; set flag | |
41 dcfsnz uart1_temp,F ; "c" | |
42 bsf simulatormode_active ; set flag | |
43 dcfsnz uart1_temp,F ; "d" | |
44 bsf internal_eeprom_write ; set flag | |
45 dcfsnz uart1_temp,F ; "e" | |
46 bsf uart_send_hash ; set flag | |
47 dcfsnz uart1_temp,F ; "f" | |
297
ceedf078b2d8
Gas Setup page 2 reworked, Texts 107, 108, 109,150, 149, 168, 42, 43, 53,54,55, 165 need update in french, spanish and german
Heinrichsweikamp
parents:
283
diff
changeset
|
48 bsf uart_reset_battery_stats ; set flag |
0 | 49 dcfsnz uart1_temp,F ; "g" |
50 bsf uart_send_int_eeprom ; set flag | |
51 dcfsnz uart1_temp,F ; "h" | |
52 bsf uart_reset_decodata ; set flag | |
53 dcfsnz uart1_temp,F ; "i" | |
54 bsf internal_eeprom_write2 ; set flag | |
55 dcfsnz uart1_temp,F ; "j" | |
56 bsf uart_send_int_eeprom2 ; set flag | |
57 dcfsnz uart1_temp,F ; "k" | |
58 bsf uart_store_tissue_data ; set flag | |
330 | 59 dcfsnz uart1_temp,F ; "l" |
60 bsf uart_dump_screen ; set flag | |
283
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
61 |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
62 movlw 0xC1 |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
63 cpfseq RCREG ; 115200Baud Bootloader request? |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
64 bra uartint1 ; No |
4ec488f046f4
Battery sign color coded, work on new uart-started 115200Baud bootloader (Do NOT use yet!)
heinrichsweikamp
parents:
266
diff
changeset
|
65 bsf uart_115200_bootloader ; Yes, set Flag |
0 | 66 |
67 | |
68 uartint1: | |
69 movf RCREG,w ; unload RCREG in stand-alone simulator mode | |
70 bcf PIR1,RCIF ; Clear flag | |
71 bcf RCSTA,CREN ; Clear receiver status | |
72 bsf RCSTA,CREN | |
73 return | |
74 | |
75 simulator_int: | |
76 btfsc standalone_simulator ; ignore in standalone simulator mode | |
77 bra uartint1 | |
78 | |
21 | 79 bsf LED_blue |
0 | 80 tstfsz RCREG ; =0x00? |
81 bra simulator_int1 ; No | |
82 incf RCREG,F ; Yes, so force RCREG=1 | |
83 | |
84 simulator_int1: | |
85 movf RCREG,w ; depth in m | |
86 mullw d'100' ; result will be mbar | |
87 movff PRODL,sim_pressure+0 ; stored for pressure overwrite | |
88 movff PRODH,sim_pressure+1 | |
89 bra uartint1 ; exit uart int | |
90 | |
238 | 91 switch_left_int: |
0 | 92 bcf INTCON,INT0IF ; Clear flag |
93 | |
94 btfsc T0CON,TMR0ON ; Timer0 running? | |
95 bra timer0_restart ; Yes, restart | |
96 | |
266 | 97 ; OSTC 2N has flipped screen and exchanged switches... |
98 movff win_flags,WREG ; Get into Bank0 | |
99 btfss WREG,0 | |
0 | 100 bsf switch_left ; Set flag, button press is OK |
266 | 101 btfsc WREG,0 |
102 bsf switch_right ; Set flag, button press is OK | |
0 | 103 |
104 bsf T0CON,TMR0ON ; Start Timer 0 | |
105 return | |
106 | |
107 | |
238 | 108 switch_right_int: |
0 | 109 bcf INTCON3,INT1IF ; Clear flag |
110 | |
111 btfsc T0CON,TMR0ON ; Timer0 running? | |
112 bra timer0_restart ; Yes, restart | |
113 | |
266 | 114 ; OSTC 2N has flipped screen and exchanged switches... |
115 movff win_flags,WREG ; Get into Bank0 | |
116 btfsc WREG,0 | |
117 bsf switch_left ; Set flag, button press is OK | |
118 btfss WREG,0 | |
0 | 119 bsf switch_right ; Set flag, button press is OK |
120 | |
121 bsf T0CON,TMR0ON ; Start Timer 0 | |
122 return | |
123 | |
124 timer0_restart: | |
125 bcf INTCON,TMR0IF ; Clear flag | |
126 clrf T0CON ; Timer0 | |
127 clrf TMR0H | |
128 clrf TMR0L | |
129 bsf T0CON,TMR0ON ; Start Timer 0 | |
130 return | |
131 | |
132 timer0int: | |
133 bcf INTCON,TMR0IF ; Clear flag | |
134 bcf T0CON,TMR0ON ; Stop Timer 0 | |
135 clrf TMR0H | |
136 clrf TMR0L | |
137 return | |
138 | |
139 timer1int: | |
140 bcf PIR1,TMR1IF ; Clear flag | |
141 | |
142 timer1int_debug: | |
21 | 143 bcf LED_red ; LEDr off (For charge indicator) |
0 | 144 |
145 movlw 0x08 ; Timer1 int after 62.5ms (=16/second) | |
146 cpfslt TMR1H ; Did we miss a 1/16 second? | |
147 incf timer1int_counter1,F ; Yes, add extra 1/16 second | |
148 | |
149 movlw 0x08 ; Timer1 int after 62.5ms (=16/second) | |
150 subwf TMR1H,F | |
151 | |
238 | 152 incf timer1int_counter1,F ; Increase timer1 counter |
153 | |
0 | 154 movlw d'15' ; One second 16 |
155 cpfsgt timer1int_counter1 | |
156 bra sensor_int_pre ; only pressure sensor | |
238 | 157 rcall RTCisr ; adjust time, then query pressure sensor |
0 | 158 |
159 sensor_int_pre: | |
238 | 160 btfsc sleepmode ; In sleepmode? |
161 return ; Yes | |
0 | 162 |
163 sensor_int: | |
164 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep) | |
165 return | |
166 | |
238 | 167 incf timer1int_counter2,F ; counts to eight for state maschine |
0 | 168 |
238 | 169 ; State 1: Clear flags and average registers, get temperature (51us) and start pressure integration (73,5us) |
170 ; State 2: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
171 ; State 3: Get temperature (51us) and start pressure integration (73,5us) | |
172 ; State 4: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
173 ; State 5: Get temperature (51us) and start pressure integration (73,5us) | |
174 ; State 6: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us) | |
175 ; State 7: Get temperature (51us) and start pressure integration (73,5us) | |
176 ; 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 | |
177 | |
178 movff timer1int_counter2,isr_divB ; isr_divB used as temp here... | |
179 dcfsnz isr_divB,F | |
180 bra sensor_int_state1_plus_restart ; Do State 1 | |
181 dcfsnz isr_divB,F | |
182 bra sensor_int_state2 ; Do State 2 | |
183 dcfsnz isr_divB,F | |
184 bra sensor_int_state1 ; Do State 3 | |
185 dcfsnz isr_divB,F | |
186 bra sensor_int_state2 ; Do State 4 | |
187 dcfsnz isr_divB,F | |
188 bra sensor_int_state1 ; Do State 5 | |
189 dcfsnz isr_divB,F | |
190 bra sensor_int_state2 ; Do State 6 | |
191 dcfsnz isr_divB,F | |
192 bra sensor_int_state1 ; Do State 7 | |
193 ; bra sensor_int2_plus_average ; Do State 8 | |
194 | |
195 ;sensor_int2_plus_average: | |
196 rcall sensor_int_state2 | |
197 sensor_int2_plus_average2: | |
0 | 198 bcf STATUS,C |
199 rrcf isr3_temp+1 ; isr3_temp / 2 | |
200 rrcf isr3_temp+0 | |
201 bcf STATUS,C | |
202 rrcf temperature_temp+1 ; temperature_temp /2 | |
203 rrcf temperature_temp+0 | |
238 | 204 |
205 bcf STATUS,C | |
206 rrcf isr3_temp+1 ; isr3_temp / 4 | |
207 rrcf isr3_temp+0 | |
208 bcf STATUS,C | |
209 rrcf temperature_temp+1 ; temperature_temp /4 | |
210 rrcf temperature_temp+0 | |
211 | |
0 | 212 movff isr3_temp+1,amb_pressure+1 ; copy into actual register |
213 movff isr3_temp+0,amb_pressure+0 | |
214 | |
215 movff temperature_temp+1,temperature+1 | |
216 movff temperature_temp+0,temperature+0 | |
217 | |
218 bsf pressure_refresh ; Set flag! Temp and pressure were updated! | |
238 | 219 clrf timer1int_counter2 ; Then reset State counter |
0 | 220 |
221 btfss simulatormode_active ; are we in simulator mode? | |
222 bra comp_air_pressure ; no | |
223 | |
224 comp_air_pressure0: | |
225 movlw LOW d'1000' ; yes, so simulate 1Bar surface pressure | |
226 movwf last_surfpressure+0 | |
227 movlw HIGH d'1000' | |
228 movwf last_surfpressure+1 | |
229 | |
230 comp_air_pressure: | |
231 bcf neg_flag | |
232 movf last_surfpressure+0,W ; compensate airpressure | |
233 subwf amb_pressure+0,W | |
238 | 234 movwf rel_pressure+0 ; rel_pressure stores depth! |
0 | 235 |
236 movf last_surfpressure+1,W | |
237 subwfb amb_pressure+1,W | |
238 movwf rel_pressure+1 | |
238 | 239 btfss STATUS,N ; result is below zero? |
240 return | |
241 clrf rel_pressure+0 ; Yes, do not display negative depths | |
242 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive | |
0 | 243 return |
238 | 244 |
245 | |
246 sensor_int_state1_plus_restart: | |
247 bcf pressure_refresh ; clear flags | |
248 clrf isr3_temp+0 ; pressure average registers | |
249 clrf isr3_temp+1 | |
250 clrf temperature_temp+0 | |
251 clrf temperature_temp+1 | |
252 | |
253 sensor_int_state1: | |
254 call get_temperature_value ; State 1: Get temperature | |
255 call get_pressure_start ; and start pressure integration. | |
256 return ; Done. | |
257 | |
258 sensor_int_state2: | |
259 call get_pressure_value ; State2: Get pressure (51us) | |
260 call get_temperature_start ; and start temperature integration (73,5us) | |
261 call calculate_compensation ; calculate temperature compensated pressure (233us) | |
262 movf amb_pressure+0,W | |
263 addwf isr3_temp+0 ; average pressure | |
264 movf amb_pressure+1,W | |
265 addwfc isr3_temp+1 | |
266 movf temperature+0,W | |
267 addwf temperature_temp+0 ; average temperature | |
268 movf temperature+1,W | |
269 addwfc temperature_temp+1 | |
270 return | |
271 | |
0 | 272 |
273 RTCisr: | |
274 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms) | |
275 bsf onesecupdate ; we have a new second! | |
276 | |
277 bcf STATUS,Z ; are we in dive mode? | |
278 btfss divemode | |
238 | 279 bra RTCisr2 ; No, must be surface or sleepmode |
0 | 280 |
281 incf samplesecs,F ; CF20 diving seconds done | |
282 decf samplesecs_value,W ; holds CF20 value (minus 1 into WREG) | |
283 cpfsgt samplesecs | |
238 | 284 bra RTCisr1 ; no |
0 | 285 |
286 clrf samplesecs ; clear counter... | |
287 bsf store_sample ; ...and set bit for profile storage | |
238 | 288 |
0 | 289 RTCisr1: |
290 ; Increase re-setable average depth divetime counter | |
111 | 291 incf average_divesecs+0,F ; increase stopwatch registers |
0 | 292 btfsc STATUS,Z |
111 | 293 incf average_divesecs+1,F ; increase stopwatch registers |
0 | 294 |
295 btfss divemode2 ; displayed divetime is running? | |
296 bra RTCisr2 ; No (e.g. too shallow) | |
297 | |
298 incf divesecs,F ; increase divetime registers | |
299 movlw d'59' | |
300 cpfsgt divesecs | |
301 bra RTCisr1a | |
238 | 302 |
0 | 303 clrf divesecs |
304 bsf realdive ; this bit is always set (again) if the dive is longer then one minute | |
305 | |
306 incf divemins+0,F ; increase divemins | |
307 btfsc STATUS,Z | |
308 incf divemins+1,F ; and now do the realtime clock routine anyway | |
309 | |
310 RTCisr1a: | |
311 btfss FLAG_apnoe_mode ; Are we in Apnoe mode? | |
312 bra RTCisr2 ; No, skip the following | |
313 | |
314 incf apnoe_secs,F ; increase descent registers | |
315 movlw d'59' | |
316 cpfsgt apnoe_secs | |
317 bra RTCisr2 | |
318 clrf apnoe_secs | |
319 | |
320 incf apnoe_mins,F ; increase descent mins | |
321 ; Now, do the RTC routine.... | |
322 RTCisr2: | |
323 incf secs,F ; adjusts seconds, minutes, hours, day, month and year. Checks for a leap year and works until 2099! | |
324 movlw d'59' | |
325 cpfsgt secs | |
326 return | |
327 clrf secs | |
328 bsf oneminupdate | |
329 incf mins,F | |
330 movlw d'59' | |
331 cpfsgt mins | |
332 return | |
333 clrf mins | |
334 incf hours,F | |
335 movlw d'23' | |
336 cpfsgt hours | |
337 return | |
338 clrf hours | |
13 | 339 incf day,F |
43 | 340 movff time_correction_value,secs ; Correct too slow clock |
13 | 341 |
0 | 342 check_date: |
343 movff month,isr_divB ; new month? | |
344 dcfsnz isr_divB,F | |
345 movlw .31 | |
346 dcfsnz isr_divB,F | |
347 movlw .28 | |
348 dcfsnz isr_divB,F | |
349 movlw .31 | |
350 dcfsnz isr_divB,F | |
351 movlw .30 | |
352 dcfsnz isr_divB,F | |
353 movlw .31 | |
354 dcfsnz isr_divB,F | |
355 movlw .30 | |
356 dcfsnz isr_divB,F | |
357 movlw .31 | |
358 dcfsnz isr_divB,F | |
359 movlw .31 | |
360 dcfsnz isr_divB,F | |
361 movlw .30 | |
362 dcfsnz isr_divB,F | |
363 movlw .31 | |
364 dcfsnz isr_divB,F | |
365 movlw .30 | |
366 dcfsnz isr_divB,F | |
367 movlw .31 | |
368 cpfsgt day,1 | |
369 return | |
370 movlw .1 | |
371 movwf day | |
372 incf month,F | |
373 movlw .12 | |
374 cpfsgt month,1 | |
375 return | |
376 movlw .1 | |
377 movwf month | |
378 incf year,F | |
379 return |