0
|
1 ;=============================================================================
|
|
2 ;
|
|
3 ; File convert.asm
|
|
4 ;
|
|
5 ; Converts register values to string
|
|
6 ;
|
|
7 ; Copyright (c) 2011, Matthias Heinrichs, HeinrichsWeikamp, all right reserved.
|
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
|
10 ; 2007-10-07 : [MH] Creation for OSTC sources
|
|
11 ; 2010-12-10 : [jDG] Optimize macro size
|
|
12 ;
|
|
13
|
|
14 #include "ostc3.inc" ; Mandatory header
|
|
15
|
|
16 ;=============================================================================
|
|
17
|
|
18 CBLOCK tmp+0x08 ; space for aa_wordprocessor
|
|
19 temp3
|
|
20 temp4
|
|
21 cvt_flags2
|
|
22 ; Reserved to tmp+0x10...
|
|
23 ENDC
|
|
24
|
|
25 #define pre_zero_flag cvt_flags2,0
|
|
26 #define all_zeros_flag cvt_flags2,1
|
|
27 #define DP_done cvt_flags2,2
|
|
28 #define DP_done2 cvt_flags2,3
|
|
29 #define show_last3 cvt_flags2,4
|
|
30 #define leading_zeros cvt_flags2,5
|
|
31
|
|
32 basic CODE
|
|
33
|
|
34 ;=============================================================================
|
|
35 global output99_call
|
|
36 output99_call:
|
|
37 clrf ignore_digits
|
|
38 incf ignore_digits,F
|
|
39 clrf temp4
|
|
40
|
|
41 global output99
|
|
42 output99:
|
|
43 movlw d'99'
|
|
44 cpfslt lo
|
|
45 movwf lo ; Limit to 99
|
|
46 movff lo,lo_temp
|
|
47 clrf hi_temp
|
|
48 bcf pre_zero_flag ; do not display leading zeros
|
|
49
|
|
50 LCD_val99_2:
|
|
51 movlw b'00001010' ; 10
|
|
52 movwf temp2
|
|
53 clrf temp3
|
|
54 rcall DEC2ASCII
|
|
55
|
|
56 movlw b'00000001' ; 1
|
|
57 movwf temp2
|
|
58 clrf temp3
|
|
59 bsf pre_zero_flag ; last figure, display zero (0)
|
|
60 rcall DEC2ASCII
|
|
61 RETURN
|
|
62
|
|
63 global output99x_call
|
|
64
|
|
65 output99x_call:
|
|
66 clrf ignore_digits
|
|
67 incf ignore_digits,F
|
|
68 clrf temp4
|
|
69
|
|
70 movlw d'99'
|
|
71 cpfslt lo
|
|
72 movwf lo ; Limit to 99
|
|
73 movff lo, lo_temp
|
|
74 clrf hi_temp
|
|
75 bsf pre_zero_flag ; display leading zeros
|
|
76 bra LCD_val99_2
|
|
77
|
|
78 global output8_call
|
|
79
|
|
80 output8_call:
|
|
81 clrf ignore_digits
|
|
82 incf ignore_digits,F
|
|
83 clrf temp4
|
|
84
|
|
85 output8:
|
|
86 movff lo, lo_temp
|
|
87 clrf hi_temp
|
|
88 bcf pre_zero_flag ; do not display leading zeros
|
|
89
|
|
90 movlw b'01100100' ; 100
|
|
91 movwf temp2
|
|
92 clrf temp3
|
|
93 rcall DEC2ASCII
|
|
94 bra LCD_val99_2
|
|
95
|
|
96 global output16_3_call
|
|
97 global output16_call
|
|
98 global output16
|
|
99 output16_3_call:
|
|
100 bsf show_last3
|
|
101 output16_call:
|
|
102 clrf ignore_digits
|
|
103 incf ignore_digits,F
|
|
104 clrf WREG
|
|
105 output16:
|
|
106 movwf temp4 ; Passed from output16dp macro, cleared by others.
|
|
107
|
|
108 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero
|
|
109
|
|
110 bsf leading_zeros
|
|
111 tstfsz temp4 ; Display leading zeros at all?
|
|
112 bcf leading_zeros
|
|
113
|
|
114 bsf DP_done2
|
|
115 tstfsz temp4
|
|
116 bcf DP_done2 ; decimal point not yet set
|
|
117
|
|
118 movff lo, lo_temp
|
|
119 movff hi, hi_temp
|
|
120 bcf pre_zero_flag ; do not display leading zeros
|
|
121
|
|
122 movlw b'00010000' ; 10000s
|
|
123 movwf temp2
|
|
124 movlw b'00100111'
|
|
125 movwf temp3
|
|
126 btfss show_last3 ; display only last three figures?
|
|
127 rcall DEC2ASCII ; No, show all. Here: 5th order digit
|
|
128
|
|
129 movlw b'11101000' ; 1000s
|
|
130 movwf temp2
|
|
131 movlw b'00000011'
|
|
132 movwf temp3
|
|
133 btfsc DP_done2 ; Is there a decimal point at all?
|
|
134 bra output16_2 ; no, use normal display mode
|
|
135
|
|
136 btfsc all_zeros_flag ; display any zero from here
|
|
137 bra output16_1 ; there was a figure /zero already
|
|
138
|
|
139 bsf pre_zero_flag ; display figure if zero?
|
|
140 decfsz temp4,W
|
|
141 bcf pre_zero_flag ; No
|
|
142
|
|
143 output16_1:
|
|
144 btfsc DP_done ; Decimal point set already?
|
|
145 bsf pre_zero_flag ; Yes, so display the rest
|
|
146 output16_2:
|
|
147 btfss show_last3 ; display only last three figures?
|
|
148 rcall DEC2ASCII ; No, show all. Here: 4th order digit
|
|
149 bcf show_last3 ; Yes, so display the rest
|
|
150
|
|
151 movlw b'01100100' ; 100s
|
|
152 movwf temp2
|
|
153 clrf temp3
|
|
154
|
|
155 btfsc ignore_digit3 ; Ignore 3rd-5th digit?
|
|
156 bra output16_5 ; Yes, skip the rest
|
|
157
|
|
158 btfsc DP_done2 ; Is there a decimal point at all?
|
|
159 bra output16_3 ; no, use normal display mode
|
|
160
|
|
161 btfsc all_zeros_flag ; display any zero from here
|
|
162 bra output16_2_1 ; there was a figure /zero already
|
|
163
|
|
164 bsf pre_zero_flag ; display figure if zero?
|
|
165 decfsz temp4,W
|
|
166 bcf pre_zero_flag ; No
|
|
167
|
|
168 output16_2_1:
|
|
169 btfsc DP_done ; Decimal point set already?
|
|
170 bsf pre_zero_flag ; Yes, so display the rest
|
|
171 btfsc DP_done2 ; Is there a decimal point at all?
|
|
172 bsf pre_zero_flag ; No, so display the rest
|
|
173 output16_3:
|
|
174 rcall DEC2ASCII ;3th order digit...
|
|
175
|
|
176 movlw b'00001010' ; 10s
|
|
177 movwf temp2
|
|
178 clrf temp3
|
|
179 btfsc DP_done2
|
|
180 bra output16_4
|
|
181
|
|
182 btfsc all_zeros_flag ; display any zero from here
|
|
183 bra output16_3_1 ; there was a figure /zero already
|
|
184
|
|
185 bsf pre_zero_flag
|
|
186 decfsz temp4,W
|
|
187 bcf pre_zero_flag
|
|
188
|
|
189 output16_3_1:
|
|
190 btfsc DP_done
|
|
191 bsf pre_zero_flag
|
|
192 btfsc DP_done2
|
|
193 bsf pre_zero_flag
|
|
194 output16_4:
|
|
195 btfsc ignore_digit4 ; Ignore 4-5th digit?
|
|
196 bra output16_5 ; Yes, skip the rest
|
|
197 rcall DEC2ASCII ; 2nd order digit
|
|
198
|
|
199 movlw b'00000001' ; 1s
|
|
200 movwf temp2
|
|
201 clrf temp3
|
|
202 bsf pre_zero_flag
|
|
203 btfss ignore_digit5 ; Ignore 5th digit?
|
|
204 rcall DEC2ASCII ; 1st order digit
|
|
205 bcf ignore_digit5 ; yes, and clear flag
|
|
206 output16_5:
|
|
207 bcf ignore_digit4 ; Clear flag
|
|
208 bcf ignore_digit3 ; Clear flag
|
|
209 clrf ignore_digits
|
|
210 incf ignore_digits,F
|
|
211 bcf DP_done
|
|
212 RETURN ; Done with convert.asm...
|
|
213
|
|
214 DEC2ASCII clrf temp1 ; converts into ASCII code
|
|
215 DEC2ASCII_2 movf temp3,W
|
|
216 subwf hi_temp,W
|
|
217 btfss STATUS,C
|
|
218 bra DEC2ASCII_4
|
|
219 bnz DEC2ASCII_3
|
|
220
|
|
221 movf temp2,W
|
|
222 subwf lo_temp,W
|
|
223 btfss STATUS,C
|
|
224 bra DEC2ASCII_4
|
|
225
|
|
226 DEC2ASCII_3 movf temp3,W
|
|
227 subwf hi_temp,F
|
|
228 movf temp2,W
|
|
229 subwf lo_temp,F
|
|
230 btfss STATUS,C
|
|
231 decf hi_temp,F
|
|
232 incf temp1,F
|
|
233 bsf pre_zero_flag
|
|
234 bra DEC2ASCII_2
|
|
235
|
|
236 DEC2ASCII_4
|
|
237 decfsz ignore_digits,F
|
|
238 return
|
|
239 incf ignore_digits,F ; so ignore_digits stays zero for the test above
|
|
240 movlw '0' ; Offset for Ascii-value
|
|
241 addwf temp1,W
|
|
242 btfsc pre_zero_flag ; is this a leading zero?
|
|
243 bra DEC2ASCII_4_1 ; no
|
|
244 btfsc leftbind
|
|
245 bra DEC2ASCII_6
|
|
246 movlw ' ' ; instead of leading zeros a space!
|
|
247 bra DEC2ASCII_5
|
|
248 DEC2ASCII_4_1:
|
|
249 bsf all_zeros_flag ; display any zero from here
|
|
250 DEC2ASCII_5
|
|
251 movwf POSTINC2
|
|
252 DEC2ASCII_6
|
|
253 decfsz temp4,F ; Set decimal point?
|
|
254 RETURN ; No
|
|
255 movlw "." ; Yes
|
|
256 movwf POSTINC2
|
|
257 bsf DP_done
|
|
258 RETURN
|
|
259
|
|
260 END |