Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/start.asm @ 117:d92a6a8ab516
added sample workspace file
| author | heinrichsweikamp |
|---|---|
| date | Sun, 26 Dec 2010 16:47:29 +0100 |
| parents | 14a074e1a375 |
| children | f24137eb85de |
| 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 | |
| 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 | |
|
98
6f8e3a08011e
1.73beta rc1 (Added new customview for divemode)
heinrichsweikamp
parents:
97
diff
changeset
|
32 lfsr FSR0, 10Bh ; Clear rambank 1-9, do not delete RTC registers |
| 0 | 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 | |
| 97 | 43 ; Extra power-up reset jDG jDG jDG jDG |
|
83
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
44 ifdef TESTING |
| 97 | 45 call do_menu_reset_all2 |
|
83
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
46 endif |
|
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
47 ; DONE jDG jDG jDG jDG |
|
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
48 |
| 0 | 49 ; Air pressure compensation after reset |
| 50 call get_calibration_data ; Get calibration data from pressure sensor | |
| 51 | |
| 52 bcf pressure_refresh | |
| 53 wait_start_pressure: | |
| 54 btfss pressure_refresh ; Air pressure compensation | |
| 55 bra wait_start_pressure | |
| 56 | |
| 57 clrf rel_pressure+0 | |
| 58 clrf rel_pressure+1 | |
| 59 clrf surface_interval+0 | |
| 60 clrf surface_interval+1 | |
| 61 | |
| 62 bsf sleepmode ; Routine only works in sleepmode... | |
| 63 call pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | |
| 64 bcf sleepmode ; Normal mode again | |
| 65 | |
| 66 movff amb_pressure+0,last_surfpressure+0 | |
| 67 movff amb_pressure+1,last_surfpressure+1 | |
| 68 movff amb_pressure+0,last_surfpressure_15min+0 | |
| 69 movff amb_pressure+1,last_surfpressure_15min+1 | |
| 70 movff amb_pressure+0,last_surfpressure_30min+0 | |
| 71 movff amb_pressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers | |
| 72 | |
| 73 ; reset deco data | |
| 74 incf nofly_time+0,F ; =1 | |
| 75 clrf wait_temp ; Use as buffer | |
| 76 movff wait_temp,char_I_He_ratio ; No He at the Surface | |
| 77 movlw d'79' ; 79% N2 | |
| 78 movwf wait_temp ; Use as buffer | |
| 79 movff wait_temp,char_I_N2_ratio ; No He at the Surface | |
| 80 movff amb_pressure+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
| 81 movff amb_pressure+1,int_I_pres_respiration+1 | |
| 82 | |
| 31 | 83 movlw d'0' |
| 84 movff WREG,char_I_step_is_1min ; 2 second deco mode | |
| 116 | 85 call deco_clear_tissue ; |
| 86 call deco_calc_desaturation_time ; calculate desaturation time | |
| 87 call deco_clear_CNS_fraction ; clear CNS | |
| 0 | 88 call calc_deko_surfmode ; calculate desaturation every minute |
| 116 | 89 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode |
| 0 | 90 movlb b'00000001' ; select ram bank 1 |
| 91 | |
| 92 ; check firmware and reset Custom Functions after an update | |
| 93 movlw LOW 0x101 | |
| 94 movwf EEADR | |
| 95 movlw HIGH 0x101 | |
| 96 movwf EEADRH | |
| 97 call read_eeprom ; read current version x | |
| 98 movff EEDATA,temp1 | |
| 99 incf EEADR,F ; set to 0x102 | |
| 100 call read_eeprom ; read current version y | |
| 101 movff EEDATA,temp2 | |
| 102 clrf EEADRH ; Reset EEADRH | |
| 103 | |
| 104 movlw softwareversion_x | |
| 105 cpfseq temp1 ; compare version x | |
| 106 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
| 107 | |
| 108 movlw softwareversion_y | |
| 109 cpfseq temp2 ; compare version y | |
| 110 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
| 111 bra restart ; x and y are equal -> do not reset cf | |
| 112 | |
| 113 check_firmware_new: | |
| 114 movlw LOW 0x101 ; store current version in EEPROM | |
| 115 movwf EEADR | |
| 116 movlw HIGH 0x101 | |
| 117 movwf EEADRH | |
| 118 movlw softwareversion_x | |
| 119 movwf EEDATA | |
| 120 call write_eeprom ; write version x | |
| 121 incf EEADR,F ; set to 0x102 | |
| 122 movlw softwareversion_y | |
| 123 movwf EEDATA | |
| 124 call write_eeprom ; write version y | |
| 125 clrf EEADRH ; Reset EEADRH | |
| 62 | 126 ; goto reset_all_cf ; resets all custom functions bank0 and bank1 and jumps to "restart" |
| 52 | 127 ; goto reset_all_cf_bank1 ; resets all custom functions bank1 and jumps to "restart" |
| 0 | 128 |
| 129 restart: | |
| 21 | 130 bcf LED_red |
| 131 bcf LED_blue ; all LEDs off | |
| 43 | 132 GETCUSTOM8 d'48' ; time correction value |
| 133 movff WREG, time_correction_value ; store in Bank0 register | |
| 15 | 134 |
| 135 clrf flag1 ; clear all flags | |
| 136 clrf flag2 | |
| 137 clrf flag3 | |
| 138 clrf flag4 | |
| 139 clrf flag5 | |
| 140 clrf flag6 | |
| 141 clrf flag7 | |
| 142 clrf flag8 | |
| 143 clrf flag9 | |
| 144 clrf flag10 | |
| 145 clrf flag11 | |
| 146 clrf flag12 | |
| 147 clrf flag13 | |
| 148 clrf flag14 | |
| 149 clrf flag15 | |
| 47 | 150 call gassetup_sort_gaslist ; Sorts Gaslist according to change depth |
| 0 | 151 call PLED_boot ; PLED boot (Incl. Clear Screen!) |
| 152 WIN_TOP .0 | |
| 153 WIN_LEFT .0 | |
| 154 WIN_FONT FT_SMALL | |
| 155 WIN_INVERT .0 ; Init new Wordprocessor | |
|
83
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
156 setf WREG |
|
3e351e25f5d1
adding anti-aliased fonts frame and merging some patches from Jeando
heinrichsweikamp
parents:
62
diff
changeset
|
157 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
|
158 movff WREG,win_color2 |
| 0 | 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: | |
| 178 | |
| 179 ; Set Debug mode? | |
| 180 read_int_eeprom d'39' | |
| 181 bsf debug_mode | |
| 182 movlw d'1' | |
| 183 cpfseq EEDATA | |
| 184 bcf debug_mode ; clear flag if <> 1 | |
| 185 | |
| 186 goto surfloop ; Jump to Surfaceloop! | |
| 187 | |
| 188 | |
| 189 display_new_cf_installed: | |
| 190 call PLED_new_cf_warning ; Display new CF warning screen | |
| 191 movlw d'20' ; timeout for warning screen | |
| 192 bra startup_screen3a ; Will RETURN after timeout or button press | |
| 193 | |
| 194 restart_set_modes_and_flags: ; "Call"ed from divemode, as well! | |
| 195 bcf gauge_mode | |
| 196 bcf FLAG_const_ppO2_mode | |
| 197 bcf FLAG_apnoe_mode | |
| 45 | 198 |
| 199 ; Pre-load modes for OC, GF 90/90 and no Aponoe or Gauge. | |
| 200 movlw d'0' | |
| 201 movwf wait_temp | |
| 202 movff wait_temp,char_I_deco_model ; Clear Flagbyte | |
| 203 ; Load GF values into RAM | |
| 204 movlw d'90' | |
| 205 movwf wait_temp | |
| 206 movff wait_temp,char_I_GF_Lo_percentage | |
| 207 movff wait_temp,char_I_GF_Hi_percentage ; Set to 90/90... | |
| 0 | 208 clrf EEADRH |
| 209 read_int_eeprom d'34' ; Read deco data | |
| 210 movlw d'1' ; Gauge mode | |
| 211 cpfseq EEDATA | |
| 212 bra restart_3_test_ppO2_mode; check for ppO2 mode | |
| 213 bsf gauge_mode ; Set flag for gauge mode | |
| 214 return ; start in Surfacemode | |
| 215 restart_3_test_ppO2_mode: | |
| 216 movlw d'2' ; const ppO2 mode | |
| 217 cpfseq EEDATA | |
| 218 bra restart_3_test_apnoe_mode; check for apnoe mode | |
| 219 bsf FLAG_const_ppO2_mode ; Set flag for ppO2 mode | |
| 220 return ; start in Surfacemode | |
| 221 restart_3_test_apnoe_mode: | |
| 222 movlw d'3' ; Apnoe mode | |
| 223 cpfseq EEDATA | |
| 224 bra restart_4_test_gf_mode ; check for GF OC mode | |
| 225 bsf FLAG_apnoe_mode ; Set flag for Apnoe Mode | |
| 226 return ; start in Surfacemode | |
| 227 restart_4_test_gf_mode: | |
| 228 movlw d'4' ; GF OC mode | |
| 229 cpfseq EEDATA | |
| 230 bra restart_5_test_gfO2_mode; check for GF CC mode | |
| 231 movlw d'1' | |
| 232 movwf wait_temp | |
| 233 movff wait_temp,char_I_deco_model ; Set Flagbyte for GF method | |
| 45 | 234 ; Load GF values into RAM |
| 235 GETCUSTOM8 d'32' ; GF low | |
| 236 movff EEDATA,char_I_GF_Lo_percentage | |
| 237 GETCUSTOM8 d'33' ; GF high | |
| 238 movff EEDATA,char_I_GF_Hi_percentage | |
| 0 | 239 return ; start in Surfacemode |
| 240 restart_5_test_gfO2_mode: | |
| 241 movlw d'5' ; GF CC mode | |
| 242 cpfseq EEDATA | |
| 243 return ; Start in Surfacemode | |
| 244 bsf FLAG_const_ppO2_mode ; Set flag for ppO2 mode | |
| 245 movlw d'1' | |
| 246 movwf wait_temp | |
| 247 movff wait_temp,char_I_deco_model ; Set Flagbyte for GF method | |
| 45 | 248 ; Load GF values into RAM |
| 249 GETCUSTOM8 d'32' ; GF low | |
| 250 movff EEDATA,char_I_GF_Lo_percentage | |
| 251 GETCUSTOM8 d'33' ; GF high | |
| 252 movff EEDATA,char_I_GF_Hi_percentage | |
| 0 | 253 return ; start in Surfacemode |
| 254 | |
| 255 startup_screen1: | |
| 256 call PLED_ClearScreen | |
| 257 call PLED_startupscreen1 ; show startup sreen | |
| 258 startup_screen1_2: | |
| 259 movlw d'10' ; timeout for startup screen | |
| 260 movwf temp1 | |
| 261 WAITMS d'200' | |
| 262 bcf switch_left | |
| 263 bcf switch_right | |
| 264 screen1_loop: | |
| 265 btfsc onesecupdate ; do every second tasks? | |
| 266 call set_dive_modes ; tests if depth>threshold | |
| 267 btfsc onesecupdate ; do every second tasks? | |
| 268 decf temp1,F | |
| 269 bcf onesecupdate ; every second tasks done | |
| 270 | |
| 271 tstfsz temp1 ; timout occured? | |
| 272 bra screen1_loop2 ; no | |
| 273 return | |
| 274 | |
| 275 screen1_loop2: | |
| 276 btfsc divemode ; Divemode active? | |
| 277 return | |
| 278 btfsc switch_left ; Ack? | |
| 279 return | |
| 280 btfsc switch_right ; Ack? | |
| 281 return | |
| 282 bra screen1_loop ; loop screen | |
| 283 | |
| 284 startup_screen2: | |
| 285 call PLED_ClearScreen ; Page 1 | |
| 286 call PLED_startupscreen2 ; show startup sreen | |
| 287 bra startup_screen1_2 | |
| 288 | |
| 289 startup_screen3a:; WARNING: Also used for decodescriptions and CF Warning screen! | |
| 290 movwf temp1 | |
| 291 WAITMS d'200' | |
| 292 bcf switch_left | |
| 293 bcf switch_right | |
| 294 screen3_loop: | |
| 295 btfsc onesecupdate ; do every second tasks? | |
| 296 call set_dive_modes ; tests if depth>threshold | |
| 297 | |
| 298 btfsc onesecupdate ; do every second tasks? | |
| 299 decf temp1,F | |
| 300 bcf onesecupdate ; every second tasks done | |
| 301 | |
| 302 tstfsz temp1 ; timout occured? | |
| 303 bra screen3_loop2 ; no | |
| 304 return | |
| 305 screen3_loop2: | |
| 306 btfsc switch_left ; Ack? | |
| 307 return | |
| 308 btfsc switch_right ; Ack? | |
| 309 return | |
| 310 bra screen3_loop ; loop screen | |
| 311 | |
| 312 init: | |
| 313 movlw b'01101100' ; 4MHz (x4 PLL) | |
| 314 movwf OSCCON | |
| 315 | |
| 316 movlw b'00010001' ; I/O Ports | |
| 317 movwf TRISA | |
| 318 clrf PORTA | |
| 319 movlw b'00000011' | |
| 320 movwf TRISB | |
| 321 clrf PORTB | |
| 322 movlw b'11011101' ; UART | |
| 323 movwf TRISC | |
| 324 clrf PORTC | |
| 325 movlw b'00000000' | |
| 326 movwf TRISE | |
| 327 clrf PORTE | |
| 328 movlw b'00000000' | |
| 329 movwf TRISD | |
| 330 clrf PORTD | |
| 331 | |
| 332 movlw b'01000000' ; Bit6: PPL enable | |
| 333 movwf OSCTUNE | |
| 334 | |
| 335 movlw b'00011111' ; Timer0 | |
| 336 movwf T0CON | |
| 337 | |
| 338 movlw b'00000111' ; Timer1 | |
| 339 movwf T1CON | |
| 340 | |
| 341 movlw b'11010000' ; Interrups | |
| 342 movwf INTCON | |
| 343 movlw b'00000101' | |
| 344 movwf INTCON2 | |
| 345 movlw b'00001000' | |
| 346 movwf INTCON3 | |
| 347 movlw b'00100001' | |
| 348 movwf PIE1 | |
| 349 movlw b'00000000' | |
| 350 movwf PIE2 | |
| 351 clrf RCON | |
| 352 | |
| 353 movlw b'00000000' ; A/D Converter | |
| 354 movwf ADCON0 | |
| 355 movlw b'00001110' | |
| 356 movwf ADCON1 | |
| 357 movlw b'10001010' ; Right justified | |
| 358 movwf ADCON2 | |
| 359 | |
| 360 clrf SSPCON1 ; Set I²C Mode | |
| 361 movlw b'00000000' | |
| 362 movwf SSPSTAT | |
| 363 movlw b'00101000' | |
| 364 movwf SSPCON1 | |
| 365 movlw b'00000000' | |
| 366 movwf SSPCON2 | |
| 367 movlw d'8' ; 400kHz I2C clock @ 16MHz Fcy | |
| 368 movwf SSPADD | |
| 369 | |
| 370 clrf CCP1CON ; PWM Module off | |
| 371 clrf ECCP1CON ; PWM Module off | |
| 372 | |
| 373 movlw b'00000111' ; Comperator Module off | |
| 374 movwf CMCON | |
| 375 | |
| 376 movlw b'00100000' | |
| 377 movwf CANCON ; ECAN Module OFF | |
| 378 | |
| 379 movlw b'00100100' ; UART | |
| 380 movwf TXSTA | |
| 381 movlw b'10010000' | |
| 382 movwf RCSTA | |
| 383 movlw b'00001000' | |
| 384 movwf BAUDCON | |
| 385 clrf SPBRGH | |
| 386 movlw d'34' | |
| 387 movwf SPBRG | |
| 388 clrf RCREG | |
| 389 clrf PIR1 | |
| 390 return |
