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
|
|
27 call init
|
|
28 btfsc divemode ; Reset from Divemode?
|
|
29 call PLED_resetdebugger ; Yes! Something went wrong, show reset informations
|
|
30
|
|
31 clrf STKPTR ; Clear Stackpointer
|
|
32 lfsr FSR0, 109h ; Clear rambank 1-9, do not delete RTC registers
|
|
33 clear_rambank:
|
|
34 clrf POSTINC0
|
|
35 movlw 0x0A
|
|
36 cpfseq FSR0H ; Bank 9 done?
|
|
37 bra clear_rambank ; clear...
|
|
38
|
|
39 ; Defaults for RTC
|
|
40 call disable_rs232 ; disable UART module
|
|
41 call RTCinit ; reset RTC
|
|
42
|
|
43 ; Air pressure compensation after reset
|
|
44 call get_calibration_data ; Get calibration data from pressure sensor
|
|
45
|
|
46 bcf pressure_refresh
|
|
47 wait_start_pressure:
|
|
48 btfss pressure_refresh ; Air pressure compensation
|
|
49 bra wait_start_pressure
|
|
50
|
|
51 clrf rel_pressure+0
|
|
52 clrf rel_pressure+1
|
|
53 clrf surface_interval+0
|
|
54 clrf surface_interval+1
|
|
55
|
|
56 bsf sleepmode ; Routine only works in sleepmode...
|
|
57 call pressuretest_sleep_fast ; Gets pressure without averaging (faster!)
|
|
58 bcf sleepmode ; Normal mode again
|
|
59
|
|
60 movff amb_pressure+0,last_surfpressure+0
|
|
61 movff amb_pressure+1,last_surfpressure+1
|
|
62 movff amb_pressure+0,last_surfpressure_15min+0
|
|
63 movff amb_pressure+1,last_surfpressure_15min+1
|
|
64 movff amb_pressure+0,last_surfpressure_30min+0
|
|
65 movff amb_pressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers
|
|
66
|
|
67 ; reset deco data
|
|
68 incf nofly_time+0,F ; =1
|
|
69 clrf wait_temp ; Use as buffer
|
|
70 movff wait_temp,char_I_He_ratio ; No He at the Surface
|
|
71 movlw d'79' ; 79% N2
|
|
72 movwf wait_temp ; Use as buffer
|
|
73 movff wait_temp,char_I_N2_ratio ; No He at the Surface
|
|
74 movff amb_pressure+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine
|
|
75 movff amb_pressure+1,int_I_pres_respiration+1
|
|
76
|
31
|
77 movlw d'0'
|
|
78 movff WREG,char_I_step_is_1min ; 2 second deco mode
|
32
|
79 call deco_main_clear_tissue ;
|
|
80 movlb b'00000001' ; select ram bank 1
|
0
|
81 call deco_main_calc_desaturation_time; calculate desaturation time
|
|
82 movlb b'00000001' ; select ram bank 1
|
|
83 call main_clear_CNS_fraction ; clear CNS
|
|
84 movlb b'00000001' ; select ram bank 1
|
|
85 call calc_deko_surfmode ; calculate desaturation every minute
|
|
86 movlb b'00000001' ; select ram bank 1
|
|
87 call deco_main_calc_wo_deco_step_1_m ; calculate deco in surface mode
|
|
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
|
|
124 ; goto reset_all_cf ; resets all custom functions bank0 and bank1 and jumps to "restart"
|
3
|
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
|
|
148
|
0
|
149 call PLED_boot ; PLED boot (Incl. Clear Screen!)
|
|
150 WIN_TOP .0
|
|
151 WIN_LEFT .0
|
|
152 WIN_FONT FT_SMALL
|
|
153 WIN_INVERT .0 ; Init new Wordprocessor
|
|
154 movlw 0xFF
|
|
155 movwf oled1_temp
|
|
156 movff oled1_temp,win_color1
|
|
157 movlw 0xFF
|
|
158 movwf oled1_temp
|
|
159 movff oled1_temp,win_color2
|
|
160 call I2CReset ; Just in Case any I2C device blocks the Bus
|
|
161 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure
|
|
162 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure
|
|
163
|
|
164 ; Check if new CF were added in the last firmware version
|
|
165 clrf EEADRH
|
|
166 read_int_eeprom d'92' ; Read number of CF used in this firmware
|
|
167 movlw max_custom_number ; Defined in definitions.asm
|
|
168 cpfseq EEDATA ; Compare with last version
|
|
169 bra restart_01 ; New CF, show warning and store new number
|
|
170 bra restart_1 ; No new CF, continue with boot
|
|
171 restart_01:
|
|
172 ; Save new number of current CF count
|
|
173 rcall display_new_cf_installed; Show warning
|
|
174 movlw max_custom_number ; Defined in definitions.asm
|
|
175 movwf EEDATA
|
|
176 write_int_eeprom d'92' ; Store number of CF used in this firmware
|
|
177
|
|
178 restart_1:
|
15
|
179 ; btfss pressure_refresh ; Wait for pressure sensor...
|
|
180 ; bra restart_1 ; loop until pressure and temp stable
|
12
|
181 ;
|
0
|
182
|
|
183 ; Set Debug mode?
|
|
184 read_int_eeprom d'39'
|
|
185 bsf debug_mode
|
|
186 movlw d'1'
|
|
187 cpfseq EEDATA
|
|
188 bcf debug_mode ; clear flag if <> 1
|
|
189
|
|
190 goto surfloop ; Jump to Surfaceloop!
|
|
191
|
|
192
|
|
193 display_new_cf_installed:
|
|
194 call PLED_new_cf_warning ; Display new CF warning screen
|
|
195 movlw d'20' ; timeout for warning screen
|
|
196 bra startup_screen3a ; Will RETURN after timeout or button press
|
|
197
|
|
198 restart_set_modes_and_flags: ; "Call"ed from divemode, as well!
|
|
199 bcf gauge_mode
|
|
200 bcf FLAG_const_ppO2_mode
|
|
201 bcf FLAG_apnoe_mode
|
45
|
202
|
|
203 ; Pre-load modes for OC, GF 90/90 and no Aponoe or Gauge.
|
|
204 movlw d'0'
|
|
205 movwf wait_temp
|
|
206 movff wait_temp,char_I_deco_model ; Clear Flagbyte
|
|
207 ; Load GF values into RAM
|
|
208 movlw d'90'
|
|
209 movwf wait_temp
|
|
210 movff wait_temp,char_I_GF_Lo_percentage
|
|
211 movff wait_temp,char_I_GF_Hi_percentage ; Set to 90/90...
|
0
|
212 clrf EEADRH
|
|
213 read_int_eeprom d'34' ; Read deco data
|
|
214 movlw d'1' ; Gauge mode
|
|
215 cpfseq EEDATA
|
|
216 bra restart_3_test_ppO2_mode; check for ppO2 mode
|
|
217 bsf gauge_mode ; Set flag for gauge mode
|
|
218 return ; start in Surfacemode
|
|
219 restart_3_test_ppO2_mode:
|
|
220 movlw d'2' ; const ppO2 mode
|
|
221 cpfseq EEDATA
|
|
222 bra restart_3_test_apnoe_mode; check for apnoe mode
|
|
223 bsf FLAG_const_ppO2_mode ; Set flag for ppO2 mode
|
|
224 return ; start in Surfacemode
|
|
225 restart_3_test_apnoe_mode:
|
|
226 movlw d'3' ; Apnoe mode
|
|
227 cpfseq EEDATA
|
|
228 bra restart_4_test_gf_mode ; check for GF OC mode
|
|
229 bsf FLAG_apnoe_mode ; Set flag for Apnoe Mode
|
|
230 return ; start in Surfacemode
|
|
231 restart_4_test_gf_mode:
|
|
232 movlw d'4' ; GF OC mode
|
|
233 cpfseq EEDATA
|
|
234 bra restart_5_test_gfO2_mode; check for GF CC mode
|
|
235 movlw d'1'
|
|
236 movwf wait_temp
|
|
237 movff wait_temp,char_I_deco_model ; Set Flagbyte for GF method
|
45
|
238 ; Load GF values into RAM
|
|
239 GETCUSTOM8 d'32' ; GF low
|
|
240 movff EEDATA,char_I_GF_Lo_percentage
|
|
241 GETCUSTOM8 d'33' ; GF high
|
|
242 movff EEDATA,char_I_GF_Hi_percentage
|
0
|
243 return ; start in Surfacemode
|
|
244 restart_5_test_gfO2_mode:
|
|
245 movlw d'5' ; GF CC mode
|
|
246 cpfseq EEDATA
|
|
247 return ; Start in Surfacemode
|
|
248 bsf FLAG_const_ppO2_mode ; Set flag for ppO2 mode
|
|
249 movlw d'1'
|
|
250 movwf wait_temp
|
|
251 movff wait_temp,char_I_deco_model ; Set Flagbyte for GF method
|
45
|
252 ; Load GF values into RAM
|
|
253 GETCUSTOM8 d'32' ; GF low
|
|
254 movff EEDATA,char_I_GF_Lo_percentage
|
|
255 GETCUSTOM8 d'33' ; GF high
|
|
256 movff EEDATA,char_I_GF_Hi_percentage
|
0
|
257 return ; start in Surfacemode
|
|
258
|
|
259 startup_screen1:
|
|
260 call PLED_ClearScreen
|
|
261 call PLED_startupscreen1 ; show startup sreen
|
|
262 startup_screen1_2:
|
|
263 movlw d'10' ; timeout for startup screen
|
|
264 movwf temp1
|
|
265 WAITMS d'200'
|
|
266 bcf switch_left
|
|
267 bcf switch_right
|
|
268 screen1_loop:
|
|
269 btfsc onesecupdate ; do every second tasks?
|
|
270 call set_dive_modes ; tests if depth>threshold
|
|
271 btfsc onesecupdate ; do every second tasks?
|
|
272 decf temp1,F
|
|
273 bcf onesecupdate ; every second tasks done
|
|
274
|
|
275 tstfsz temp1 ; timout occured?
|
|
276 bra screen1_loop2 ; no
|
|
277 return
|
|
278
|
|
279 screen1_loop2:
|
|
280 btfsc divemode ; Divemode active?
|
|
281 return
|
|
282 btfsc switch_left ; Ack?
|
|
283 return
|
|
284 btfsc switch_right ; Ack?
|
|
285 return
|
|
286 bra screen1_loop ; loop screen
|
|
287
|
|
288 startup_screen2:
|
|
289 call PLED_ClearScreen ; Page 1
|
|
290 call PLED_startupscreen2 ; show startup sreen
|
|
291 bra startup_screen1_2
|
|
292
|
|
293 startup_screen3a:; WARNING: Also used for decodescriptions and CF Warning screen!
|
|
294 movwf temp1
|
|
295 WAITMS d'200'
|
|
296 bcf switch_left
|
|
297 bcf switch_right
|
|
298 screen3_loop:
|
|
299 btfsc onesecupdate ; do every second tasks?
|
|
300 call set_dive_modes ; tests if depth>threshold
|
|
301
|
|
302 btfsc onesecupdate ; do every second tasks?
|
|
303 decf temp1,F
|
|
304 bcf onesecupdate ; every second tasks done
|
|
305
|
|
306 tstfsz temp1 ; timout occured?
|
|
307 bra screen3_loop2 ; no
|
|
308 return
|
|
309 screen3_loop2:
|
|
310 btfsc switch_left ; Ack?
|
|
311 return
|
|
312 btfsc switch_right ; Ack?
|
|
313 return
|
|
314 bra screen3_loop ; loop screen
|
|
315
|
|
316 init:
|
|
317 movlw b'01101100' ; 4MHz (x4 PLL)
|
|
318 movwf OSCCON
|
|
319
|
|
320 movlw b'00010001' ; I/O Ports
|
|
321 movwf TRISA
|
|
322 clrf PORTA
|
|
323 movlw b'00000011'
|
|
324 movwf TRISB
|
|
325 clrf PORTB
|
|
326 movlw b'11011101' ; UART
|
|
327 movwf TRISC
|
|
328 clrf PORTC
|
|
329 movlw b'00000000'
|
|
330 movwf TRISE
|
|
331 clrf PORTE
|
|
332 movlw b'00000000'
|
|
333 movwf TRISD
|
|
334 clrf PORTD
|
|
335
|
|
336 movlw b'01000000' ; Bit6: PPL enable
|
|
337 movwf OSCTUNE
|
|
338
|
|
339 movlw b'00011111' ; Timer0
|
|
340 movwf T0CON
|
|
341
|
|
342 movlw b'00000111' ; Timer1
|
|
343 movwf T1CON
|
|
344
|
|
345 movlw b'11010000' ; Interrups
|
|
346 movwf INTCON
|
|
347 movlw b'00000101'
|
|
348 movwf INTCON2
|
|
349 movlw b'00001000'
|
|
350 movwf INTCON3
|
|
351 movlw b'00100001'
|
|
352 movwf PIE1
|
|
353 movlw b'00000000'
|
|
354 movwf PIE2
|
|
355 clrf RCON
|
|
356
|
|
357 movlw b'00000000' ; A/D Converter
|
|
358 movwf ADCON0
|
|
359 movlw b'00001110'
|
|
360 movwf ADCON1
|
|
361 movlw b'10001010' ; Right justified
|
|
362 movwf ADCON2
|
|
363
|
|
364 clrf SSPCON1 ; Set I²C Mode
|
|
365 movlw b'00000000'
|
|
366 movwf SSPSTAT
|
|
367 movlw b'00101000'
|
|
368 movwf SSPCON1
|
|
369 movlw b'00000000'
|
|
370 movwf SSPCON2
|
|
371 movlw d'8' ; 400kHz I2C clock @ 16MHz Fcy
|
|
372 movwf SSPADD
|
|
373
|
|
374 clrf CCP1CON ; PWM Module off
|
|
375 clrf ECCP1CON ; PWM Module off
|
|
376
|
|
377 movlw b'00000111' ; Comperator Module off
|
|
378 movwf CMCON
|
|
379
|
|
380 movlw b'00100000'
|
|
381 movwf CANCON ; ECAN Module OFF
|
|
382
|
|
383 movlw b'00100100' ; UART
|
|
384 movwf TXSTA
|
|
385 movlw b'10010000'
|
|
386 movwf RCSTA
|
|
387 movlw b'00001000'
|
|
388 movwf BAUDCON
|
|
389 clrf SPBRGH
|
|
390 movlw d'34'
|
|
391 movwf SPBRG
|
|
392 clrf RCREG
|
|
393 clrf PIR1
|
|
394 return
|