0
|
1 ; OSTC - diving computer code
|
|
2 ; Copyright (C) 2008 HeinrichsWeikamp GbR
|
|
3
|
|
4 ; This program is free software: you can redistribute it and/or modify
|
|
5 ; it under the terms of the GNU General Public License as published by
|
|
6 ; the Free Software Foundation, either version 3 of the License, or
|
|
7 ; (at your option) any later version.
|
|
8
|
|
9 ; This program is distributed in the hope that it will be useful,
|
|
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 ; GNU General Public License for more details.
|
|
13
|
|
14 ; You should have received a copy of the GNU General Public License
|
|
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
|
17
|
|
18 ; converts hex values to dez values
|
|
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
|
|
20 ; written: 13/10/07
|
103
|
21 ; 10/12/2010 jDG: optimize macro size.
|
|
22 ; last updated: 10/12/2010
|
0
|
23 ; known bugs:
|
|
24 ; ToDo: clean up!!!
|
|
25
|
|
26
|
|
27 output_16_3 macro ; displays only last three figures from a 16Bit value (0-999)
|
103
|
28 call output16_3_call
|
0
|
29 endm
|
|
30
|
|
31 output_16dp macro temp4 ; 16Bit with decimal point
|
|
32 movlw temp4 ; Temp4 stores position for decimal point
|
|
33 call output16
|
|
34 endm
|
|
35
|
|
36 output_16 macro ; 16Bit Normal
|
103
|
37 call output16_call
|
0
|
38 endm
|
|
39
|
|
40 output_8 macro ; 8 Bit Normal
|
103
|
41 call output8_call
|
|
42 endm
|
|
43
|
|
44 output_99 macro ; displays only last two figures from a 8Bit value (0-99)
|
|
45 call output99_call
|
|
46 endm
|
|
47
|
|
48 output_99x macro ; displays only last two figures from a 8Bit value with leading zero (00-99)
|
|
49 call output99x_call
|
|
50 endm
|
|
51
|
|
52 output99_call:
|
0
|
53 clrf ignore_digits
|
|
54 incf ignore_digits,F
|
|
55 clrf temp4
|
|
56
|
|
57 output99:
|
|
58 movlw d'99'
|
|
59 cpfslt lo
|
|
60 movwf lo ; Limit to 99
|
64
|
61 movff lo,lo_temp
|
0
|
62 clrf hi_temp
|
|
63 bcf pre_zero_flag ; do not display leading zeros
|
|
64
|
|
65 LCD_val99_2:
|
|
66 movlw b'00001010' ; 10
|
|
67 movwf temp2
|
|
68 clrf temp3
|
|
69 rcall DEC2ASCII
|
|
70
|
|
71 movlw b'00000001' ; 1
|
|
72 movwf temp2
|
|
73 clrf temp3
|
|
74 bsf pre_zero_flag ; last figure, display zero (0)
|
|
75 rcall DEC2ASCII
|
|
76 RETURN
|
|
77
|
103
|
78 output99x_call:
|
|
79 clrf ignore_digits
|
|
80 incf ignore_digits,F
|
|
81 clrf temp4
|
|
82
|
64
|
83 movlw d'99'
|
|
84 cpfslt lo
|
|
85 movwf lo ; Limit to 99
|
0
|
86 movff lo, lo_temp
|
|
87 clrf hi_temp
|
|
88 bsf pre_zero_flag ; display leading zeros
|
|
89 bra LCD_val99_2
|
|
90
|
103
|
91 output8_call:
|
|
92 clrf ignore_digits
|
|
93 incf ignore_digits,F
|
|
94 clrf temp4
|
|
95
|
0
|
96 output8
|
|
97 movff lo, lo_temp
|
|
98 clrf hi_temp
|
|
99 bcf pre_zero_flag ; do not display leading zeros
|
|
100
|
|
101 movlw b'01100100' ; 100
|
|
102 movwf temp2
|
|
103 clrf temp3
|
|
104 rcall DEC2ASCII
|
|
105 bra LCD_val99_2
|
|
106
|
103
|
107 output16_3_call:
|
|
108 clrf ignore_digits
|
|
109 incf ignore_digits,F
|
|
110 clrf WREG
|
|
111 bra output16
|
|
112
|
|
113 output16_call:
|
|
114 clrf ignore_digits
|
|
115 incf ignore_digits,F
|
|
116 clrf WREG
|
|
117
|
0
|
118 output16
|
103
|
119 movwf temp4 ; Passed from output16dp macro, cleared by others.
|
|
120
|
0
|
121 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero
|
|
122
|
|
123 bsf leading_zeros
|
|
124 incf temp4,1
|
|
125 decfsz temp4,F
|
|
126 bcf leading_zeros
|
|
127
|
|
128 bsf DP_done2
|
|
129 incf temp4,1
|
|
130 decfsz temp4,F
|
|
131 bcf DP_done2 ; decimal point not yet set
|
|
132
|
|
133 movff lo, lo_temp
|
|
134 movff hi, hi_temp
|
|
135 bcf pre_zero_flag ; do not display leading zeros
|
|
136
|
|
137 movlw b'00010000' ; 10000s
|
|
138 movwf temp2
|
|
139 movlw b'00100111'
|
|
140 movwf temp3
|
|
141 btfss show_last3 ; display only last three figures?
|
|
142 rcall DEC2ASCII
|
|
143
|
|
144 movlw b'11101000' ; 1000s
|
|
145 movwf temp2
|
|
146 movlw b'00000011'
|
|
147 movwf temp3
|
|
148 btfsc DP_done2 ; Is there a decimal point at all?
|
|
149 bra output16_2 ; no, use normal display mode
|
|
150
|
|
151 btfsc all_zeros_flag ; display any zero from here
|
|
152 bra output16_1 ; there was a figure /zero already
|
|
153
|
|
154 bsf pre_zero_flag ; display figure if zero?
|
|
155 decfsz temp4,W
|
|
156 bcf pre_zero_flag ; No
|
|
157
|
|
158 output16_1:
|
|
159 btfsc DP_done ; Decimal point set already?
|
|
160 bsf pre_zero_flag ; Yes, so display the rest
|
|
161 output16_2:
|
|
162 btfss show_last3 ; display only last three figures?
|
|
163 rcall DEC2ASCII
|
|
164 bcf show_last3 ; No, so display the rest
|
|
165
|
|
166 movlw b'01100100' ; 100s
|
|
167 movwf temp2
|
|
168 clrf temp3
|
|
169
|
|
170 btfsc ignore_digit3 ; Ignore 3rd-5th digit?
|
|
171 bra output16_5 ; Yes, skip the rest
|
|
172
|
|
173 btfsc DP_done2 ; Is there a decimal point at all?
|
|
174 bra output16_3 ; no, use normal display mode
|
|
175
|
|
176 btfsc all_zeros_flag ; display any zero from here
|
|
177 bra output16_2_1 ; there was a figure /zero already
|
|
178
|
|
179 bsf pre_zero_flag ; display figure if zero?
|
|
180 decfsz temp4,W
|
|
181 bcf pre_zero_flag ; No
|
|
182
|
|
183 output16_2_1:
|
|
184 btfsc DP_done ; Decimal point set already?
|
|
185 bsf pre_zero_flag ; Yes, so display the rest
|
|
186 btfsc DP_done2 ; Is there a decimal point at all?
|
|
187 bsf pre_zero_flag ; No, so display the rest
|
|
188 output16_3:
|
|
189 rcall DEC2ASCII
|
|
190
|
|
191 movlw b'00001010' ; 10s
|
|
192 movwf temp2
|
|
193 clrf temp3
|
|
194 btfsc DP_done2
|
|
195 bra output16_4
|
|
196
|
|
197 btfsc all_zeros_flag ; display any zero from here
|
|
198 bra output16_3_1 ; there was a figure /zero already
|
|
199
|
|
200 bsf pre_zero_flag
|
|
201 decfsz temp4,W
|
|
202 bcf pre_zero_flag
|
|
203
|
|
204 output16_3_1:
|
|
205 btfsc DP_done
|
|
206 bsf pre_zero_flag
|
|
207 btfsc DP_done2
|
|
208 bsf pre_zero_flag
|
|
209 output16_4:
|
|
210 btfsc ignore_digit4 ; Ignore 4-5th digit?
|
|
211 bra output16_5 ; Yes, skip the rest
|
|
212 rcall DEC2ASCII
|
|
213
|
|
214 movlw b'00000001' ; 1s
|
|
215 movwf temp2
|
|
216 clrf temp3
|
|
217 bsf pre_zero_flag
|
|
218 btfss ignore_digit5 ; Ignore 5th digit?
|
|
219 rcall DEC2ASCII ; No!
|
|
220 bcf ignore_digit5 ; yes, and clear flag
|
|
221 output16_5:
|
|
222 bcf ignore_digit3 ; Clear flag
|
|
223 clrf ignore_digits
|
|
224 incf ignore_digits,F
|
|
225 bcf DP_done
|
|
226 RETURN
|
|
227
|
|
228 DEC2ASCII clrf temp1 ; converts into ASCII code
|
|
229 DEC2ASCII_2 movf temp3,W
|
|
230 subwf hi_temp,0
|
|
231 btfss STATUS,C
|
|
232 bra DEC2ASCII_4
|
|
233 bnz DEC2ASCII_3
|
|
234
|
|
235 movf temp2,W
|
|
236 subwf lo_temp,0
|
|
237 btfss STATUS,C
|
|
238 bra DEC2ASCII_4
|
|
239
|
|
240 DEC2ASCII_3 movf temp3,W
|
|
241 subwf hi_temp,1
|
|
242 movf temp2,W
|
|
243 subwf lo_temp,1
|
|
244 btfss STATUS,C
|
|
245 decf hi_temp,1
|
|
246 incf temp1,1
|
|
247 bsf pre_zero_flag
|
|
248 bra DEC2ASCII_2
|
|
249
|
|
250 DEC2ASCII_4
|
|
251 decfsz ignore_digits,F
|
|
252 return
|
|
253 incf ignore_digits,F
|
|
254 movlw '0' ; Offset for Ascii-value
|
|
255 addwf temp1,0
|
|
256 btfsc pre_zero_flag ; is this a leading zero?
|
|
257 bra DEC2ASCII_4_1 ; no
|
|
258 btfsc leftbind
|
|
259 bra DEC2ASCII_6
|
|
260 movlw ' ' ; instead of leading zeros a space!
|
|
261 bra DEC2ASCII_5
|
|
262
|
|
263 DEC2ASCII_4_1:
|
|
264 bsf all_zeros_flag ; display any zero from here
|
|
265 DEC2ASCII_5
|
|
266 movwf POSTINC2
|
|
267 DEC2ASCII_6
|
|
268 decfsz temp4,F ; Set decimal point?
|
|
269 RETURN ; No
|
|
270 movlw "." ; Yes
|
|
271 movwf POSTINC2
|
|
272 bsf DP_done
|
|
273 RETURN |