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
|
|
79 movff WREG,unused_x24B
|
|
80 ; call deco_main_clear_tissue ;
|
|
81 ; movlb b'00000001' ; select ram bank 1
|
0
|
82 call deco_main_calc_desaturation_time; calculate desaturation time
|
|
83 movlb b'00000001' ; select ram bank 1
|
|
84 call main_clear_CNS_fraction ; clear CNS
|
|
85 movlb b'00000001' ; select ram bank 1
|
|
86 call calc_deko_surfmode ; calculate desaturation every minute
|
|
87 movlb b'00000001' ; select ram bank 1
|
|
88 call deco_main_calc_wo_deco_step_1_m ; calculate deco in surface mode
|
|
89 movlb b'00000001' ; select ram bank 1
|
|
90
|
|
91 ; check firmware and reset Custom Functions after an update
|
|
92 movlw LOW 0x101
|
|
93 movwf EEADR
|
|
94 movlw HIGH 0x101
|
|
95 movwf EEADRH
|
|
96 call read_eeprom ; read current version x
|
|
97 movff EEDATA,temp1
|
|
98 incf EEADR,F ; set to 0x102
|
|
99 call read_eeprom ; read current version y
|
|
100 movff EEDATA,temp2
|
|
101 clrf EEADRH ; Reset EEADRH
|
|
102
|
|
103 movlw softwareversion_x
|
|
104 cpfseq temp1 ; compare version x
|
|
105 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM
|
|
106
|
|
107 movlw softwareversion_y
|
|
108 cpfseq temp2 ; compare version y
|
|
109 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM
|
|
110 bra restart ; x and y are equal -> do not reset cf
|
|
111
|
|
112 check_firmware_new:
|
|
113 movlw LOW 0x101 ; store current version in EEPROM
|
|
114 movwf EEADR
|
|
115 movlw HIGH 0x101
|
|
116 movwf EEADRH
|
|
117 movlw softwareversion_x
|
|
118 movwf EEDATA
|
|
119 call write_eeprom ; write version x
|
|
120 incf EEADR,F ; set to 0x102
|
|
121 movlw softwareversion_y
|
|
122 movwf EEDATA
|
|
123 call write_eeprom ; write version y
|
|
124 clrf EEADRH ; Reset EEADRH
|
|
125 ; goto reset_all_cf ; resets all custom functions bank0 and bank1 and jumps to "restart"
|
3
|
126 goto reset_all_cf_bank1 ; resets all custom functions bank1 and jumps to "restart"
|
0
|
127
|
|
128 restart:
|
21
|
129 bcf LED_red
|
|
130 bcf LED_blue ; all LEDs off
|
15
|
131
|
|
132 clrf flag1 ; clear all flags
|
|
133 clrf flag2
|
|
134 clrf flag3
|
|
135 clrf flag4
|
|
136 clrf flag5
|
|
137 clrf flag6
|
|
138 clrf flag7
|
|
139 clrf flag8
|
|
140 clrf flag9
|
|
141 clrf flag10
|
|
142 clrf flag11
|
|
143 clrf flag12
|
|
144 clrf flag13
|
|
145 clrf flag14
|
|
146 clrf flag15
|
|
147
|
0
|
148 call PLED_boot ; PLED boot (Incl. Clear Screen!)
|
|
149 WIN_TOP .0
|
|
150 WIN_LEFT .0
|
|
151 WIN_FONT FT_SMALL
|
|
152 WIN_INVERT .0 ; Init new Wordprocessor
|
|
153 movlw 0xFF
|
|
154 movwf oled1_temp
|
|
155 movff oled1_temp,win_color1
|
|
156 movlw 0xFF
|
|
157 movwf oled1_temp
|
|
158 movff oled1_temp,win_color2
|
|
159 call I2CReset ; Just in Case any I2C device blocks the Bus
|
|
160 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure
|
|
161 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure
|
|
162
|
|
163 ; Check if new CF were added in the last firmware version
|
|
164 clrf EEADRH
|
|
165 read_int_eeprom d'92' ; Read number of CF used in this firmware
|
|
166 movlw max_custom_number ; Defined in definitions.asm
|
|
167 cpfseq EEDATA ; Compare with last version
|
|
168 bra restart_01 ; New CF, show warning and store new number
|
|
169 bra restart_1 ; No new CF, continue with boot
|
|
170 restart_01:
|
|
171 ; Save new number of current CF count
|
|
172 rcall display_new_cf_installed; Show warning
|
|
173 movlw max_custom_number ; Defined in definitions.asm
|
|
174 movwf EEDATA
|
|
175 write_int_eeprom d'92' ; Store number of CF used in this firmware
|
|
176
|
|
177 restart_1:
|
15
|
178 ; btfss pressure_refresh ; Wait for pressure sensor...
|
|
179 ; bra restart_1 ; loop until pressure and temp stable
|
12
|
180 ;
|
0
|
181
|
|
182 ; Set Debug mode?
|
|
183 read_int_eeprom d'39'
|
|
184 bsf debug_mode
|
|
185 movlw d'1'
|
|
186 cpfseq EEDATA
|
|
187 bcf debug_mode ; clear flag if <> 1
|
|
188
|
|
189 goto surfloop ; Jump to Surfaceloop!
|
|
190
|
|
191
|
|
192 display_new_cf_installed:
|
|
193 call PLED_new_cf_warning ; Display new CF warning screen
|
|
194 movlw d'20' ; timeout for warning screen
|
|
195 bra startup_screen3a ; Will RETURN after timeout or button press
|
|
196
|
|
197 restart_set_modes_and_flags: ; "Call"ed from divemode, as well!
|
|
198 bcf gauge_mode
|
|
199 bcf FLAG_const_ppO2_mode
|
|
200 bcf FLAG_apnoe_mode
|
|
201 clrf EEADRH
|
|
202 read_int_eeprom d'34' ; Read deco data
|
|
203 movlw d'1' ; Gauge mode
|
|
204 cpfseq EEDATA
|
|
205 bra restart_3_test_ppO2_mode; check for ppO2 mode
|
|
206 bsf gauge_mode ; Set flag for gauge mode
|
|
207 movlw d'0'
|
|
208 movwf wait_temp
|
|
209 movff wait_temp,char_I_deco_model ; Clear Flagbyte
|
|
210 return ; start in Surfacemode
|
|
211 restart_3_test_ppO2_mode:
|
|
212 movlw d'2' ; const ppO2 mode
|
|
213 cpfseq EEDATA
|
|
214 bra restart_3_test_apnoe_mode; check for apnoe mode
|
|
215 bsf FLAG_const_ppO2_mode ; Set flag for ppO2 mode
|
|
216 movlw d'0'
|
|
217 movwf wait_temp
|
|
218 movff wait_temp,char_I_deco_model ; Clear Flagbyte
|
|
219 return ; start in Surfacemode
|
|
220 restart_3_test_apnoe_mode:
|
|
221 movlw d'3' ; Apnoe mode
|
|
222 cpfseq EEDATA
|
|
223 bra restart_4_test_gf_mode ; check for GF OC mode
|
|
224 bsf FLAG_apnoe_mode ; Set flag for Apnoe Mode
|
|
225 movlw d'0'
|
|
226 movwf wait_temp
|
|
227 movff wait_temp,char_I_deco_model ; Clear Flagbyte
|
|
228 return ; start in Surfacemode
|
|
229 restart_4_test_gf_mode:
|
|
230 movlw d'4' ; GF OC mode
|
|
231 cpfseq EEDATA
|
|
232 bra restart_5_test_gfO2_mode; check for GF CC mode
|
|
233 movlw d'1'
|
|
234 movwf wait_temp
|
|
235 movff wait_temp,char_I_deco_model ; Set Flagbyte for GF method
|
|
236 return ; start in Surfacemode
|
|
237 restart_5_test_gfO2_mode:
|
|
238 movlw d'5' ; GF CC mode
|
|
239 cpfseq EEDATA
|
|
240 return ; Start in Surfacemode
|
|
241 bsf FLAG_const_ppO2_mode ; Set flag for ppO2 mode
|
|
242 movlw d'1'
|
|
243 movwf wait_temp
|
|
244 movff wait_temp,char_I_deco_model ; Set Flagbyte for GF method
|
|
245 return ; start in Surfacemode
|
|
246
|
|
247 startup_screen1:
|
|
248 call PLED_ClearScreen
|
|
249 call PLED_startupscreen1 ; show startup sreen
|
|
250 startup_screen1_2:
|
|
251 movlw d'10' ; timeout for startup screen
|
|
252 movwf temp1
|
|
253 WAITMS d'200'
|
|
254 bcf switch_left
|
|
255 bcf switch_right
|
|
256 screen1_loop:
|
|
257 btfsc onesecupdate ; do every second tasks?
|
|
258 call set_dive_modes ; tests if depth>threshold
|
|
259 btfsc onesecupdate ; do every second tasks?
|
|
260 decf temp1,F
|
|
261 bcf onesecupdate ; every second tasks done
|
|
262
|
|
263 tstfsz temp1 ; timout occured?
|
|
264 bra screen1_loop2 ; no
|
|
265 return
|
|
266
|
|
267 screen1_loop2:
|
|
268 btfsc divemode ; Divemode active?
|
|
269 return
|
|
270 btfsc switch_left ; Ack?
|
|
271 return
|
|
272 btfsc switch_right ; Ack?
|
|
273 return
|
|
274 bra screen1_loop ; loop screen
|
|
275
|
|
276 startup_screen2:
|
|
277 call PLED_ClearScreen ; Page 1
|
|
278 call PLED_startupscreen2 ; show startup sreen
|
|
279 bra startup_screen1_2
|
|
280
|
|
281 startup_screen3a:; WARNING: Also used for decodescriptions and CF Warning screen!
|
|
282 movwf temp1
|
|
283 WAITMS d'200'
|
|
284 bcf switch_left
|
|
285 bcf switch_right
|
|
286 screen3_loop:
|
|
287 btfsc onesecupdate ; do every second tasks?
|
|
288 call set_dive_modes ; tests if depth>threshold
|
|
289
|
|
290 btfsc onesecupdate ; do every second tasks?
|
|
291 decf temp1,F
|
|
292 bcf onesecupdate ; every second tasks done
|
|
293
|
|
294 tstfsz temp1 ; timout occured?
|
|
295 bra screen3_loop2 ; no
|
|
296 return
|
|
297 screen3_loop2:
|
|
298 btfsc switch_left ; Ack?
|
|
299 return
|
|
300 btfsc switch_right ; Ack?
|
|
301 return
|
|
302 bra screen3_loop ; loop screen
|
|
303
|
|
304 init:
|
|
305 movlw b'01101100' ; 4MHz (x4 PLL)
|
|
306 movwf OSCCON
|
|
307
|
|
308 movlw b'00010001' ; I/O Ports
|
|
309 movwf TRISA
|
|
310 clrf PORTA
|
|
311 movlw b'00000011'
|
|
312 movwf TRISB
|
|
313 clrf PORTB
|
|
314 movlw b'11011101' ; UART
|
|
315 movwf TRISC
|
|
316 clrf PORTC
|
|
317 movlw b'00000000'
|
|
318 movwf TRISE
|
|
319 clrf PORTE
|
|
320 movlw b'00000000'
|
|
321 movwf TRISD
|
|
322 clrf PORTD
|
|
323
|
|
324 movlw b'01000000' ; Bit6: PPL enable
|
|
325 movwf OSCTUNE
|
|
326
|
|
327 movlw b'00011111' ; Timer0
|
|
328 movwf T0CON
|
|
329
|
|
330 movlw b'00000111' ; Timer1
|
|
331 movwf T1CON
|
|
332
|
|
333 movlw b'11010000' ; Interrups
|
|
334 movwf INTCON
|
|
335 movlw b'00000101'
|
|
336 movwf INTCON2
|
|
337 movlw b'00001000'
|
|
338 movwf INTCON3
|
|
339 movlw b'00100001'
|
|
340 movwf PIE1
|
|
341 movlw b'00000000'
|
|
342 movwf PIE2
|
|
343 clrf RCON
|
|
344
|
|
345 movlw b'00000000' ; A/D Converter
|
|
346 movwf ADCON0
|
|
347 movlw b'00001110'
|
|
348 movwf ADCON1
|
|
349 movlw b'10001010' ; Right justified
|
|
350 movwf ADCON2
|
|
351
|
|
352 clrf SSPCON1 ; Set I²C Mode
|
|
353 movlw b'00000000'
|
|
354 movwf SSPSTAT
|
|
355 movlw b'00101000'
|
|
356 movwf SSPCON1
|
|
357 movlw b'00000000'
|
|
358 movwf SSPCON2
|
|
359 movlw d'8' ; 400kHz I2C clock @ 16MHz Fcy
|
|
360 movwf SSPADD
|
|
361
|
|
362 clrf CCP1CON ; PWM Module off
|
|
363 clrf ECCP1CON ; PWM Module off
|
|
364
|
|
365 movlw b'00000111' ; Comperator Module off
|
|
366 movwf CMCON
|
|
367
|
|
368 movlw b'00100000'
|
|
369 movwf CANCON ; ECAN Module OFF
|
|
370
|
|
371 movlw b'00100100' ; UART
|
|
372 movwf TXSTA
|
|
373 movlw b'10010000'
|
|
374 movwf RCSTA
|
|
375 movlw b'00001000'
|
|
376 movwf BAUDCON
|
|
377 clrf SPBRGH
|
|
378 movlw d'34'
|
|
379 movwf SPBRG
|
|
380 clrf RCREG
|
|
381 clrf PIR1
|
|
382 return
|