annotate code_part1/OSTC_code_asm_part1/sleepmode.asm @ 640:50ba6255f53e

ccr menu
author heinrichsweikamp
date Thu, 20 Sep 2012 14:29:58 +0200
parents bab5a9fc1b10
children e6ac142e82b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
1 ; OSTC - diving computer code
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
2 ; Copyright (C) 2008 HeinrichsWeikamp GbR
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
3 ; This program is free software: you can redistribute it and/or modify
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
4 ; it under the terms of the GNU General Public License as published by
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
5 ; the Free Software Foundation, either version 3 of the License, or
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
6 ; (at your option) any later version.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
7 ; This program is distributed in the hope that it will be useful,
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
8 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
9 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
10 ; GNU General Public License for more details.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
11 ; You should have received a copy of the GNU General Public License
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
12 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
13 ; Routines for sleepmode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
14 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
15 ; written: 050520
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
16 ; last updated: 090507
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
17 ; known bugs:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
18 ; ToDo:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
19 sleeploop: ; enter sleepmode!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
20 ; first check if the 16 hash char are=0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
21 lfsr FSR2, char_O_hash
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
22 movlw d'16'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
23 movwf temp1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
24 sleeploop1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
25 tstfsz POSTINC2 ; Test hash values
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
26 bra sleeploop2 ; At least one char is not zero -> Do not build hash
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
27 decfsz temp1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
28 bra sleeploop1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
29 ; build hash (about 90sek @ 16MHz)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
30 call PLED_ClearScreen ; clear
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
31 DISPLAYTEXT .1 ; "Building MD2 hash"
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
32 DISPLAYTEXT .2 ; "Please wait..."
116
14a074e1a375 Split C code, and use direct linking.
JeanDo
parents: 21
diff changeset
33 call deco_hash ; calculate MD2 hash
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
34 movlb b'00000001' ; Back to Bank1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
35 sleeploop2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
36 call PLED_DisplayOff ; display off
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
37 call disable_rs232 ; disable UART module
626
bab5a9fc1b10 restore last used customview in dive- and surface-mode
heinrichsweikamp
parents: 497
diff changeset
38
bab5a9fc1b10 restore last used customview in dive- and surface-mode
heinrichsweikamp
parents: 497
diff changeset
39 ; Save surface mode custom view
bab5a9fc1b10 restore last used customview in dive- and surface-mode
heinrichsweikamp
parents: 497
diff changeset
40 movff menupos3,EEDATA ; Copy to EEDATA
bab5a9fc1b10 restore last used customview in dive- and surface-mode
heinrichsweikamp
parents: 497
diff changeset
41 write_int_eeprom d'93' ; Write last selected customview surface mode into EEPROM
bab5a9fc1b10 restore last used customview in dive- and surface-mode
heinrichsweikamp
parents: 497
diff changeset
42
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
43 clrf divemins+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
44 clrf divemins+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
45 bcf TRISB,6
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
46 bcf TRISB,7
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
47 bcf PORTB,6
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
48 bcf PORTB,7 ; Disable UART
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
49 sleeploop_loop:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
50 btfsc oneminupdate ; one minute in sleep?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
51 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
52
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
53 btfsc onesecupdate ; one second in sleep?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
54 rcall onesec_sleep ; check switches, check pressure sensor, etc.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
55
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
56 btfss sleepmode ; wake up? (This bit will be set in other routines)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
57 goto restart ; yes
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
58 nop
153
17de42ab02b6 realtime clock defaults
heinrichsweikamp
parents: 125
diff changeset
59 btfss nsm
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
60 sleep ; Sleep until Timer1 will wake up the device
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
61 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
62 bra sleeploop_loop ; do loop until someting happens
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
63
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
64
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
65 onemin_sleep:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
66 call get_battery_voltage ; get battery voltage
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
67 btfsc enter_error_sleep ; Enter Fatal Error Routine?
16
01510acaeb11 1.54 rc2
heinrichsweikamp
parents: 0
diff changeset
68 call fatal_error_sleep ; Yes (In Sleepmode_vxx.asm!)
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
69
354
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
70 ;---- adjust airpressure compensation any 15 minutes
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
71 incf divemins+1,F ; counts to 14...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
72 movlw d'14'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
73 cpfsgt divemins+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
74 bra onemin_sleep2 ; 15 minutes not done!
354
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
75 clrf divemins+1 ; reset counter
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
76
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
77 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
78
357
562f1bc79f3c Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents: 341
diff changeset
79 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility
562f1bc79f3c Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents: 341
diff changeset
80
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
81 call check_temp_extrema ; Check for temperature extremas
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
82
116
14a074e1a375 Split C code, and use direct linking.
JeanDo
parents: 21
diff changeset
83 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
84 movlb b'00000001'
354
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
85
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
86 movff last_surfpressure_15min+0,last_surfpressure_30min+0 ; save older airpressure
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
87 movff last_surfpressure_15min+1,last_surfpressure_30min+1 ; save older airpressure
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
88 SAFE_2BYTE_COPY amb_pressure, last_surfpressure_15min ; save new airpressure
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
89
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
90 GETCUSTOM15 d'7' ; loads max_sufpressure into lo, hi
398
ab962c4b19d6 Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents: 361
diff changeset
91 movff lo,sub_a+0 ; max. "allowed" airpressure in mbar
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
92 movff hi,sub_a+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
93 movff last_surfpressure_15min+0,sub_b+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
94 movff last_surfpressure_15min+1,sub_b+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
95 call sub16 ; sub_c = sub_a - sub_b
354
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
96 btfss neg_flag ; Is 1080mbar < amb_pressure ?
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
97 bra onemin_sleep2 ; NO: current airpressure is lower then "allowed" airpressure, ok!
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
98
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
99 ; not ok! Overwrite with max. "allowed" airpressure
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
100 GETCUSTOM15 d'7' ; loads max_sufpressure into lo, hi
398
ab962c4b19d6 Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents: 361
diff changeset
101 movff lo,last_surfpressure_15min+0 ; max. "allowed" airpressure in mbar
ab962c4b19d6 Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents: 361
diff changeset
102 movff hi,last_surfpressure_15min+1 ; max. "allowed" airpressure in mbar
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
103
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
104 onemin_sleep2:
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 297
diff changeset
105 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; LOW copy pressure to deco routine
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
106 GETCUSTOM8 d'11' ; Saturation multiplier %
251
f0cba9cff25c Still hunting for bb13...
JeanDo
parents: 213
diff changeset
107 movff WREG,char_I_saturation_multiplier
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
108 GETCUSTOM8 d'12' ; Desaturation multiplier %
251
f0cba9cff25c Still hunting for bb13...
JeanDo
parents: 213
diff changeset
109 movff WREG,char_I_desaturation_multiplier
116
14a074e1a375 Split C code, and use direct linking.
JeanDo
parents: 21
diff changeset
110 call deco_calc_wo_deco_step_1_min ; "calc_tissue_sleep"
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
111 movlb b'00000001' ; RAM Bank1 selected
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
112
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
113 bcf oneminupdate ; all done
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
114 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
115
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
116 onesec_sleep:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
117 call test_charger ; charger on?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
118
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
119 btfss nofly_active
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
120 bra onesec_sleep_nonofly
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
121
21
73014f788032 1.60 stable rc1
heinrichsweikamp
parents: 18
diff changeset
122 bsf LED_blue ; Set nofly LED
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
123
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
124 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
125 sleep
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
126 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
127
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
128 onesec_sleep_nonofly:
21
73014f788032 1.60 stable rc1
heinrichsweikamp
parents: 18
diff changeset
129 bcf LED_blue ; Clear nofly LED
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
130 incf divemins+0,F ; counts to #test_pressure_in_sleep (5)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
131 movlw d'5'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
132 cpfsgt divemins+0 ; here: temp variable
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
133 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet
354
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
134 clrf divemins+0
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
135
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
136 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!)
421
af2894e5cda4 copy from amb_pressure_avg to amb_pressure for compatibility
heinrichsweikamp
parents: 398
diff changeset
137 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
138
361
88660a400338 Updated 64K logbook to changeset 360.
JeanDo
parents: 357 354
diff changeset
139 ; compare current ambient pressure with threshold CF6==1160mbar.
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
140 GETCUSTOM15 d'6' ; loads pressure threshold into lo,hi
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
141 movff lo,sub_a+0 ; power on if ambient pressure is greater threshold
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
142 movff hi,sub_a+1
361
88660a400338 Updated 64K logbook to changeset 360.
JeanDo
parents: 357 354
diff changeset
143 SAFE_2BYTE_COPY amb_pressure_avg, sub_b
88660a400338 Updated 64K logbook to changeset 360.
JeanDo
parents: 357 354
diff changeset
144 call sub16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ?
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
145 bsf sleepmode
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
146 btfsc neg_flag ; Wake up from Sleep?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
147 bcf sleepmode ; amb_pressure>pressure_offset_divemode: wake up!
354
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
148
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
149 onesec_sleep1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
150 bcf onesecupdate ; all done.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
151 btfsc switch_left
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
152 bra onesec_sleep1a
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
153 btfsc switch_right
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
154 bra onesec_sleep1a
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
155 ; No button pressed
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
156 bcf INTCON,INT0IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
157 bcf INTCON3,INT1IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
158 bcf switch_right
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
159 bcf switch_left
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
160 bcf T0CON,TMR0ON ; Stop Timer 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
161 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
162 onesec_sleep1a: ; At least one button pressed....
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
163 bcf INTCON,INT0IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
164 bcf INTCON3,INT1IF ; Clear flag
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
165 bcf switch_right
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
166 bcf switch_left
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
167 bcf T0CON,TMR0ON ; Stop Timer 0
354
cec312042b94 Fix sub16 neg detect (related to bug #44)
JeanDo
parents: 341
diff changeset
168 bcf sleepmode ; wake up!
125
2907b42c195b Altimeter:
JeanDo
parents: 116
diff changeset
169
213
d19445e0cb2f BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents: 153
diff changeset
170 ; Restart altimeter averaging, so next averaging starts right over...
d19445e0cb2f BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents: 153
diff changeset
171 call altimeter_restart
125
2907b42c195b Altimeter:
JeanDo
parents: 116
diff changeset
172
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
173 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
174
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
175 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
176 call get_temperature_start ; and start temperature integration (73,5us)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
177 sleep
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
178 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
179 sleep
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
180 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
181 sleep ; Wait at least 35ms (every 16.5ms Timer1 wakeup)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
182 call get_temperature_value ; State 1: Get temperature
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
183 call get_pressure_start ; Start pressure integration.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
184 sleep
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
185 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
186 sleep
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
187 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
188 sleep ; Wait at least 35ms (every 16.5ms Timer1 wakeup)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
189 call get_pressure_value ; State2: Get pressure (51us)
357
562f1bc79f3c Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents: 341
diff changeset
190 clrf amb_pressure_avg+0
562f1bc79f3c Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents: 341
diff changeset
191 clrf amb_pressure_avg+1 ; clear for sleep routine
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
192 call calculate_compensation ; calculate temperature compensated pressure (233us)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
193 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
194
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
195 fatal_error_sleep:
16
01510acaeb11 1.54 rc2
heinrichsweikamp
parents: 0
diff changeset
196 WAITMS d'250'
01510acaeb11 1.54 rc2
heinrichsweikamp
parents: 0
diff changeset
197 WAITMS d'250'
01510acaeb11 1.54 rc2
heinrichsweikamp
parents: 0
diff changeset
198 WAITMS d'250'
01510acaeb11 1.54 rc2
heinrichsweikamp
parents: 0
diff changeset
199 WAITMS d'250'
01510acaeb11 1.54 rc2
heinrichsweikamp
parents: 0
diff changeset
200 call get_battery_voltage ; get battery voltage
01510acaeb11 1.54 rc2
heinrichsweikamp
parents: 0
diff changeset
201 btfss enter_error_sleep ; REALLY enter Fatal Error Routine?
01510acaeb11 1.54 rc2
heinrichsweikamp
parents: 0
diff changeset
202 return ; No!
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
203 clrf INTCON
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
204 clrf INTCON2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
205 clrf INTCON3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
206 bcf ADCON0,0 ; AD converter off
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
207 call disable_rs232 ; disable UART module
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
208 movlw b'00010000'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
209 movwf TRISA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
210 clrf PORTA ; And pulled to GND
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
211 clrf TRISB ; All output
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
212 clrf PORTB ; And pulled to GND
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
213 movlw b'00011101' ; UART
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
214 movwf TRISC
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
215 clrf PORTC ; And pulled to GND
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
216 clrf TRISD ; All output
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
217 clrf PORTD ; And pulled to GND
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
218 clrf TRISE ; All output
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
219 clrf PORTE ; And pulled to GND
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
220 clrf T0CON ; Timer OFF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
221 clrf T1CON ; Timer OFF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
222 clrf T2CON ; Timer OFF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
223 clrf OSCTUNE
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
224 movlw b'00000010' ; 31kHz
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
225 movwf OSCCON
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
226 bsf WDTCON,0 ; Watchdog timer on...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
227 fatal_error_sleep_loop: ; Device will never quit this loop!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
228 movff fatal_error_code,temp4
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
229 movlw d'15'
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
230 movwf temp1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
231 fatal_error_sleep_loop1:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
232 sleep
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
233 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
234 decfsz temp1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
235 bra fatal_error_sleep_loop1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
236 fatal_error_sleep_loop2:
21
73014f788032 1.60 stable rc1
heinrichsweikamp
parents: 18
diff changeset
237 bsf LED_red
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
238 clrwdt
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
239 WAIT10US d'5'
21
73014f788032 1.60 stable rc1
heinrichsweikamp
parents: 18
diff changeset
240 bcf LED_red
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
241 sleep
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
242 nop
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
243 decfsz temp4,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
244 bra fatal_error_sleep_loop2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
245 bra fatal_error_sleep_loop