annotate code_part1/OSTC_code_asm_part1/altimeter.asm @ 125:2907b42c195b

Altimeter: - use H = 19902 log10(P0/P) - Interface to select sea level mbars. - Average over 32 values, using 1/16 of mbar. - Display in customview area. - Fix display ****m when not yet computed - Fix reset when exiting sleep mode - Fix : edit menu in 1/4 of mbar. - Fix use CF#49 to enable/disable altimeter, also in altimeter menu. - Fix visible in Menu 2
author JeanDo
date Wed, 29 Dec 2010 01:41:13 +0100
parents
children 49bb155ddfbf
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.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
26 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
27 altimeter_calc:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
28 movlb HIGH(pressureAvg)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
29
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
30 movf pressureRef+0,W ; Already initialized ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
31 iorwf pressureRef+1,W
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
32 bnz altimeter_1 ; Yes...
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
33
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
34 movlw LOW(4*.1013+1) ; Init see level at 1013,25 mbar.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
35 movwf pressureRef+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
36 movlw HIGH(4*.1013+1)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
37 movwf pressureRef+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
38
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
39 ; Reset computation. Eg. after a sleep, enables to faster restart with correct
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
40 ; values...
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
41 altimeter_reset:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
42 movlb HIGH(pressureAvg)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
43 clrf pressureSum+0 ; Init averaging area
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
44 clrf pressureSum+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
45 clrf pressureCount
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
46
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
47 clrf altitude+0 ; Mark as not computed yet.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
48 clrf altitude+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
49
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
50 movff amb_pressure+0,pressureAvg+0 ; And init first average.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
51 movff amb_pressure+1,pressureAvg+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
52
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
53 movlw 4 ; And multiply AVG by 16 to be coherent.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
54 altimeter_reset_1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
55 bcf STATUS,C
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
56 rlcf pressureAvg+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
57 rlcf pressureAvg+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
58 decfsz WREG
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
59 bra altimeter_reset_1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
60
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
61 movlb 1 ; Back to normal bank1.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
62 return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
63
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
64 altimeter_1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
65 ;---- Do a bank-safe 16bit summing -----------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
66 movff amb_pressure+0,WREG
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
67 addwf pressureSum+0,F
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
68 movff amb_pressure+1,WREG
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
69 addwfc pressureSum+1,F
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
70
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
71 incf pressureCount ; Increment count too.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
72 movlw .32 ; Already 32 done ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
73 subwf pressureCount,W
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
74 bnz altimeter_4 ; NO: skip update.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
75
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
76 ;---- Update altitude every 32 pressure measures --------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
77 bcf STATUS,C ; Divide by 2, to store pressure x16
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
78 rrcf pressureSum+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
79 rrcf pressureSum+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
80
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
81 movff pressureSum+0,pressureAvg+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
82 movff pressureSum+1,pressureAvg+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
83
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
84 rcall compute_altitude ; Compute from the averaged value...
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
85
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
86 clrf pressureSum+0 ; And reset sum zone for next averaging.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
87 clrf pressureSum+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
88 clrf pressureCount
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
89
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
90 altimeter_4:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
91 movlb 1 ; make sure to be in normal bank1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
92 return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
93
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
94 ;---- Display result -------------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
95 altimeter_display:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
96 GETCUSTOM8 .49 ; Check CF#49
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
97 btfss WREG,0 ; Enabled ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
98 return ; NO: return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
99
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
100 WIN_TOP .35 ; Custom view drawing zone...
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
101 WIN_LEFT .90
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
102 WIN_INVERT .0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
103 WIN_FONT .0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
104 call PLED_standard_color
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
105
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
106 STRCPY "Alt:"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
107
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
108 movff altitude+0,lo ; BANK-SAFE read altitude
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
109 movff altitude+1,hi
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
110 movf lo,W ; Is it zero (not computed yet) ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
111 iorwf hi,W
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
112 bz altimeter_2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
113
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
114 bsf leftbind
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
115 output_16
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
116 bcf leftbind
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
117 bra altimeter_3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
118
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
119 altimeter_2:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
120 STRCAT "****"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
121
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
122 altimeter_3:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
123 STRCAT_PRINT "m "
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
124 return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
125
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
126 ;=============================================================================
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
127 ; Compute altitude, using the formula:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
128 ; H(P) = 18.787 log10(P0/P) (Log base 10)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
129
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
130 ;---- Interface the the Mayh library -----------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
131 extern __AARGB2 ; A float in fA2, fA1, fA0, fAExo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
132 extern __BARGB2 ; B float in fB2, fB1, fB0, fBExo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
133 extern FLO1632U ; convert uint16 fA+1 --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
134 extern FPD32 ; fp32 divide fA/fB --> fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
135 extern FPM32 ; fp32 multiply fA*fB --> fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
136 extern INT3216 ; convert fp32 fA --> int16 fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
137 #define fA __AARGB2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
138 #define fB __BARGB2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
139
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
140 ;---- Interface to the C library ---------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
141 extern __AARGB3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
142 extern log10 ; float32 log(auto float32)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
143 #define fRet __AARGB3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
144
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
145 compute_altitude:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
146 ; Setup C-code stack, to enable calling the log() function.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
147 lfsr FSR1, c_code_data_stack
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
148 lfsr FSR2, c_code_data_stack
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
149
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
150 ; Convert pressure to float, --> fB
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
151 movff pressureAvg+0, fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
152 movff pressureAvg+1, fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
153 call FLO1632U ; u16 fA[1:2] --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
154 movff fA+0, fB+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
155 movff fA+1, fB+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
156 movff fA+2, fB+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
157 movff fA+3, fB+3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
158
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
159 ; Convert sea-level reference pressure to float, --> fB
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
160 movff pressureRef+0, fA+1 ; Get sea level pressure.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
161 movff pressureRef+1, fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
162 bcf STATUS,C ; Multiply by 4.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
163 rlcf fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
164 rlcf fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
165 bcf STATUS,C
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
166 rlcf fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
167 rlcf fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
168 call FLO1632U ; to float: u16 fA[1:2] --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
169
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
170 ; Divide
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
171 call FPD32 ; fp32 X/Y --> X
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
172
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
173 ; log10()
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
174 movff fA+0, POSTINC1 ; Push X to stack
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
175 movff fA+1, POSTINC1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
176 movff fA+2, POSTINC1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
177 movff fA+3, POSTINC1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
178 call log10 ; log(P0/P)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
179
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
180 movf POSTDEC1,F,ACCESS ; pop argument
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
181 movf POSTDEC1,F,ACCESS
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
182 movf POSTDEC1,F,ACCESS
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
183 movf POSTDEC1,F,ACCESS
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
184
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
185 ; Move log10(P0/P) to fB
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
186 movff fRet+0,fB+0 ; move result to fB
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
187 movff fRet+1,fB+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
188 movff fRet+2,fB+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
189 movff fRet+3,fB+3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
190
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
191 ; Multiply by scaling factor for meters, and standatd atmosphere.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
192 movlw LOW(.18787)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
193 movff WREG, fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
194 movlw HIGH(.18787)
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
195 movff WREG, fA+2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
196 call FLO1632U ; u16 fA[1:2] --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
197 call FPM32 ; altitute --> fp32 fA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
198
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
199 ; Convert result to int16 --> altitude.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
200 call INT3216 ; fp32 fA --> int16 fA+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
201 movff fA+1, altitude+0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
202 movff fA+2, altitude+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
203
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
204 return
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
205
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
206 ;=============================================================================
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
207 ; Altimeter menu
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
208 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
209 ; Edit reference (where altitude = 0) pressure, while displaying corresponding
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
210 ; altitude.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
211 ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
212 altimeter_menu:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
213 call PLED_ClearScreen ; Menu header.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
214 call PLED_standard_color
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
215 call PLED_topline_box
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
216 WIN_INVERT .1 ; Init new Wordprocessor
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
217 WIN_FONT .0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
218 WIN_LEFT .80-7*7
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
219 WIN_TOP .0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
220 STRCPY_PRINT "Set Altimeter:"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
221
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
222 movlw 3 ; Start menu on line 3.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
223 movwf menupos
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
224
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
225 altimeter_menu_2:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
226 WIN_FONT .0 ; Reset, because compute erase that...
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
227 WIN_INVERT .0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
228 WIN_LEFT .20 ; First line:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
229 WIN_TOP .35
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
230 STRCPY "Sea ref:"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
231
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
232 movff pressureRef+0, lo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
233 movff pressureRef+1, hi
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
234 bcf STATUS,C ; Divide ref pressure by 4
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
235 rrcf hi ; to get the integer part of it:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
236 rrcf lo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
237 bcf STATUS,C
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
238 rrcf hi
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
239 rrcf lo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
240 bsf leftbind
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
241 output_16
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
242
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
243 PUTC '.'
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
244 movff pressureRef+0, hi ; Decimal part is constructed
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
245 clrf WREG ; from the 2 lower bits.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
246 btfsc hi,0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
247 addlw .25
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
248 btfsc hi,1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
249 addlw .50
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
250 movwf lo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
251 output_99x
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
252
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
253 STRCAT_PRINT "mbar "
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
254
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
255 WIN_TOP .65 ; Second line:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
256 STRCPY "Alt:"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
257 movff altitude+0, lo
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
258 movff altitude+1, hi
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
259 bcf leftbind
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
260 output_16
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
261 STRCAT_PRINT "m "
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
262
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
263 WIN_TOP .95 ; Action enable
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
264 STRCPY "Enabled: "
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
265 GETCUSTOM8 .49
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
266 btfss WREG,0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
267 bra alt_menu_1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
268 STRCAT_PRINT "ON "
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
269 bra alt_menu_2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
270 alt_menu_1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
271 STRCAT_PRINT "OFF"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
272 alt_menu_2:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
273
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
274 WIN_TOP .125 ; Action add
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
275 STRCPY_PRINT "+0.25 mbar"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
276 WIN_TOP .155 ; Action sub
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
277 STRCPY_PRINT "-0.25 mbar"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
278 WIN_TOP .185 ; Action exit
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
279 STRCPY_PRINT "Exit"
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
280
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
281 alt_menu_loop:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
282 call PLED_menu_cursor ; Display cursor
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
283 bcf switch_left ; reset buttons state
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
284 bcf switch_right
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
285
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
286 alt_menu_loop1: ; Wait for button.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
287 btfsc switch_right ; [[MENU]] button
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
288 bra alt_menu_next
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
289
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
290 btfsc switch_left ;[[ENTER]] button
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
291 bra alt_menu_do_it
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
292
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
293 btfsc divemode ; Diving stared ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
294 goto restart ; YES: quit this menu !
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
295
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
296 btfsc onesecupdate ; Check what should be every 1sec.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
297 call timeout_surfmode
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
298
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
299 btfsc onesecupdate
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
300 call set_dive_modes
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
301
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
302 bcf onesecupdate ; end of 1sek. tasks
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
303
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
304 btfsc sleepmode ; Sleep mode entered ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
305 bra alt_menu_exit
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
306
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
307 bra alt_menu_loop1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
308
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
309 ;---- Move to next line ------------------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
310
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
311 alt_menu_next:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
312 incf menupos ; next line.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
313 movlw .7
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
314 cpfseq menupos ; Below last line ?
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
315 bra alt_menu_loop
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
316 movlw .3 ; Yes: back to line no 3.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
317 movwf menupos
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
318 bra alt_menu_loop
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
319
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
320 ;----- Execute menu line -----------------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
321
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
322 alt_menu_do_it:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
323 movf menupos,W ; test line value
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
324 addlw -3
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
325 bz alt_menu_enable
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
326 dcfsnz WREG
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
327 bra alt_menu_plus1 ; 4 --> +1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
328 dcfsnz WREG
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
329 bra alt_menu_minus1 ; 5 --> -1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
330 bra alt_menu_exit ; else --> exit
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
331
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
332 ;---- Toggle altimeter (CF#49) -----------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
333 alt_menu_enable:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
334 GETCUSTOM8 .49 ; Read CF#49
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
335 btg WREG,0 ; Toggle boolean value
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
336 movwf EEDATA
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
337 movlw d'1' ; Upper EEPROM Bank
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
338 movwf EEADRH
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
339 movlw 4*(.49-.32) + 0x82 ; CF#49 low byte address in EEPROM
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
340 movwf EEADR
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
341 call write_eeprom
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
342 bra altimeter_menu_2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
343
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
344 ;---- Increment sea level pressure -------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
345
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
346 alt_menu_plus1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
347 movlb HIGH(pressureRef) ; Setup our own ram bank
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
348 infsnz pressureRef+0 ; 16bit inc.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
349 incf pressureRef+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
350 bra alt_menu_recompute ; then recompute altitude.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
351
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
352 ;---- Decrement sea level pressure -------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
353
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
354 alt_menu_minus1:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
355 movlb HIGH(pressureRef) ; Setup our own ram bank
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
356 decf pressureRef+0 ; 16bit decrement
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
357 movlw 0
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
358 subwfb pressureRef+1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
359
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
360 alt_menu_recompute:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
361 rcall compute_altitude ; Recompute altitude
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
362 movlb 1 ; Go back to normal bank1
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
363 bra altimeter_menu_2
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
364
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
365 ;---- Exit altimeter menu ----------------------------------------------------
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
366 alt_menu_exit:
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
367 movlw .5 ; reset position to Altimeter line.
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
368 movwf menupos ;
2907b42c195b Altimeter:
JeanDo
parents:
diff changeset
369 goto more_menu2 ; in the More... menu.