Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/start.asm @ 234:bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
author | JeanDo |
---|---|
date | Thu, 17 Mar 2011 18:32:16 +0100 |
parents | 2cbaa01dac26 |
children | ade0848c8b8b |
rev | line source |
---|---|
0 | 1 ; OSTC - diving computer code |
2 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
3 | |
4 ; This program is free software: you can redistribute it and/or modify | |
5 ; it under the terms of the GNU General Public License as published by | |
6 ; the Free Software Foundation, either version 3 of the License, or | |
7 ; (at your option) any later version. | |
8 | |
9 ; This program is distributed in the hope that it will be useful, | |
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ; GNU General Public License for more details. | |
13 | |
14 ; You should have received a copy of the GNU General Public License | |
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | |
17 | |
18 ; Start and init | |
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
20 ; written: 10/13/04 | |
21 ; last updated: 06/24/08 | |
22 ; known bugs: | |
23 ; ToDo: | |
24 | |
25 start: | |
26 movlb b'00000001' ; ram bank 1 selected | |
119 | 27 movff STKPTR,temp10 |
0 | 28 call init |
29 btfsc divemode ; Reset from Divemode? | |
30 call PLED_resetdebugger ; Yes! Something went wrong, show reset informations | |
31 | |
32 clrf STKPTR ; Clear Stackpointer | |
98
6f8e3a08011e
1.73beta rc1 (Added new customview for divemode)
heinrichsweikamp
parents:
97
diff
changeset
|
33 lfsr FSR0, 10Bh ; Clear rambank 1-9, do not delete RTC registers |
0 | 34 clear_rambank: |
35 clrf POSTINC0 | |
36 movlw 0x0A | |
37 cpfseq FSR0H ; Bank 9 done? | |
38 bra clear_rambank ; clear... | |
39 | |
40 ; Defaults for RTC | |
41 call disable_rs232 ; disable UART module | |
42 call RTCinit ; reset RTC | |
43 | |
44 ; Air pressure compensation after reset | |
45 call get_calibration_data ; Get calibration data from pressure sensor | |
46 | |
47 bcf pressure_refresh | |
48 wait_start_pressure: | |
49 btfss pressure_refresh ; Air pressure compensation | |
50 bra wait_start_pressure | |
51 | |
52 clrf rel_pressure+0 | |
53 clrf rel_pressure+1 | |
54 clrf surface_interval+0 | |
55 clrf surface_interval+1 | |
56 | |
57 bsf sleepmode ; Routine only works in sleepmode... | |
58 call pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | |
59 bcf sleepmode ; Normal mode again | |
233 | 60 |
0 | 61 movff amb_pressure+0,last_surfpressure+0 |
62 movff amb_pressure+1,last_surfpressure+1 | |
63 movff amb_pressure+0,last_surfpressure_15min+0 | |
64 movff amb_pressure+1,last_surfpressure_15min+1 | |
65 movff amb_pressure+0,last_surfpressure_30min+0 | |
66 movff amb_pressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers | |
67 | |
233 | 68 ; Extra power-up reset (JeanDo) |
69 ifdef TESTING | |
70 call do_menu_reset_all2 | |
71 endif | |
72 | |
0 | 73 ; reset deco data |
197 | 74 clrf WREG ; Use as buffer |
75 movff WREG,char_I_He_ratio ; No He at the Surface | |
0 | 76 movlw d'79' ; 79% N2 |
197 | 77 movff WREG,char_I_N2_ratio ; No He at the Surface |
0 | 78 movff amb_pressure+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine |
79 movff amb_pressure+1,int_I_pres_respiration+1 | |
80 | |
197 | 81 clrf WREG |
31 | 82 movff WREG,char_I_step_is_1min ; 2 second deco mode |
116 | 83 call deco_clear_tissue ; |
84 call deco_calc_desaturation_time ; calculate desaturation time | |
85 call deco_clear_CNS_fraction ; clear CNS | |
0 | 86 call calc_deko_surfmode ; calculate desaturation every minute |
116 | 87 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode |
0 | 88 movlb b'00000001' ; select ram bank 1 |
89 | |
90 ; check firmware and reset Custom Functions after an update | |
91 movlw LOW 0x101 | |
92 movwf EEADR | |
93 movlw HIGH 0x101 | |
94 movwf EEADRH | |
95 call read_eeprom ; read current version x | |
96 movff EEDATA,temp1 | |
97 incf EEADR,F ; set to 0x102 | |
98 call read_eeprom ; read current version y | |
99 movff EEDATA,temp2 | |
100 clrf EEADRH ; Reset EEADRH | |
101 | |
102 movlw softwareversion_x | |
103 cpfseq temp1 ; compare version x | |
104 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
105 | |
106 movlw softwareversion_y | |
107 cpfseq temp2 ; compare version y | |
108 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
109 bra restart ; x and y are equal -> do not reset cf | |
110 | |
111 check_firmware_new: | |
112 movlw LOW 0x101 ; store current version in EEPROM | |
113 movwf EEADR | |
114 movlw HIGH 0x101 | |
115 movwf EEADRH | |
116 movlw softwareversion_x | |
117 movwf EEDATA | |
118 call write_eeprom ; write version x | |
119 incf EEADR,F ; set to 0x102 | |
120 movlw softwareversion_y | |
121 movwf EEDATA | |
122 call write_eeprom ; write version y | |
123 clrf EEADRH ; Reset EEADRH | |
160 | 124 ; goto reset_all_cf ; resets all custom functions bank0 and bank1 and jumps to "restart" |
52 | 125 ; goto reset_all_cf_bank1 ; resets all custom functions bank1 and jumps to "restart" |
0 | 126 |
127 restart: | |
21 | 128 bcf LED_red |
129 bcf LED_blue ; all LEDs off | |
43 | 130 GETCUSTOM8 d'48' ; time correction value |
131 movff WREG, time_correction_value ; store in Bank0 register | |
15 | 132 |
133 clrf flag1 ; clear all flags | |
134 clrf flag2 | |
135 clrf flag3 | |
136 clrf flag4 | |
137 clrf flag5 | |
138 clrf flag6 | |
139 clrf flag7 | |
140 clrf flag8 | |
141 clrf flag9 | |
142 clrf flag10 | |
143 clrf flag11 | |
144 clrf flag12 | |
145 clrf flag13 | |
146 clrf flag14 | |
147 clrf flag15 | |
153 | 148 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
167
diff
changeset
|
149 ; Should we set win_flip_screen ? |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
167
diff
changeset
|
150 bsf flag1,0 ; Precondition to yes |
153 | 151 clrf EEADRH ; Reset EEADRH |
152 read_int_eeprom d'1' | |
153 movlw .7 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
167
diff
changeset
|
154 cpfsgt EEDATA ; serial > 2048 (Mk2n hardware) ? |
153 | 155 bcf flag1,0 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
167
diff
changeset
|
156 incf EEDATA,W ; serial == 65535 (emulation) ? |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
167
diff
changeset
|
157 btfsc STATUS,Z |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
167
diff
changeset
|
158 bcf flag1,0 |
153 | 159 movff flag1,win_flags ; store in Bank0 register |
160 clrf flag1 ; Clear flag1 (again) | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
167
diff
changeset
|
161 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
167
diff
changeset
|
162 ; Should we disable sleep (hardware emulator) |
154 | 163 movlw .0 |
164 cpfsgt EEDATA ; >256 | |
167 | 165 bsf nsm ; NO-SLEEP-MODE : for hardware debugging |
153 | 166 |
142 | 167 call gassetup_sort_gaslist ; Sorts Gaslist according to change depth |
168 call PLED_boot ; PLED boot (Incl. Clear Screen!) | |
0 | 169 WIN_TOP .0 |
170 WIN_LEFT .0 | |
171 WIN_FONT FT_SMALL | |
172 WIN_INVERT .0 ; Init new Wordprocessor | |
83
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
173 setf WREG |
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
174 movff WREG,win_color1 ; Beware: win_color1 is bank0, and we are bank1 currently |
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
175 movff WREG,win_color2 |
0 | 176 call I2CReset ; Just in Case any I2C device blocks the Bus |
177 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure | |
178 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure | |
179 | |
180 ; Check if new CF were added in the last firmware version | |
181 clrf EEADRH | |
182 read_int_eeprom d'92' ; Read number of CF used in this firmware | |
183 movlw max_custom_number ; Defined in definitions.asm | |
184 cpfseq EEDATA ; Compare with last version | |
185 bra restart_01 ; New CF, show warning and store new number | |
186 bra restart_1 ; No new CF, continue with boot | |
187 restart_01: | |
188 ; Save new number of current CF count | |
189 rcall display_new_cf_installed; Show warning | |
190 movlw max_custom_number ; Defined in definitions.asm | |
191 movwf EEDATA | |
192 write_int_eeprom d'92' ; Store number of CF used in this firmware | |
193 | |
194 restart_1: | |
195 | |
196 ; Set Debug mode? | |
197 read_int_eeprom d'39' | |
198 bsf debug_mode | |
199 movlw d'1' | |
200 cpfseq EEDATA | |
201 bcf debug_mode ; clear flag if <> 1 | |
202 | |
203 goto surfloop ; Jump to Surfaceloop! | |
204 | |
205 | |
206 display_new_cf_installed: | |
207 call PLED_new_cf_warning ; Display new CF warning screen | |
208 movlw d'20' ; timeout for warning screen | |
209 bra startup_screen3a ; Will RETURN after timeout or button press | |
197 | 210 |
211 ;============================================================================= | |
212 ; Setup all flags and parameters for divemode and simulator computations. | |
213 ; | |
214 restart_set_modes_and_flags: ; "Call"ed from divemode, as well! | |
0 | 215 bcf gauge_mode |
216 bcf FLAG_const_ppO2_mode | |
217 bcf FLAG_apnoe_mode | |
45 | 218 |
219 ; Pre-load modes for OC, GF 90/90 and no Aponoe or Gauge. | |
197 | 220 bcf no_deco_customviews ; Clear no-deco-mode-flag |
45 | 221 movlw d'0' |
197 | 222 movff WREG,char_I_deco_model ; Clear Flagbyte |
45 | 223 ; Load GF values into RAM |
224 movlw d'90' | |
197 | 225 movff WREG,char_I_GF_Low_percentage |
226 movff WREG,char_I_GF_High_percentage ; Set to 90/90... | |
0 | 227 clrf EEADRH |
197 | 228 read_int_eeprom d'34' ; Read deco data |
229 movlw d'1' ; Gauge mode | |
0 | 230 cpfseq EEDATA |
197 | 231 bra restart_3_test_ppO2_mode ; check for ppO2 mode |
232 bsf gauge_mode ; Set flag for gauge mode | |
233 bsf no_deco_customviews ; Set no-deco-mode-flag | |
234 return ; start in Surfacemode | |
0 | 235 restart_3_test_ppO2_mode: |
197 | 236 movlw d'2' ; const ppO2 mode |
0 | 237 cpfseq EEDATA |
197 | 238 bra restart_3_test_apnoe_mode; check for apnoe mode |
239 bsf FLAG_const_ppO2_mode ; Set flag for ppO2 mode | |
240 return ; start in Surfacemode | |
0 | 241 restart_3_test_apnoe_mode: |
197 | 242 movlw d'3' ; Apnoe mode |
0 | 243 cpfseq EEDATA |
197 | 244 bra restart_4_test_gf_mode ; check for GF OC mode |
245 bsf FLAG_apnoe_mode ; Set flag for Apnoe Mode | |
246 bsf no_deco_customviews ; Set no-deco-mode-flag | |
247 return ; start in Surfacemode | |
0 | 248 restart_4_test_gf_mode: |
197 | 249 movlw d'4' ; GF OC mode |
0 | 250 cpfseq EEDATA |
197 | 251 bra restart_5_test_gfO2_mode ; check for GF CC mode |
0 | 252 movlw d'1' |
197 | 253 movff WREG,char_I_deco_model ; Set Flagbyte for GF method |
45 | 254 ; Load GF values into RAM |
197 | 255 GETCUSTOM8 d'32' ; GF low |
256 movff EEDATA,char_I_GF_Low_percentage | |
257 GETCUSTOM8 d'33' ; GF high | |
258 movff EEDATA,char_I_GF_High_percentage | |
259 return ; start in Surfacemode | |
0 | 260 restart_5_test_gfO2_mode: |
197 | 261 movlw d'5' ; GF CC mode |
0 | 262 cpfseq EEDATA |
197 | 263 return ; Start in Surfacemode |
264 bsf FLAG_const_ppO2_mode ; Set flag for ppO2 mode | |
0 | 265 movlw d'1' |
197 | 266 movff WREG,char_I_deco_model ; Set Flagbyte for GF method |
137 | 267 ; Load GF values into RAM |
197 | 268 GETCUSTOM8 d'32' ; GF low |
163 | 269 movff EEDATA,char_I_GF_Low_percentage |
197 | 270 GETCUSTOM8 d'33' ; GF high |
163 | 271 movff EEDATA,char_I_GF_High_percentage |
197 | 272 return ; start in Surfacemode |
273 | |
274 ;============================================================================= | |
0 | 275 |
276 startup_screen1: | |
277 call PLED_ClearScreen | |
278 call PLED_startupscreen1 ; show startup sreen | |
279 startup_screen1_2: | |
280 movlw d'10' ; timeout for startup screen | |
281 movwf temp1 | |
282 WAITMS d'200' | |
283 bcf switch_left | |
284 bcf switch_right | |
285 screen1_loop: | |
286 btfsc onesecupdate ; do every second tasks? | |
287 call set_dive_modes ; tests if depth>threshold | |
288 btfsc onesecupdate ; do every second tasks? | |
289 decf temp1,F | |
290 bcf onesecupdate ; every second tasks done | |
291 | |
292 tstfsz temp1 ; timout occured? | |
293 bra screen1_loop2 ; no | |
294 return | |
295 | |
296 screen1_loop2: | |
297 btfsc divemode ; Divemode active? | |
298 return | |
299 btfsc switch_left ; Ack? | |
300 return | |
301 btfsc switch_right ; Ack? | |
302 return | |
303 bra screen1_loop ; loop screen | |
304 | |
305 startup_screen2: | |
306 call PLED_ClearScreen ; Page 1 | |
307 call PLED_startupscreen2 ; show startup sreen | |
308 bra startup_screen1_2 | |
309 | |
310 startup_screen3a:; WARNING: Also used for decodescriptions and CF Warning screen! | |
311 movwf temp1 | |
312 WAITMS d'200' | |
313 bcf switch_left | |
314 bcf switch_right | |
315 screen3_loop: | |
316 btfsc onesecupdate ; do every second tasks? | |
317 call set_dive_modes ; tests if depth>threshold | |
318 | |
319 btfsc onesecupdate ; do every second tasks? | |
320 decf temp1,F | |
321 bcf onesecupdate ; every second tasks done | |
322 | |
323 tstfsz temp1 ; timout occured? | |
324 bra screen3_loop2 ; no | |
325 return | |
326 screen3_loop2: | |
327 btfsc switch_left ; Ack? | |
328 return | |
329 btfsc switch_right ; Ack? | |
330 return | |
331 bra screen3_loop ; loop screen | |
332 | |
333 init: | |
334 movlw b'01101100' ; 4MHz (x4 PLL) | |
335 movwf OSCCON | |
336 | |
337 movlw b'00010001' ; I/O Ports | |
338 movwf TRISA | |
339 clrf PORTA | |
340 movlw b'00000011' | |
341 movwf TRISB | |
342 clrf PORTB | |
343 movlw b'11011101' ; UART | |
344 movwf TRISC | |
345 clrf PORTC | |
346 movlw b'00000000' | |
347 movwf TRISE | |
348 clrf PORTE | |
349 movlw b'00000000' | |
350 movwf TRISD | |
351 clrf PORTD | |
352 | |
353 movlw b'01000000' ; Bit6: PPL enable | |
354 movwf OSCTUNE | |
355 | |
356 movlw b'00011111' ; Timer0 | |
357 movwf T0CON | |
358 | |
359 movlw b'00000111' ; Timer1 | |
360 movwf T1CON | |
361 | |
362 movlw b'11010000' ; Interrups | |
363 movwf INTCON | |
364 movlw b'00000101' | |
365 movwf INTCON2 | |
366 movlw b'00001000' | |
367 movwf INTCON3 | |
368 movlw b'00100001' | |
369 movwf PIE1 | |
370 movlw b'00000000' | |
371 movwf PIE2 | |
372 clrf RCON | |
373 | |
374 movlw b'00000000' ; A/D Converter | |
375 movwf ADCON0 | |
376 movlw b'00001110' | |
377 movwf ADCON1 | |
378 movlw b'10001010' ; Right justified | |
379 movwf ADCON2 | |
380 | |
381 clrf SSPCON1 ; Set I²C Mode | |
382 movlw b'00000000' | |
383 movwf SSPSTAT | |
384 movlw b'00101000' | |
385 movwf SSPCON1 | |
386 movlw b'00000000' | |
387 movwf SSPCON2 | |
388 movlw d'8' ; 400kHz I2C clock @ 16MHz Fcy | |
389 movwf SSPADD | |
390 | |
391 clrf CCP1CON ; PWM Module off | |
392 clrf ECCP1CON ; PWM Module off | |
393 | |
394 movlw b'00000111' ; Comperator Module off | |
395 movwf CMCON | |
396 | |
397 movlw b'00100000' | |
398 movwf CANCON ; ECAN Module OFF | |
399 | |
400 movlw b'00100100' ; UART | |
401 movwf TXSTA | |
402 movlw b'10010000' | |
403 movwf RCSTA | |
404 movlw b'00001000' | |
405 movwf BAUDCON | |
406 clrf SPBRGH | |
407 movlw d'34' | |
408 movwf SPBRG | |
409 clrf RCREG | |
410 clrf PIR1 | |
411 return |