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
|
|
21 ; last updated: 5/11/07
|
|
22 ; known bugs:
|
|
23 ; ToDo: clean up!!!
|
|
24
|
|
25
|
|
26 output_16_3 macro ; displays only last three figures from a 16Bit value (0-999)
|
|
27 clrf ignore_digits
|
|
28 incf ignore_digits,F
|
|
29 clrf temp4
|
|
30 bsf show_last3
|
|
31 movf temp4,W ; Temp4 stores position for decimal point
|
|
32 call output16
|
|
33 endm
|
|
34
|
|
35 output_16dp macro temp4 ; 16Bit with decimal point
|
|
36 movlw temp4 ; Temp4 stores position for decimal point
|
|
37 call output16
|
|
38 endm
|
|
39
|
|
40 output_16 macro ; 16Bit Normal
|
|
41 clrf ignore_digits
|
|
42 incf ignore_digits,F
|
|
43 clrf temp4
|
|
44 movf temp4,W ; Temp4 stores position for decimal point
|
|
45 call output16
|
|
46 endm
|
|
47
|
|
48 output_8 macro ; 8 Bit Normal
|
|
49 clrf ignore_digits
|
|
50 incf ignore_digits,F
|
|
51 clrf temp4
|
|
52 call output8
|
|
53 endm
|
|
54
|
|
55 output_99 macro ; displays only last two figures from a 8Bit value (0-99)
|
|
56 clrf ignore_digits
|
|
57 incf ignore_digits,F
|
|
58 clrf temp4
|
|
59 call output99
|
|
60 endm
|
|
61
|
|
62 output_99x macro ; displays only last two figures from a 8Bit value with leading zero (00-99)
|
|
63 clrf ignore_digits
|
|
64 incf ignore_digits,F
|
|
65 clrf temp4
|
|
66 call output99x
|
|
67 endm
|
|
68
|
|
69 output99:
|
|
70 movlw d'99'
|
|
71 cpfslt lo
|
|
72 movwf lo ; Limit to 99
|
64
|
73 movff lo,lo_temp
|
0
|
74 clrf hi_temp
|
|
75 bcf pre_zero_flag ; do not display leading zeros
|
|
76
|
|
77 LCD_val99_2:
|
|
78 movlw b'00001010' ; 10
|
|
79 movwf temp2
|
|
80 clrf temp3
|
|
81 rcall DEC2ASCII
|
|
82
|
|
83 movlw b'00000001' ; 1
|
|
84 movwf temp2
|
|
85 clrf temp3
|
|
86 bsf pre_zero_flag ; last figure, display zero (0)
|
|
87 rcall DEC2ASCII
|
|
88 RETURN
|
|
89
|
|
90 output99x:
|
64
|
91 movlw d'99'
|
|
92 cpfslt lo
|
|
93 movwf lo ; Limit to 99
|
0
|
94 movff lo, lo_temp
|
|
95 clrf hi_temp
|
|
96 bsf pre_zero_flag ; display leading zeros
|
|
97 bra LCD_val99_2
|
|
98
|
|
99 output8
|
|
100 movff lo, lo_temp
|
|
101 clrf hi_temp
|
|
102 bcf pre_zero_flag ; do not display leading zeros
|
|
103
|
|
104 movlw b'01100100' ; 100
|
|
105 movwf temp2
|
|
106 clrf temp3
|
|
107 rcall DEC2ASCII
|
|
108 bra LCD_val99_2
|
|
109
|
|
110 output16
|
|
111 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero
|
|
112
|
|
113 movwf temp4
|
|
114
|
|
115 bsf leading_zeros
|
|
116 incf temp4,1
|
|
117 decfsz temp4,F
|
|
118 bcf leading_zeros
|
|
119
|
|
120 bsf DP_done2
|
|
121 incf temp4,1
|
|
122 decfsz temp4,F
|
|
123 bcf DP_done2 ; decimal point not yet set
|
|
124
|
|
125 movff lo, lo_temp
|
|
126 movff hi, hi_temp
|
|
127 bcf pre_zero_flag ; do not display leading zeros
|
|
128
|
|
129 movlw b'00010000' ; 10000s
|
|
130 movwf temp2
|
|
131 movlw b'00100111'
|
|
132 movwf temp3
|
|
133 btfss show_last3 ; display only last three figures?
|
|
134 rcall DEC2ASCII
|
|
135
|
|
136 movlw b'11101000' ; 1000s
|
|
137 movwf temp2
|
|
138 movlw b'00000011'
|
|
139 movwf temp3
|
|
140 btfsc DP_done2 ; Is there a decimal point at all?
|
|
141 bra output16_2 ; no, use normal display mode
|
|
142
|
|
143 btfsc all_zeros_flag ; display any zero from here
|
|
144 bra output16_1 ; there was a figure /zero already
|
|
145
|
|
146 bsf pre_zero_flag ; display figure if zero?
|
|
147 decfsz temp4,W
|
|
148 bcf pre_zero_flag ; No
|
|
149
|
|
150 output16_1:
|
|
151 btfsc DP_done ; Decimal point set already?
|
|
152 bsf pre_zero_flag ; Yes, so display the rest
|
|
153 output16_2:
|
|
154 btfss show_last3 ; display only last three figures?
|
|
155 rcall DEC2ASCII
|
|
156 bcf show_last3 ; No, so display the rest
|
|
157
|
|
158 movlw b'01100100' ; 100s
|
|
159 movwf temp2
|
|
160 clrf temp3
|
|
161
|
|
162 btfsc ignore_digit3 ; Ignore 3rd-5th digit?
|
|
163 bra output16_5 ; Yes, skip the rest
|
|
164
|
|
165 btfsc DP_done2 ; Is there a decimal point at all?
|
|
166 bra output16_3 ; no, use normal display mode
|
|
167
|
|
168 btfsc all_zeros_flag ; display any zero from here
|
|
169 bra output16_2_1 ; there was a figure /zero already
|
|
170
|
|
171 bsf pre_zero_flag ; display figure if zero?
|
|
172 decfsz temp4,W
|
|
173 bcf pre_zero_flag ; No
|
|
174
|
|
175 output16_2_1:
|
|
176 btfsc DP_done ; Decimal point set already?
|
|
177 bsf pre_zero_flag ; Yes, so display the rest
|
|
178 btfsc DP_done2 ; Is there a decimal point at all?
|
|
179 bsf pre_zero_flag ; No, so display the rest
|
|
180 output16_3:
|
|
181 rcall DEC2ASCII
|
|
182
|
|
183 movlw b'00001010' ; 10s
|
|
184 movwf temp2
|
|
185 clrf temp3
|
|
186 btfsc DP_done2
|
|
187 bra output16_4
|
|
188
|
|
189 btfsc all_zeros_flag ; display any zero from here
|
|
190 bra output16_3_1 ; there was a figure /zero already
|
|
191
|
|
192 bsf pre_zero_flag
|
|
193 decfsz temp4,W
|
|
194 bcf pre_zero_flag
|
|
195
|
|
196 output16_3_1:
|
|
197 btfsc DP_done
|
|
198 bsf pre_zero_flag
|
|
199 btfsc DP_done2
|
|
200 bsf pre_zero_flag
|
|
201 output16_4:
|
|
202 btfsc ignore_digit4 ; Ignore 4-5th digit?
|
|
203 bra output16_5 ; Yes, skip the rest
|
|
204 rcall DEC2ASCII
|
|
205
|
|
206 movlw b'00000001' ; 1s
|
|
207 movwf temp2
|
|
208 clrf temp3
|
|
209 bsf pre_zero_flag
|
|
210 btfss ignore_digit5 ; Ignore 5th digit?
|
|
211 rcall DEC2ASCII ; No!
|
|
212 bcf ignore_digit5 ; yes, and clear flag
|
|
213 output16_5:
|
|
214 bcf ignore_digit3 ; Clear flag
|
|
215 clrf ignore_digits
|
|
216 incf ignore_digits,F
|
|
217 bcf DP_done
|
|
218 RETURN
|
|
219
|
|
220 DEC2ASCII clrf temp1 ; converts into ASCII code
|
|
221 DEC2ASCII_2 movf temp3,W
|
|
222 subwf hi_temp,0
|
|
223 btfss STATUS,C
|
|
224 bra DEC2ASCII_4
|
|
225 bnz DEC2ASCII_3
|
|
226
|
|
227 movf temp2,W
|
|
228 subwf lo_temp,0
|
|
229 btfss STATUS,C
|
|
230 bra DEC2ASCII_4
|
|
231
|
|
232 DEC2ASCII_3 movf temp3,W
|
|
233 subwf hi_temp,1
|
|
234 movf temp2,W
|
|
235 subwf lo_temp,1
|
|
236 btfss STATUS,C
|
|
237 decf hi_temp,1
|
|
238 incf temp1,1
|
|
239 bsf pre_zero_flag
|
|
240 bra DEC2ASCII_2
|
|
241
|
|
242 DEC2ASCII_4
|
|
243 decfsz ignore_digits,F
|
|
244 return
|
|
245 incf ignore_digits,F
|
|
246 movlw '0' ; Offset for Ascii-value
|
|
247 addwf temp1,0
|
|
248 btfsc pre_zero_flag ; is this a leading zero?
|
|
249 bra DEC2ASCII_4_1 ; no
|
|
250 btfsc leftbind
|
|
251 bra DEC2ASCII_6
|
|
252 movlw ' ' ; instead of leading zeros a space!
|
|
253 bra DEC2ASCII_5
|
|
254
|
|
255 DEC2ASCII_4_1:
|
|
256 bsf all_zeros_flag ; display any zero from here
|
|
257 DEC2ASCII_5
|
|
258 movwf POSTINC2
|
|
259 DEC2ASCII_6
|
|
260 decfsz temp4,F ; Set decimal point?
|
|
261 RETURN ; No
|
|
262 movlw "." ; Yes
|
|
263 movwf POSTINC2
|
|
264 bsf DP_done
|
|
265 RETURN |