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