Mercurial > public > hwos_code
comparison src/convert.asm @ 604:ca4556fb60b9
bump to 2.99beta, work on 3.00 stable
author | heinrichsweikamp |
---|---|
date | Thu, 22 Nov 2018 19:47:26 +0100 |
parents | b455b31ce022 |
children | c40025d8e750 |
comparison
equal
deleted
inserted
replaced
603:00b24fb4324d | 604:ca4556fb60b9 |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File convert.asm ## V2.98 | 3 ; File convert.asm ## V2.98c |
4 ; | 4 ; |
5 ; Converts register values to string | 5 ; Converts register values to string |
6 ; | 6 ; |
7 ; Copyright (c) 2011, Matthias Heinrichs, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, Matthias Heinrichs, HeinrichsWeikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
11 ; 2010-12-10 : [jDG] Optimize macro size | 11 ; 2010-12-10 : [jDG] Optimize macro size |
12 ; | 12 ; |
13 | 13 |
14 #include "hwos.inc" ; Mandatory header | 14 #include "hwos.inc" ; Mandatory header |
15 | 15 |
16 basic CODE | 16 convert CODE |
17 | 17 |
18 ;============================================================================= | 18 ;============================================================================= |
19 | 19 |
20 global output99_call | 20 global output99_call |
21 output99_call: | 21 output99_call: |
26 | 26 |
27 global output99 | 27 global output99 |
28 output99: | 28 output99: |
29 movlw d'99' | 29 movlw d'99' |
30 cpfslt lo | 30 cpfslt lo |
31 movwf lo ; Limit to 99 | 31 movwf lo ; limit to 99 |
32 movff lo,lo_temp | 32 movff lo,lo_temp |
33 clrf hi_temp | 33 clrf hi_temp |
34 bcf pre_zero_flag ; do not display leading zeros | 34 bcf pre_zero_flag ; do not display leading zeros |
35 | 35 |
36 LCD_val99_2: | 36 LCD_val99_2: |
52 incf ignore_digits,F | 52 incf ignore_digits,F |
53 clrf cvt_temp4 | 53 clrf cvt_temp4 |
54 | 54 |
55 movlw d'99' | 55 movlw d'99' |
56 cpfslt lo | 56 cpfslt lo |
57 movwf lo ; Limit to 99 | 57 movwf lo ; limit to 99 |
58 movff lo, lo_temp | 58 movff lo, lo_temp |
59 clrf hi_temp | 59 clrf hi_temp |
60 bsf pre_zero_flag ; display leading zeros | 60 bsf pre_zero_flag ; display leading zeros |
61 bra LCD_val99_2 | 61 bra LCD_val99_2 |
62 | 62 |
82 output16_4_call: ; limit to 9999 | 82 output16_4_call: ; limit to 9999 |
83 bsf show_last4 | 83 bsf show_last4 |
84 ; 9999 = 27 0F = [39][15] | 84 ; 9999 = 27 0F = [39][15] |
85 movlw .40 | 85 movlw .40 |
86 cpfslt hi ; hi < 40 ? | 86 cpfslt hi ; hi < 40 ? |
87 bra output16_4_call_2 ; No, hi >= 40, do limit | 87 bra output16_4_call_2 ; NO - hi >= 40, do limit |
88 ; Yes, hi <= 39 | 88 ; Yes, hi <= 39 |
89 movlw .39 | 89 movlw .39 |
90 cpfseq hi ; hi = 39 ? | 90 cpfseq hi ; hi = 39 ? |
91 bra output16_4_call_3 ; No, hi < 39, no limit needed | 91 bra output16_4_call_3 ; NO - hi < 39, no limit needed |
92 ; Yes, hi = 39 | 92 ; Yes, hi = 39 |
93 movlw .15 | 93 movlw .15 |
94 cpfslt lo ; lo < 15 | 94 cpfslt lo ; lo < 15 |
95 movwf lo ; No, lo >= 15, set lo = 15. | 95 movwf lo ; NO - lo >= 15, set lo = 15. |
96 ; Yes, lo <= 14 or lo set to =15 | 96 ; Yes, lo <= 14 or lo set to =15 |
97 bra output16_4_call_3 ; done. | 97 bra output16_4_call_3 ; done |
98 output16_4_call_2: ; Set to 9999 | 98 output16_4_call_2: ; set to 9999 |
99 movlw LOW .9999 | 99 movlw LOW .9999 |
100 movwf lo | 100 movwf lo |
101 movlw HIGH .9999 | 101 movlw HIGH .9999 |
102 movwf hi | 102 movwf hi |
103 output16_4_call_3: | 103 output16_4_call_3: |
111 ; Limit to 3 | 111 ; Limit to 3 |
112 movlw .4 | 112 movlw .4 |
113 cpfslt hi | 113 cpfslt hi |
114 bra output16_3_call_2 | 114 bra output16_3_call_2 |
115 movlw .3 | 115 movlw .3 |
116 cpfseq hi ; =3? | 116 cpfseq hi ; = 3 ? |
117 bra output16_3_call_3 ; No, done. | 117 bra output16_3_call_3 ; NO - done |
118 movlw .231 ; Limit to 231(+768=999...) | 118 movlw .231 ; limit to 231(+768=999...) |
119 cpfslt lo | 119 cpfslt lo |
120 movwf lo | 120 movwf lo |
121 bra output16_3_call_3 ; done. | 121 bra output16_3_call_3 ; done |
122 output16_3_call_2: ; Set to .999 | 122 output16_3_call_2: ; set to .999 |
123 movlw LOW .999 | 123 movlw LOW .999 |
124 movwf lo | 124 movwf lo |
125 movlw HIGH .999 | 125 movlw HIGH .999 |
126 movwf hi | 126 movwf hi |
127 output16_3_call_3: | 127 output16_3_call_3: |
128 output16_call: | 128 output16_call: |
129 clrf ignore_digits | 129 clrf ignore_digits |
130 incf ignore_digits,F | 130 incf ignore_digits,F |
131 clrf WREG | 131 clrf WREG |
132 output16: | 132 output16: |
133 movwf cvt_temp4 ; Passed from output16dp macro, cleared by others. | 133 movwf cvt_temp4 ; passed from output16dp macro, cleared by others. |
134 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero | 134 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero |
135 bsf leading_zeros | 135 bsf leading_zeros |
136 tstfsz cvt_temp4 ; Display leading zeros at all? | 136 tstfsz cvt_temp4 ; display leading zeros at all? |
137 bcf leading_zeros | 137 bcf leading_zeros |
138 bsf DP_done2 | 138 bsf DP_done2 |
139 tstfsz cvt_temp4 | 139 tstfsz cvt_temp4 |
140 bcf DP_done2 ; decimal point not yet set | 140 bcf DP_done2 ; decimal point not yet set |
141 movff lo, lo_temp | 141 movff lo, lo_temp |
147 movwf cvt_temp3 | 147 movwf cvt_temp3 |
148 btfsc show_last3 ; display only last three figures? | 148 btfsc show_last3 ; display only last three figures? |
149 bra output16_sk5 | 149 bra output16_sk5 |
150 btfsc show_last4 ; display only last four figures? | 150 btfsc show_last4 ; display only last four figures? |
151 bra output16_sk5 | 151 bra output16_sk5 |
152 rcall DEC2ASCII ; No, show all. Here: 5th order digit | 152 rcall DEC2ASCII ; NO - show all, here: 5th order digit |
153 | 153 |
154 output16_sk5: | 154 output16_sk5: |
155 bcf show_last4 | 155 bcf show_last4 |
156 movlw b'11101000' ; 1000s | 156 movlw b'11101000' ; 1000s |
157 movwf cvt_temp2 | 157 movwf cvt_temp2 |
158 movlw b'00000011' | 158 movlw b'00000011' |
159 movwf cvt_temp3 | 159 movwf cvt_temp3 |
160 btfsc DP_done2 ; Is there a decimal point at all? | 160 btfsc DP_done2 ; is there a decimal point at all? |
161 bra output16_2 ; no, use normal display mode | 161 bra output16_2 ; NO - use normal display mode |
162 | 162 |
163 btfsc all_zeros_flag ; display any zero from here | 163 btfsc all_zeros_flag ; display any zero from here |
164 bra output16_1 ; there was a figure /zero already | 164 bra output16_1 ; there was a figure /zero already |
165 | 165 |
166 bsf pre_zero_flag ; display figure if zero? | 166 bsf pre_zero_flag ; display figure if zero? |
167 decfsz cvt_temp4,W | 167 decfsz cvt_temp4,W |
168 bcf pre_zero_flag ; No | 168 bcf pre_zero_flag ; NO |
169 | 169 |
170 output16_1: | 170 output16_1: |
171 btfsc DP_done ; Decimal point set already? | 171 btfsc DP_done ; decimal point set already? |
172 bsf pre_zero_flag ; Yes, so display the rest | 172 bsf pre_zero_flag ; YES - so display the rest |
173 output16_2: | 173 output16_2: |
174 btfss show_last3 ; display only last three figures? | 174 btfss show_last3 ; display only last three figures? |
175 rcall DEC2ASCII ; No, show all. Here: 4th order digit | 175 rcall DEC2ASCII ; NO - show all. Here: 4th order digit |
176 bcf show_last3 ; Yes, so display the rest | 176 bcf show_last3 ; YES - so display the rest |
177 movlw b'01100100' ; 100s | 177 movlw b'01100100' ; 100s |
178 movwf cvt_temp2 | 178 movwf cvt_temp2 |
179 clrf cvt_temp3 | 179 clrf cvt_temp3 |
180 btfsc ignore_digit3 ; Ignore 3rd-5th digit? | 180 btfsc ignore_digit3 ; ignore 3rd-5th digit? |
181 bra output16_5 ; Yes, skip the rest | 181 bra output16_5 ; YES - skip the rest |
182 btfsc DP_done2 ; Is there a decimal point at all? | 182 btfsc DP_done2 ; is there a decimal point at all? |
183 bra output16_3 ; no, use normal display mode | 183 bra output16_3 ; NO - use normal display mode |
184 btfsc all_zeros_flag ; display any zero from here | 184 btfsc all_zeros_flag ; display any zero from here |
185 bra output16_2_1 ; there was a figure /zero already | 185 bra output16_2_1 ; there was a figure /zero already |
186 bsf pre_zero_flag ; display figure if zero? | 186 bsf pre_zero_flag ; display figure if zero? |
187 decfsz cvt_temp4,W | 187 decfsz cvt_temp4,W |
188 bcf pre_zero_flag ; No | 188 bcf pre_zero_flag ; NO |
189 | 189 |
190 output16_2_1: | 190 output16_2_1: |
191 btfsc DP_done ; Decimal point set already? | 191 btfsc DP_done ; decimal point set already? |
192 bsf pre_zero_flag ; Yes, so display the rest | 192 bsf pre_zero_flag ; YES - so display the rest |
193 btfsc DP_done2 ; Is there a decimal point at all? | 193 btfsc DP_done2 ; is there a decimal point at all? |
194 bsf pre_zero_flag ; No, so display the rest | 194 bsf pre_zero_flag ; NO - so display the rest |
195 output16_3: | 195 output16_3: |
196 rcall DEC2ASCII ; 3th order digit... | 196 rcall DEC2ASCII ; 3th order digit... |
197 movlw b'00001010' ; 10s | 197 movlw b'00001010' ; 10s |
198 movwf cvt_temp2 | 198 movwf cvt_temp2 |
199 clrf cvt_temp3 | 199 clrf cvt_temp3 |
209 btfsc DP_done | 209 btfsc DP_done |
210 bsf pre_zero_flag | 210 bsf pre_zero_flag |
211 btfsc DP_done2 | 211 btfsc DP_done2 |
212 bsf pre_zero_flag | 212 bsf pre_zero_flag |
213 output16_4: | 213 output16_4: |
214 btfsc ignore_digit4 ; Ignore 4-5th digit? | 214 btfsc ignore_digit4 ; ignore 4-5th digit? |
215 bra output16_5 ; Yes, skip the rest | 215 bra output16_5 ; YES - skip the rest |
216 rcall DEC2ASCII ; 2nd order digit | 216 rcall DEC2ASCII ; 2nd order digit |
217 | 217 |
218 movlw b'00000001' ; 1s | 218 movlw b'00000001' ; 1s |
219 movwf cvt_temp2 | 219 movwf cvt_temp2 |
220 clrf cvt_temp3 | 220 clrf cvt_temp3 |
221 bsf pre_zero_flag | 221 bsf pre_zero_flag |
222 btfss ignore_digit5 ; Ignore 5th digit? | 222 btfss ignore_digit5 ; ignore 5th digit? |
223 rcall DEC2ASCII ; 1st order digit | 223 rcall DEC2ASCII ; 1st order digit |
224 bcf ignore_digit5 ; yes, and clear flag | 224 bcf ignore_digit5 ; YES - clear flag |
225 output16_5: | 225 output16_5: |
226 bcf ignore_digit4 ; Clear flag | 226 bcf ignore_digit4 ; clear flag |
227 bcf ignore_digit3 ; Clear flag | 227 bcf ignore_digit3 ; clear flag |
228 clrf ignore_digits | 228 clrf ignore_digits |
229 incf ignore_digits,F | 229 incf ignore_digits,F |
230 bcf DP_done | 230 bcf DP_done |
231 RETURN ; Done with convert.asm... | 231 return ; done with convert.asm... |
232 | 232 |
233 | 233 |
234 DEC2ASCII: | 234 DEC2ASCII: |
235 clrf cvt_temp1 ; converts into ASCII code | 235 clrf cvt_temp1 ; converts into ASCII code |
236 DEC2ASCII_2: | 236 DEC2ASCII_2: |
237 movf cvt_temp3,W | 237 movf cvt_temp3,W |
238 subwf hi_temp,W | 238 subwf hi_temp,W |
239 btfss STATUS,C | 239 btfss STATUS,C |
240 bra DEC2ASCII_4 | 240 bra DEC2ASCII_4 |
255 bra DEC2ASCII_2 | 255 bra DEC2ASCII_2 |
256 DEC2ASCII_4: | 256 DEC2ASCII_4: |
257 decfsz ignore_digits,F | 257 decfsz ignore_digits,F |
258 return | 258 return |
259 incf ignore_digits,F ; so ignore_digits stays zero for the test above | 259 incf ignore_digits,F ; so ignore_digits stays zero for the test above |
260 movlw '0' ; Offset for ASCII-value | 260 movlw '0' ; offset for ASCII-value |
261 addwf cvt_temp1,W | 261 addwf cvt_temp1,W |
262 btfsc pre_zero_flag ; is this a leading zero? | 262 btfsc pre_zero_flag ; is this a leading zero? |
263 bra DEC2ASCII_4_1 ; no | 263 bra DEC2ASCII_4_1 ; NO |
264 btfsc leftbind | 264 btfsc leftbind |
265 bra DEC2ASCII_6 | 265 bra DEC2ASCII_6 |
266 movlw ' ' ; instead of leading zeros a space! | 266 movlw ' ' ; instead of leading zeros a space! |
267 bra DEC2ASCII_5 | 267 bra DEC2ASCII_5 |
268 DEC2ASCII_4_1: | 268 DEC2ASCII_4_1: |
269 bsf all_zeros_flag ; display any zero from here | 269 bsf all_zeros_flag ; display any zero from here |
270 DEC2ASCII_5: | 270 DEC2ASCII_5: |
271 movwf POSTINC2 | 271 movwf POSTINC2 |
272 DEC2ASCII_6: | 272 DEC2ASCII_6: |
273 decfsz cvt_temp4,F ; Set decimal point? | 273 decfsz cvt_temp4,F ; set decimal point? |
274 RETURN ; No | 274 RETURN ; NO |
275 movlw "." ; Yes | 275 movlw "." ; YES |
276 movwf POSTINC2 | 276 movwf POSTINC2 |
277 bsf DP_done | 277 bsf DP_done |
278 return | 278 return |
279 | 279 |
280 | |
281 global outputHEX_call | |
282 outputHEX_call: ; coverts 8 Bit integer into two hex digits | |
283 movwf cvt_temp1 ; copy byte to process from WREG to local temp | |
284 swapf cvt_temp1,F ; swap nibbles to process upper nibble first | |
285 rcall outputHEX_nibble ; print nibble as ASCII | |
286 swapf cvt_temp1,F ; swap back to process lower nibble | |
287 outputHEX_nibble: | |
288 movff cvt_temp1,cvt_temp2 ; create a working copy | |
289 movlw 0x0F ; mask for lower nibble | |
290 andwf cvt_temp2,F ; isolate lower nibble | |
291 movlw 0x30 ; offset from binary 0 to ASCII code for "0" | |
292 addwf cvt_temp2,F ; add offset | |
293 movlw 0x39 ; ASCII code for "9" | |
294 cpfsgt cvt_temp2 ; character code in cvt_temp2 pointing to something after "9"? | |
295 bra outputHEX_1 ; NO - character code represents "0"..."9", can be printed | |
296 movlw 0x07 ; YES - offset from ASCII code for character after "9" to character "A" | |
297 addwf cvt_temp2,F ; - add offset, character code now represents "A"..."F", can be printed now | |
298 outputHEX_1: | |
299 movff cvt_temp2,POSTINC2 ; copy character code to output buffer | |
300 return | |
301 | |
302 | |
280 END | 303 END |