annotate code_part1/OSTC_code_asm_part1/altimeter.asm @ 816:df8cd5ffd993

BUGFIX: Load first diluent if <> 1 correctly Auto-SP change work...
author heinrichsweikamp
date Sat, 16 May 2015 14:48:26 +0200
parents a5d44fb115a8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
1 ;=============================================================================
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
2 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
3 ; File altimeter.asm
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
4 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
5 ; Altimeter function prototype.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
6 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
7 ; This program is free software: you can redistribute it and/or modify
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
8 ; it under the terms of the GNU General Public License as published by
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
9 ; the Free Software Foundation, either version 3 of the License, or
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
10 ; (at your option) any later version.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
11 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
12 ; This program is distributed in the hope that it will be useful,
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
15 ; GNU General Public License for more details.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
16 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
17 ; You should have received a copy of the GNU General Public License
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
18 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
19 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
20 ; Copyright (c) 2010, JD Gascuel.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
21 ;=============================================================================
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
22 ; HISTORY
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
23 ; 2010-12-15 : [jDG] First prototype with quadratic polynomial ant tp°.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
24 ; 2010-12-28 : [jDG] Use MPLAB Math and C libraries for FP32 computations.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
25 ; 2011-01-02 : [jDG] Edit reference pressure by 0.25 mbar.
214
8a0bbe43df65 (altimeter restart: fix bank addressing)
JeanDo
parents: 213
diff changeset
26 ; 2011-01-31 : [jDG] Better menu: default 1013mbar, and editing by +/- 1mbar.
8a0bbe43df65 (altimeter restart: fix bank addressing)
JeanDo
parents: 213
diff changeset
27 ; 2011-02-23 : [jDG] Fix restart after sleepmode.
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
28 ;
132
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
29 ; Known bug: Simulator reset altitude and reference...
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
30
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
31 altimeter_calc:
214
8a0bbe43df65 (altimeter restart: fix bank addressing)
JeanDo
parents: 213
diff changeset
32 movlb HIGH(pressureAvg) ; Altimeter data in bank 0.
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
33
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
34 movlw HIGH(4*.900) ; Is presure ref bigger than 900mbar
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
35 cpfsgt pressureRef+1
214
8a0bbe43df65 (altimeter restart: fix bank addressing)
JeanDo
parents: 213
diff changeset
36 bra altimeter_reset ; No: Should do a reset now.
162
fdebc43c8372 Fix altimeter auto-reset
JeanDo
parents: 134
diff changeset
37
fdebc43c8372 Fix altimeter auto-reset
JeanDo
parents: 134
diff changeset
38 movlw HIGH(4*.1100) ; Is ref pressure bigger than 1100mbar ?
fdebc43c8372 Fix altimeter auto-reset
JeanDo
parents: 134
diff changeset
39 cpfsgt pressureRef+1
fdebc43c8372 Fix altimeter auto-reset
JeanDo
parents: 134
diff changeset
40 bra altimeter_1 ; No: ok it is valid...
fdebc43c8372 Fix altimeter auto-reset
JeanDo
parents: 134
diff changeset
41
213
d19445e0cb2f BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents: 199
diff changeset
42 ; Reset calibration value to default.
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
43 altimeter_reset:
214
8a0bbe43df65 (altimeter restart: fix bank addressing)
JeanDo
parents: 213
diff changeset
44 movlb HIGH(pressureAvg) ; Altimeter data in bank 0.
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
45 movlw LOW(4*.1013+1) ; Init see level at 1013,25 mbar.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
46 movwf pressureRef+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
47 movlw HIGH(4*.1013+1)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
48 movwf pressureRef+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
49
213
d19445e0cb2f BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents: 199
diff changeset
50 ; Restart averaging. Eg. after a sleep, enables to faster restart with correct
d19445e0cb2f BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents: 199
diff changeset
51 ; values...
d19445e0cb2f BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents: 199
diff changeset
52 altimeter_restart:
214
8a0bbe43df65 (altimeter restart: fix bank addressing)
JeanDo
parents: 213
diff changeset
53 movlb HIGH(pressureAvg) ; Altimeter data in bank 0.
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
54 clrf pressureSum+0 ; Init averaging area
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
55 clrf pressureSum+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
56 clrf pressureCount
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
57
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 214
diff changeset
58 SAFE_2BYTE_COPY amb_pressure, pressureAvg ; And init first average.
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
59
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
60 movlw 4 ; And multiply AVG by 16 to be coherent.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
61 altimeter_reset_1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
62 bcf STATUS,C
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
63 rlcf pressureAvg+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
64 rlcf pressureAvg+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
65 decfsz WREG
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
66 bra altimeter_reset_1
132
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
67
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
68 rcall compute_altitude
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
69
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
70 movlb 1 ; Back to normal bank1.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
71 return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
72
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
73 altimeter_1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
74 ;---- Do a bank-safe 16bit summing -----------------------------------
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 214
diff changeset
75 SAFE_2BYTE_COPY amb_pressure, lo ; And init first average.
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 214
diff changeset
76
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 214
diff changeset
77 movff lo,WREG
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
78 addwf pressureSum+0,F
341
2144f19fa1eb BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents: 214
diff changeset
79 movff hi,WREG
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
80 addwfc pressureSum+1,F
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
81
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
82 incf pressureCount ; Increment count too.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
83 movlw .32 ; Already 32 done ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
84 subwf pressureCount,W
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
85 bnz altimeter_4 ; NO: skip update.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
86
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
87 ;---- Update altitude every 32 pressure measures --------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
88 bcf STATUS,C ; Divide by 2, to store pressure x16
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
89 rrcf pressureSum+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
90 rrcf pressureSum+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
91
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
92 movff pressureSum+0,pressureAvg+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
93 movff pressureSum+1,pressureAvg+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
94
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
95 rcall compute_altitude ; Compute from the averaged value...
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
96
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
97 clrf pressureSum+0 ; And reset sum zone for next averaging.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
98 clrf pressureSum+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
99 clrf pressureCount
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
100
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
101 altimeter_4:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
102 movlb 1 ; make sure to be in normal bank1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
103 return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
104
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
105 ;---- Display result -------------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
106 altimeter_display:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
107 GETCUSTOM8 .49 ; Check CF#49
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
108 btfss WREG,0 ; Enabled ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
109 return ; NO: return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
110
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
111 WIN_TOP .35 ; Custom view drawing zone...
721
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
112 WIN_LEFT .82
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
113 WIN_FONT FT_SMALL
681
6e456a6398e0 Hardware4 support
heinrichsweikamp
parents: 576
diff changeset
114 call DISP_standard_color
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
115
445
6e57b5bb98ce localisation part 1 from Sergei
heinrichsweikamp
parents: 384
diff changeset
116 STRCPY TXT_ALT5
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
117
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
118 movff altitude+0,lo ; BANK-SAFE read altitude
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
119 movff altitude+1,hi
721
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
120 btfss hi,7 ; Is altitude negative ?
166
80de93d72a17 Allow display of altitude <= 0m
JeanDo
parents: 162
diff changeset
121 bra altimeter_2 ; No: just print it
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
122
166
80de93d72a17 Allow display of altitude <= 0m
JeanDo
parents: 162
diff changeset
123 PUTC '-' ; Yes: print the minus sign
80de93d72a17 Allow display of altitude <= 0m
JeanDo
parents: 162
diff changeset
124 comf hi ; And do a 16bit 2-complement.
80de93d72a17 Allow display of altitude <= 0m
JeanDo
parents: 162
diff changeset
125 comf lo
80de93d72a17 Allow display of altitude <= 0m
JeanDo
parents: 162
diff changeset
126 infsnz lo
80de93d72a17 Allow display of altitude <= 0m
JeanDo
parents: 162
diff changeset
127 incf hi
80de93d72a17 Allow display of altitude <= 0m
JeanDo
parents: 162
diff changeset
128
80de93d72a17 Allow display of altitude <= 0m
JeanDo
parents: 162
diff changeset
129 altimeter_2:
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
130 bsf leftbind
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
131 output_16
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
132 bcf leftbind
721
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
133 STRCAT TXT_METER5
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
134 clrf WREG
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
135 movff WREG,letter+.11 ;limit to 12chars
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
136 STRCAT_PRINT ""
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
137 return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
138
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
139 ;=============================================================================
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
140 ; Compute altitude, using the formula:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
141 ; H(P) = 18.787 log10(P0/P) (Log base 10)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
142
721
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
143 ;---- Interface the the Math library -----------------------------------------
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
144 extern __AARGB2 ; A float in fA2, fA1, fA0, fAExo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
145 extern __BARGB2 ; B float in fB2, fB1, fB0, fBExo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
146 extern FLO1632U ; convert uint16 fA+1 --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
147 extern FPD32 ; fp32 divide fA/fB --> fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
148 extern FPM32 ; fp32 multiply fA*fB --> fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
149 extern INT3216 ; convert fp32 fA --> int16 fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
150 #define fA __AARGB2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
151 #define fB __BARGB2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
152
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
153 ;---- Interface to the C library ---------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
154 extern __AARGB3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
155 extern log10 ; float32 log(auto float32)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
156 #define fRet __AARGB3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
157
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
158 compute_altitude:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
159 ; Setup C-code stack, to enable calling the log() function.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
160 lfsr FSR1, c_code_data_stack
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
161 lfsr FSR2, c_code_data_stack
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
162
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
163 ; Convert pressure to float, --> fB
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
164 movff pressureAvg+0, fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
165 movff pressureAvg+1, fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
166 call FLO1632U ; u16 fA[1:2] --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
167 movff fA+0, fB+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
168 movff fA+1, fB+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
169 movff fA+2, fB+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
170 movff fA+3, fB+3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
171
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
172 ; Convert sea-level reference pressure to float, --> fB
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
173 movff pressureRef+0, fA+1 ; Get sea level pressure.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
174 movff pressureRef+1, fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
175 bcf STATUS,C ; Multiply by 4.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
176 rlcf fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
177 rlcf fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
178 bcf STATUS,C
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
179 rlcf fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
180 rlcf fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
181 call FLO1632U ; to float: u16 fA[1:2] --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
182
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
183 ; Divide
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
184 call FPD32 ; fp32 X/Y --> X
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
185
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
186 ; log10()
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
187 movff fA+0, POSTINC1 ; Push X to stack
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
188 movff fA+1, POSTINC1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
189 movff fA+2, POSTINC1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
190 movff fA+3, POSTINC1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
191 call log10 ; log(P0/P)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
192
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
193 movf POSTDEC1,F,ACCESS ; pop argument
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
194 movf POSTDEC1,F,ACCESS
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
195 movf POSTDEC1,F,ACCESS
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
196 movf POSTDEC1,F,ACCESS
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
197
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
198 ; Move log10(P0/P) to fB
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
199 movff fRet+0,fB+0 ; move result to fB
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
200 movff fRet+1,fB+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
201 movff fRet+2,fB+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
202 movff fRet+3,fB+3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
203
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
204 ; Multiply by scaling factor for meters, and standatd atmosphere.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
205 movlw LOW(.18787)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
206 movff WREG, fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
207 movlw HIGH(.18787)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
208 movff WREG, fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
209 call FLO1632U ; u16 fA[1:2] --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
210 call FPM32 ; altitute --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
211
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
212 ; Convert result to int16 --> altitude.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
213 call INT3216 ; fp32 fA --> int16 fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
214 movff fA+1, altitude+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
215 movff fA+2, altitude+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
216
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
217 return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
218
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
219 ;=============================================================================
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
220 ; Altimeter menu
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
221 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
222 ; Edit reference (where altitude = 0) pressure, while displaying corresponding
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
223 ; altitude.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
224 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
225 altimeter_menu:
132
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
226 movff pressureRef+0,WREG ; Make sure it is initialized...
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
227 movff pressureRef+1,fA
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
228 iorwf fA
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
229 bnz altimeter_menu_1 ; Yes: skip reset...
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
230 rcall altimeter_reset
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
231
49bb155ddfbf Fix altimeter after simulator (zero divide -> 32767m)
JeanDo
parents: 125
diff changeset
232 altimeter_menu_1:
681
6e456a6398e0 Hardware4 support
heinrichsweikamp
parents: 576
diff changeset
233 call DISP_ClearScreen ; Menu header.
717
91ae251d379f "ostc3-style" menu titles
heinrichsweikamp
parents: 681
diff changeset
234 call DISP_divemask_color
91ae251d379f "ostc3-style" menu titles
heinrichsweikamp
parents: 681
diff changeset
235 DISPLAYTEXTH .288 ; Title bar
681
6e456a6398e0 Hardware4 support
heinrichsweikamp
parents: 576
diff changeset
236 call DISP_standard_color
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
237
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
238 movlw 2 ; Start menu on line 2.
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
239 movwf menupos
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
240
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
241 altimeter_menu_2:
174
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
242 WIN_FONT 0
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
243 WIN_LEFT .20 ; First line:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
244 WIN_TOP .35
174
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
245 lfsr FSR2,letter
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
246 OUTPUTTEXTH .289 ; Sea ref:
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
247
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
248 movff pressureRef+0, lo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
249 movff pressureRef+1, hi
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
250 bcf STATUS,C ; Divide ref pressure by 4
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
251 rrcf hi ; to get the integer part of it:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
252 rrcf lo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
253 bcf STATUS,C
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
254 rrcf hi
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
255 rrcf lo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
256 bsf leftbind
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
257 output_16
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
258
445
6e57b5bb98ce localisation part 1 from Sergei
heinrichsweikamp
parents: 384
diff changeset
259 STRCAT_PRINT TXT_MBAR7
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
260
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
261 WIN_TOP .65 ; Action enable
174
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
262 lfsr FSR2, letter
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
263 OUTPUTTEXTH .290
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
264 GETCUSTOM8 .49
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
265 btfss WREG,0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
266 bra alt_menu_1
199
f5e9db793dd3 Minor missing translations
JeanDo
parents: 174
diff changeset
267 OUTPUTTEXT .130 ; ON
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
268 bra alt_menu_2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
269 alt_menu_1:
199
f5e9db793dd3 Minor missing translations
JeanDo
parents: 174
diff changeset
270 OUTPUTTEXT .131 ; OFF
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
271 alt_menu_2:
199
f5e9db793dd3 Minor missing translations
JeanDo
parents: 174
diff changeset
272 call word_processor
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
273
174
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
274 DISPLAYTEXTH .291 ; Action reset
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
275 DISPLAYTEXTH .292 ; Action add
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
276 DISPLAYTEXTH .293 ; Action sub
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
277 DISPLAYTEXT .011 ; Action exit
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
278
721
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
279 WIN_LEFT .80 ; Bottom right.
174
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
280 lfsr FSR2, letter
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
281 OUTPUTTEXTH .294 ; "Alt: "
53b16a746166 Multi-lang
JeanDo
parents: 170
diff changeset
282
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
283 movff altitude+0, lo
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
284 movff altitude+1, hi
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
285 btfss hi,7 ; Is altitude negativ ?
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
286 bra altimeter_menu_3 ; No: just print it
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
287
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
288 PUTC '-' ; Yes: print the minus sign
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
289 comf hi ; And do a 16bit 2-complement.
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
290 comf lo
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
291 infsnz lo
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
292 incf hi
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
293
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
294 altimeter_menu_3:
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
295 bsf leftbind
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
296 output_16
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
297 bcf leftbind
721
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
298 STRCAT TXT_METER5
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
299 clrf WREG
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
300 movff WREG,letter+.11 ;limit to 12chars
a5d44fb115a8 fix altimeter with display1
heinrichsweikamp
parents: 717
diff changeset
301 STRCAT_PRINT ""
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
302
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
303 alt_menu_loop:
681
6e456a6398e0 Hardware4 support
heinrichsweikamp
parents: 576
diff changeset
304 call DISP_menu_cursor ; Display cursor
576
ab2686087bce faster font display, code cleaning
heinrichsweikamp
parents: 445
diff changeset
305 call wait_switches ; Waits until switches are released, resets flag if button stays pressed!
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
306
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
307 alt_menu_loop1: ; Wait for button.
337
6bdf80d7276c Added screen dumps of general menus.
JeanDo
parents: 214
diff changeset
308 btfsc uart_dump_screen ; Asked to dump screen contains ?
6bdf80d7276c Added screen dumps of general menus.
JeanDo
parents: 214
diff changeset
309 call dump_screen ; Yes!
6bdf80d7276c Added screen dumps of general menus.
JeanDo
parents: 214
diff changeset
310
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
311 btfsc switch_right ; [[MENU]] button
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
312 bra alt_menu_next
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
313
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
314 btfsc switch_left ;[[ENTER]] button
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
315 bra alt_menu_do_it
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
316
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
317 btfsc divemode ; Diving stared ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
318 goto restart ; YES: quit this menu !
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
319
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
320 btfsc onesecupdate ; Check what should be every 1sec.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
321 call timeout_surfmode
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
322
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
323 btfsc onesecupdate
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
324 call set_dive_modes
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
325
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
326 bcf onesecupdate ; end of 1sek. tasks
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
327
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
328 btfsc sleepmode ; Sleep mode entered ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
329 bra alt_menu_exit
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
330
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
331 bra alt_menu_loop1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
332
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
333 ;---- Move to next line ------------------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
334
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
335 alt_menu_next:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
336 incf menupos ; next line.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
337 movlw .7
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
338 cpfseq menupos ; Below last line ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
339 bra alt_menu_loop
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
340 movlw .2 ; Yes: back to line no 2.
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
341 movwf menupos
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
342 bra alt_menu_loop
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
343
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
344 ;----- Execute menu line -----------------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
345
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
346 alt_menu_do_it:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
347 movf menupos,W ; test line value
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
348 addlw -2
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
349 bz alt_menu_enable ; 2 --> reset
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
350 dcfsnz WREG
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
351 bra alt_menu_reset ; 3 --> +1
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
352 dcfsnz WREG
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
353 bra alt_menu_plus1 ; 4 --> +1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
354 dcfsnz WREG
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
355 bra alt_menu_minus1 ; 5 --> -1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
356 bra alt_menu_exit ; else --> exit
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
357
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
358 ;---- Toggle altimeter (CF#49) -----------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
359 alt_menu_enable:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
360 GETCUSTOM8 .49 ; Read CF#49
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
361 btg WREG,0 ; Toggle boolean value
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
362 movwf EEDATA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
363 movlw d'1' ; Upper EEPROM Bank
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
364 movwf EEADRH
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
365 movlw 4*(.49-.32) + 0x82 ; CF#49 low byte address in EEPROM
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
366 movwf EEADR
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
367 call write_eeprom
384
904863f96582 Work-Around for "Reset all" overwriting 0x00 to 0x04 in EEPROM Bank1
heinrichsweikamp
parents: 344
diff changeset
368 clrf EEADRH ; Reset EEADRH for compatibility
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
369 bra altimeter_menu_2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
370
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
371 ;---- Reset sea level pressure to reference ----------------------------------
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
372 alt_menu_reset:
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
373 rcall altimeter_reset
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
374 bra altimeter_menu_2
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
375
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
376 ;---- Increment sea level pressure -------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
377 alt_menu_plus1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
378 movlb HIGH(pressureRef) ; Setup our own ram bank
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
379 movlw 4
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
380 addwf pressureRef+0,F ; 16bit inc.
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
381 movlw 0
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
382 addwfc pressureRef+1,F
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
383 bra alt_menu_recompute ; then recompute altitude.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
384
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
385 ;---- Decrement sea level pressure -------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
386 alt_menu_minus1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
387 movlb HIGH(pressureRef) ; Setup our own ram bank
170
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
388 movlw -4
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
389 addwf pressureRef+0,F ; 16bit decrement
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
390 movlw -1
0f7ca37b1412 Altimeter: auto reset
JeanDo
parents: 166
diff changeset
391 addwfc pressureRef+1,F
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
392
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
393 alt_menu_recompute:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
394 rcall compute_altitude ; Recompute altitude
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
395 movlb 1 ; Go back to normal bank1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
396 bra altimeter_menu_2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
397
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
398 ;---- Exit altimeter menu ----------------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
399 alt_menu_exit:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
400 movlw .5 ; reset position to Altimeter line.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
401 movwf menupos ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
402 goto more_menu2 ; in the More... menu.