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
|
106
|
110 bsf show_last3
|
103
|
111 clrf WREG
|
|
112 bra output16
|
|
113
|
|
114 output16_call:
|
|
115 clrf ignore_digits
|
|
116 incf ignore_digits,F
|
|
117 clrf WREG
|
|
118
|
0
|
119 output16
|
103
|
120 movwf temp4 ; Passed from output16dp macro, cleared by others.
|
|
121
|
0
|
122 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero
|
|
123
|
|
124 bsf leading_zeros
|
|
125 incf temp4,1
|
|
126 decfsz temp4,F
|
|
127 bcf leading_zeros
|
|
128
|
|
129 bsf DP_done2
|
|
130 incf temp4,1
|
|
131 decfsz temp4,F
|
|
132 bcf DP_done2 ; decimal point not yet set
|
|
133
|
|
134 movff lo, lo_temp
|
|
135 movff hi, hi_temp
|
|
136 bcf pre_zero_flag ; do not display leading zeros
|
|
137
|
|
138 movlw b'00010000' ; 10000s
|
|
139 movwf temp2
|
|
140 movlw b'00100111'
|
|
141 movwf temp3
|
|
142 btfss show_last3 ; display only last three figures?
|
|
143 rcall DEC2ASCII
|
|
144
|
|
145 movlw b'11101000' ; 1000s
|
|
146 movwf temp2
|
|
147 movlw b'00000011'
|
|
148 movwf temp3
|
|
149 btfsc DP_done2 ; Is there a decimal point at all?
|
|
150 bra output16_2 ; no, use normal display mode
|
|
151
|
|
152 btfsc all_zeros_flag ; display any zero from here
|
|
153 bra output16_1 ; there was a figure /zero already
|
|
154
|
|
155 bsf pre_zero_flag ; display figure if zero?
|
|
156 decfsz temp4,W
|
|
157 bcf pre_zero_flag ; No
|
|
158
|
|
159 output16_1:
|
|
160 btfsc DP_done ; Decimal point set already?
|
|
161 bsf pre_zero_flag ; Yes, so display the rest
|
|
162 output16_2:
|
|
163 btfss show_last3 ; display only last three figures?
|
|
164 rcall DEC2ASCII
|
|
165 bcf show_last3 ; No, so display the rest
|
|
166
|
|
167 movlw b'01100100' ; 100s
|
|
168 movwf temp2
|
|
169 clrf temp3
|
|
170
|
|
171 btfsc ignore_digit3 ; Ignore 3rd-5th digit?
|
|
172 bra output16_5 ; Yes, skip the rest
|
|
173
|
|
174 btfsc DP_done2 ; Is there a decimal point at all?
|
|
175 bra output16_3 ; no, use normal display mode
|
|
176
|
|
177 btfsc all_zeros_flag ; display any zero from here
|
|
178 bra output16_2_1 ; there was a figure /zero already
|
|
179
|
|
180 bsf pre_zero_flag ; display figure if zero?
|
|
181 decfsz temp4,W
|
|
182 bcf pre_zero_flag ; No
|
|
183
|
|
184 output16_2_1:
|
|
185 btfsc DP_done ; Decimal point set already?
|
|
186 bsf pre_zero_flag ; Yes, so display the rest
|
|
187 btfsc DP_done2 ; Is there a decimal point at all?
|
|
188 bsf pre_zero_flag ; No, so display the rest
|
|
189 output16_3:
|
|
190 rcall DEC2ASCII
|
|
191
|
|
192 movlw b'00001010' ; 10s
|
|
193 movwf temp2
|
|
194 clrf temp3
|
|
195 btfsc DP_done2
|
|
196 bra output16_4
|
|
197
|
|
198 btfsc all_zeros_flag ; display any zero from here
|
|
199 bra output16_3_1 ; there was a figure /zero already
|
|
200
|
|
201 bsf pre_zero_flag
|
|
202 decfsz temp4,W
|
|
203 bcf pre_zero_flag
|
|
204
|
|
205 output16_3_1:
|
|
206 btfsc DP_done
|
|
207 bsf pre_zero_flag
|
|
208 btfsc DP_done2
|
|
209 bsf pre_zero_flag
|
|
210 output16_4:
|
|
211 btfsc ignore_digit4 ; Ignore 4-5th digit?
|
|
212 bra output16_5 ; Yes, skip the rest
|
|
213 rcall DEC2ASCII
|
|
214
|
|
215 movlw b'00000001' ; 1s
|
|
216 movwf temp2
|
|
217 clrf temp3
|
|
218 bsf pre_zero_flag
|
|
219 btfss ignore_digit5 ; Ignore 5th digit?
|
|
220 rcall DEC2ASCII ; No!
|
|
221 bcf ignore_digit5 ; yes, and clear flag
|
|
222 output16_5:
|
|
223 bcf ignore_digit3 ; Clear flag
|
|
224 clrf ignore_digits
|
|
225 incf ignore_digits,F
|
|
226 bcf DP_done
|
|
227 RETURN
|
|
228
|
|
229 DEC2ASCII clrf temp1 ; converts into ASCII code
|
|
230 DEC2ASCII_2 movf temp3,W
|
|
231 subwf hi_temp,0
|
|
232 btfss STATUS,C
|
|
233 bra DEC2ASCII_4
|
|
234 bnz DEC2ASCII_3
|
|
235
|
|
236 movf temp2,W
|
|
237 subwf lo_temp,0
|
|
238 btfss STATUS,C
|
|
239 bra DEC2ASCII_4
|
|
240
|
|
241 DEC2ASCII_3 movf temp3,W
|
|
242 subwf hi_temp,1
|
|
243 movf temp2,W
|
|
244 subwf lo_temp,1
|
|
245 btfss STATUS,C
|
|
246 decf hi_temp,1
|
|
247 incf temp1,1
|
|
248 bsf pre_zero_flag
|
|
249 bra DEC2ASCII_2
|
|
250
|
|
251 DEC2ASCII_4
|
|
252 decfsz ignore_digits,F
|
|
253 return
|
|
254 incf ignore_digits,F
|
|
255 movlw '0' ; Offset for Ascii-value
|
|
256 addwf temp1,0
|
|
257 btfsc pre_zero_flag ; is this a leading zero?
|
|
258 bra DEC2ASCII_4_1 ; no
|
|
259 btfsc leftbind
|
|
260 bra DEC2ASCII_6
|
|
261 movlw ' ' ; instead of leading zeros a space!
|
|
262 bra DEC2ASCII_5
|
|
263
|
|
264 DEC2ASCII_4_1:
|
|
265 bsf all_zeros_flag ; display any zero from here
|
|
266 DEC2ASCII_5
|
|
267 movwf POSTINC2
|
|
268 DEC2ASCII_6
|
|
269 decfsz temp4,F ; Set decimal point?
|
|
270 RETURN ; No
|
|
271 movlw "." ; Yes
|
|
272 movwf POSTINC2
|
|
273 bsf DP_done
|
|
274 RETURN |