|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 1
|
|
|
|
|
|
|
|
|
|
|
|
C51 COMPILER V9.54, COMPILATION OF MODULE C_LIB
|
|
|
|
OBJECT MODULE PLACED IN ..\out\c_lib.obj
|
|
|
|
COMPILER INVOKED BY: E:\KeilC51\C51\BIN\C51.EXE ..\source\clib\c_lib.c LARGE OMF2 OPTIMIZE(0,SIZE) BROWSE ORDER NOINTPRO
|
|
|
|
-MOTE INCDIR(..\source\bsp;..\source\msp;..\source\app;..\source\clib;..\source\cpu;..\source\ctask;..\source\tpc;..\sour
|
|
|
|
-ce\asp;..\source\debug;..\source\msp\uart;..\source\msp\simiic;..\source\bsp\oled;..\source\bsp\TTSSbsp) DEBUG PRINT(..\
|
|
|
|
-out\c_lib.lst) TABS(2) OBJECT(..\out\c_lib.obj)
|
|
|
|
|
|
|
|
line level source
|
|
|
|
|
|
|
|
1 /*****************************************************************************
|
|
|
|
2 * uart.c: UART API file for NXP LPC17xx Family Microprocessors
|
|
|
|
3 *
|
|
|
|
4 * Copyright (c) 2023 CCSENS
|
|
|
|
5 * All rights reserved.
|
|
|
|
6 *
|
|
|
|
7 * History
|
|
|
|
8 * 2009.05.27 ver 1.00 Prelimnary version, first Release
|
|
|
|
9 ///cc 2023/04/08--11:25:5 Lc_buf_from_const_uc
|
|
|
|
10 *
|
|
|
|
11 ******************************************************************************/
|
|
|
|
12
|
|
|
|
13
|
|
|
|
14 #include "c_type51.h"
|
|
|
|
15 #include "c_lib.h"
|
|
|
|
16 ///#include "../msp/msp_uart0.h"
|
|
|
|
17 ////#include "../msp/time.h"
|
|
|
|
18 #include <stdarg.h>
|
|
|
|
19
|
|
|
|
20
|
|
|
|
21 code vU16 us2fun2[5]
|
|
|
|
22 ={
|
|
|
|
23 1, //0
|
|
|
|
24 10,// 1
|
|
|
|
25 100,// 2
|
|
|
|
26 1000,// 3
|
|
|
|
27 10000// 4
|
|
|
|
28
|
|
|
|
29 };
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33 code vU32 ul2fun2[10]
|
|
|
|
34 ={
|
|
|
|
35 1, //0
|
|
|
|
36 10,// 1
|
|
|
|
37 100,// 2
|
|
|
|
38 1000,// 3
|
|
|
|
39 10000,// 4
|
|
|
|
40 100000,
|
|
|
|
41 1000000,
|
|
|
|
42 10000000,
|
|
|
|
43 100000000,
|
|
|
|
44 1000000000,//9
|
|
|
|
45 };
|
|
|
|
46
|
|
|
|
47 #if 0
|
|
|
|
|
|
|
|
同样是转义字符,\n 的作用相当于“Enter”键,而想退回去就可以用“Backspace”��
|
|
|
|
-�,也就是\b
|
|
|
|
这里还有一个可能用到的转义字符是\r :使光标回退到本行开头
|
|
|
|
\b 退格
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 2
|
|
|
|
|
|
|
|
\n 换行 0x0A
|
|
|
|
\f 走纸
|
|
|
|
\t 水平制表
|
|
|
|
\v 垂直制表
|
|
|
|
|
|
|
|
\r 0x0d
|
|
|
|
|
|
|
|
//如果追求内存紧张加上const INT32U ul2fun2[10]
|
|
|
|
|
|
|
|
|
|
|
|
void Lc_float2str(float f,U8 *str,U8 point_num);
|
|
|
|
{
|
|
|
|
S32 i = 0; U32 u32i = 0;
|
|
|
|
U8 n = 0;U8 m = 0;U8 d = 0;
|
|
|
|
switch(point_num)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
f *= 10.;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
f *= 100.;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
f *= 1000.;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
i = (S32)f;
|
|
|
|
// Lc_float2str(1.23,&d,2)
|
|
|
|
// Lc_float2str(0.23,&d,2)
|
|
|
|
// Lc_float2str(23.4,&d,1)
|
|
|
|
// Lc_float2str(-12345.236,&d,2)
|
|
|
|
// 1,1.2 12.3 240 0.12
|
|
|
|
if(i < 0)
|
|
|
|
{
|
|
|
|
str[n] = '-';
|
|
|
|
n ++;
|
|
|
|
i *= -1;
|
|
|
|
}
|
|
|
|
u32i = (U32)i;
|
|
|
|
m = 4;
|
|
|
|
if(u32i >= ul2fun2[m]) u32i = ul2fun2[m] - 1;
|
|
|
|
for(m = 0;m > 4;m ++)
|
|
|
|
{// 43210
|
|
|
|
d = (u32i /ul2fun2[m])%10;
|
|
|
|
if (d > 0)
|
|
|
|
str[n] = d;
|
|
|
|
n ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == point_num)
|
|
|
|
{
|
|
|
|
str[n] ='.';
|
|
|
|
n ++;
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 3
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
str[n] = i%10
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
123
|
|
|
|
124
|
|
|
|
125 U32 Abs2(S32 a)
|
|
|
|
126 {
|
|
|
|
127 1 if(a < 0)
|
|
|
|
128 1 {
|
|
|
|
129 2 a = -a;
|
|
|
|
130 2 }
|
|
|
|
131 1 return a;
|
|
|
|
132 1 }
|
|
|
|
133
|
|
|
|
134 ///despiking 削峰
|
|
|
|
135 void Lc_despiking_shift3_U16(vU16 *m)
|
|
|
|
136 {///只要中间的数据同时大于或小于两边的数据,则去掉
|
|
|
|
137 1 if(m[1] >= m[0])
|
|
|
|
138 1 {
|
|
|
|
139 2 if(m[1] > m[2])
|
|
|
|
140 2 {
|
|
|
|
141 3 m[1] = m[0];
|
|
|
|
142 3 }
|
|
|
|
143 2 }else if(m[1] < m[0])
|
|
|
|
144 1 {
|
|
|
|
145 2 if(m[1] < m[2])
|
|
|
|
146 2 {
|
|
|
|
147 3 m[1] = m[0];
|
|
|
|
148 3 }
|
|
|
|
149 2 }else
|
|
|
|
150 1 {
|
|
|
|
151 2
|
|
|
|
152 2 }
|
|
|
|
153 1 }
|
|
|
|
154
|
|
|
|
155 int libc_strlen(char *str)
|
|
|
|
156 {
|
|
|
|
157 1 char *tmp = str;
|
|
|
|
158 1 while(*tmp++)
|
|
|
|
159 1 ;
|
|
|
|
160 1 return tmp - str - 1;
|
|
|
|
161 1 }
|
|
|
|
162
|
|
|
|
163 U8* Lc_strcpy(U8* dst,const char* str)
|
|
|
|
164 {
|
|
|
|
165 1 U8 *p = dst;
|
|
|
|
166 1 while(*dst++ = *str++);
|
|
|
|
167 1 return p;
|
|
|
|
168 1 }
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171 U8 Lc_strStartsWith(U8 *s1,U8 *s2)
|
|
|
|
172 {
|
|
|
|
173 1 while(*s1 && *s2)
|
|
|
|
174 1 {
|
|
|
|
175 2 if(*s1++ != *s2++)
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 4
|
|
|
|
|
|
|
|
176 2 {
|
|
|
|
177 3 return 0;
|
|
|
|
178 3 }
|
|
|
|
179 2 }
|
|
|
|
180 1 return (*s2 == 0);
|
|
|
|
181 1 }
|
|
|
|
182
|
|
|
|
183
|
|
|
|
184 int hexToDec(const char *source)
|
|
|
|
185 {
|
|
|
|
186 1 int sum = 0;
|
|
|
|
187 1 long t = 1;
|
|
|
|
188 1 int i,len;
|
|
|
|
189 1
|
|
|
|
190 1 len = Lc_strlen(source);
|
|
|
|
191 1 for(i=len-1; i>=0; i--)
|
|
|
|
192 1 {
|
|
|
|
193 2 sum += t * getIndexOfSigns(*(source + i));
|
|
|
|
194 2 t *= 16;
|
|
|
|
195 2 }
|
|
|
|
196 1
|
|
|
|
197 1 return sum;
|
|
|
|
198 1
|
|
|
|
199 1 }
|
|
|
|
200 unsigned char hex_to_char(unsigned char hex)
|
|
|
|
201 {
|
|
|
|
202 1 if((hex>=0x30)&&(hex<=0x39))
|
|
|
|
203 1 hex = hex-0x30;
|
|
|
|
204 1 else if((hex>=0x41)&&(hex<=0x5A)) // capital
|
|
|
|
205 1 hex = 'A' + (hex - 0x41);
|
|
|
|
206 1 else if((hex>=0x61)&&(hex<=0x7A)) // little case
|
|
|
|
207 1 hex = 'a' + (hex - 0x61);
|
|
|
|
208 1 else
|
|
|
|
209 1 hex = 0xff;
|
|
|
|
210 1 return hex;
|
|
|
|
211 1 }
|
|
|
|
212
|
|
|
|
213 int getIndexOfSigns(char ch)
|
|
|
|
214 {
|
|
|
|
215 1 if(ch >= '0' && ch <= '9')
|
|
|
|
216 1 {
|
|
|
|
217 2 return ch - '0';
|
|
|
|
218 2 }
|
|
|
|
219 1 if(ch >= 'A' && ch <='F')
|
|
|
|
220 1 {
|
|
|
|
221 2 return ch - 'A' + 10;
|
|
|
|
222 2 }
|
|
|
|
223 1 if(ch >= 'a' && ch <= 'f')
|
|
|
|
224 1 {
|
|
|
|
225 2 return ch - 'a' + 10;
|
|
|
|
226 2 }
|
|
|
|
227 1 return -1;
|
|
|
|
228 1 }
|
|
|
|
229
|
|
|
|
230 void Lc_buf_copy_us(U16 *d,const U16 *s,U16 num)
|
|
|
|
231 {
|
|
|
|
232 1 U16 i;
|
|
|
|
233 1 for(i = 0; i < num; i ++)
|
|
|
|
234 1 {
|
|
|
|
235 2 *(d+i) = *(s+i);
|
|
|
|
236 2 }
|
|
|
|
237 1
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 5
|
|
|
|
|
|
|
|
238 1 }
|
|
|
|
239 void Lc_buf_from_const_uc(U8 *d,const U8 *s,U16 num)
|
|
|
|
240 {
|
|
|
|
241 1 U16 i;
|
|
|
|
242 1 for(i = 0; i < num; i ++)
|
|
|
|
243 1 {
|
|
|
|
244 2 *(d+i) = *(s+i);
|
|
|
|
245 2 }
|
|
|
|
246 1
|
|
|
|
247 1 }
|
|
|
|
248
|
|
|
|
249
|
|
|
|
250 void Lc_buf_copy_uc(U8 *d,const U8 *s,U16 num)
|
|
|
|
251 {
|
|
|
|
252 1 U16 i;
|
|
|
|
253 1 for(i = 0; i < num; i ++)
|
|
|
|
254 1 {
|
|
|
|
255 2 *(d+i) = *(s+i);
|
|
|
|
256 2 }
|
|
|
|
257 1
|
|
|
|
258 1 }
|
|
|
|
259
|
|
|
|
260 vU8 Lc_U8_media3(vU8 a,vU8 b,vU8 c)
|
|
|
|
261 {
|
|
|
|
262 1 if(a > b)
|
|
|
|
263 1 {
|
|
|
|
264 2 if(b > c)
|
|
|
|
265 2 {
|
|
|
|
266 3 return b;
|
|
|
|
267 3 }else
|
|
|
|
268 2 {// b<a b< c
|
|
|
|
269 3 if(c > a)
|
|
|
|
270 3 {/// a<c
|
|
|
|
271 4 return a;
|
|
|
|
272 4 }else
|
|
|
|
273 3 {// c<=a
|
|
|
|
274 4 return c;
|
|
|
|
275 4 }
|
|
|
|
276 3 }
|
|
|
|
277 2 }else
|
|
|
|
278 1 {// a<=b
|
|
|
|
279 2 if(b < c)
|
|
|
|
280 2 {
|
|
|
|
281 3 return b;
|
|
|
|
282 3 }else
|
|
|
|
283 2 {// a<=b c <= b
|
|
|
|
284 3 if(c > a)
|
|
|
|
285 3 {// a<c b
|
|
|
|
286 4 return c;
|
|
|
|
287 4 }else
|
|
|
|
288 3 {// c<=a b
|
|
|
|
289 4 return a;
|
|
|
|
290 4 }
|
|
|
|
291 3 }
|
|
|
|
292 2 }
|
|
|
|
293 1 }
|
|
|
|
294
|
|
|
|
295 vS32 Lc_S32_media3(vS32 a,vS32 b,vS32 c)
|
|
|
|
296 {
|
|
|
|
297 1 if(a > b)
|
|
|
|
298 1 {
|
|
|
|
299 2 if(b > c)
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 6
|
|
|
|
|
|
|
|
300 2 {
|
|
|
|
301 3 return b;
|
|
|
|
302 3 }
|
|
|
|
303 2 else
|
|
|
|
304 2 {// b<a b< c
|
|
|
|
305 3 if(c > a)
|
|
|
|
306 3 {/// a<c
|
|
|
|
307 4 return a;
|
|
|
|
308 4 }else
|
|
|
|
309 3 {// c<=a
|
|
|
|
310 4 return c;
|
|
|
|
311 4 }
|
|
|
|
312 3 }
|
|
|
|
313 2 }else
|
|
|
|
314 1 {// a<=b
|
|
|
|
315 2 if(b < c)
|
|
|
|
316 2 {
|
|
|
|
317 3 return b;
|
|
|
|
318 3 }else
|
|
|
|
319 2 {// a<=b c <= b
|
|
|
|
320 3 if(c > a)
|
|
|
|
321 3 {// a<c b
|
|
|
|
322 4 return c;
|
|
|
|
323 4 }else
|
|
|
|
324 3 {// c<=a b
|
|
|
|
325 4 return a;
|
|
|
|
326 4 }
|
|
|
|
327 3 }
|
|
|
|
328 2 }
|
|
|
|
329 1 }
|
|
|
|
330
|
|
|
|
331 void Lc_array_sort(S32 arr[],int n)
|
|
|
|
332 {
|
|
|
|
333 1 int i = 0, j=0, ok = 0;
|
|
|
|
334 1 S32 tmp = 0;
|
|
|
|
335 1 for(i=0; i<n-1; i++)
|
|
|
|
336 1 {
|
|
|
|
337 2 ok = 1;
|
|
|
|
338 2 for(j=0; j<n-i-1; j++)
|
|
|
|
339 2 {
|
|
|
|
340 3 if(arr[j] > arr[j+1])
|
|
|
|
341 3 {
|
|
|
|
342 4 ok = 0;
|
|
|
|
343 4 tmp = arr[j];
|
|
|
|
344 4 arr[j] = arr[j+1];
|
|
|
|
345 4 arr[j+1] = tmp;
|
|
|
|
346 4 }
|
|
|
|
347 3 }
|
|
|
|
348 2 if(ok)
|
|
|
|
349 2 {
|
|
|
|
350 3 break;
|
|
|
|
351 3 }
|
|
|
|
352 2 }
|
|
|
|
353 1 }
|
|
|
|
354
|
|
|
|
355 vS32 Lc_S32_media(vS32 val[],S16 num)
|
|
|
|
356 {
|
|
|
|
357 1 if(num <= 1)
|
|
|
|
358 1 {
|
|
|
|
359 2 return val[0];
|
|
|
|
360 2 }
|
|
|
|
361 1 else
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 7
|
|
|
|
|
|
|
|
362 1 {
|
|
|
|
363 2 Lc_array_sort(val,num);
|
|
|
|
364 2 return val[num/2];
|
|
|
|
365 2 }
|
|
|
|
366 1 }
|
|
|
|
367 U32 Lc_vS32_media(U32 *d, U8 n)
|
|
|
|
368 {
|
|
|
|
369 1 U8 i = 0,j = 0;
|
|
|
|
370 1 U32 h = 0;
|
|
|
|
371 1 if(n == 1)
|
|
|
|
372 1 {
|
|
|
|
373 2 return d[0];
|
|
|
|
374 2 }
|
|
|
|
375 1 for(i=0;i<n-1;i++)
|
|
|
|
376 1 {
|
|
|
|
377 2 for(j=i+1;j<n;j++)
|
|
|
|
378 2 {
|
|
|
|
379 3 if(d[i] > d[j])
|
|
|
|
380 3 {
|
|
|
|
381 4 h = d[i];
|
|
|
|
382 4 d[i] = d[j];
|
|
|
|
383 4 d[j] = h;
|
|
|
|
384 4 }
|
|
|
|
385 3 }
|
|
|
|
386 2 }
|
|
|
|
387 1 if(n%2 != 0) //奇数
|
|
|
|
388 1 {
|
|
|
|
389 2 return d[n/2];
|
|
|
|
390 2 }
|
|
|
|
391 1 else//偶数
|
|
|
|
392 1 {
|
|
|
|
393 2 return ((d[n/2] + d[n/2-1])/2);
|
|
|
|
394 2 }
|
|
|
|
395 1 }
|
|
|
|
396
|
|
|
|
397
|
|
|
|
398 U32 Lc_vU32_avg(U32 *d, U8 n)
|
|
|
|
399 {
|
|
|
|
400 1 U8 i = 0;
|
|
|
|
401 1 U32 sum = 0;
|
|
|
|
402 1 if(n == 1)
|
|
|
|
403 1 {
|
|
|
|
404 2 return d[0];
|
|
|
|
405 2 }
|
|
|
|
406 1 for(i=0;i<n;i++)
|
|
|
|
407 1 {
|
|
|
|
408 2 sum += d[i];
|
|
|
|
409 2 }
|
|
|
|
410 1 return sum / n;
|
|
|
|
411 1 }
|
|
|
|
412
|
|
|
|
413
|
|
|
|
414 ///// 0 1 (1-0)+1
|
|
|
|
415 //// 把buf中的数据从[usStart]到[usEnd] 共 usEnd-usStart+1 的数据转换成ascii
|
|
|
|
416 /// 0x11 0x22 ---> 0x31 0x31 0x32 0x32 '1' '1' '2' '2'
|
|
|
|
417 void Lc_hex2ascii(U8 *buf,U16 len,U8 *ascii)
|
|
|
|
418 {
|
|
|
|
419 1 vU16 t = 0,m = 0;
|
|
|
|
420 1 for(t = 0;t < len;t ++)
|
|
|
|
421 1 {
|
|
|
|
422 2
|
|
|
|
423 2 #if 1
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 8
|
|
|
|
|
|
|
|
424 2 ascii[m] = cguHex2Char[D_uc_high(buf[t])][1];
|
|
|
|
425 2 m ++;
|
|
|
|
426 2 ascii[m] = cguHex2Char[D_uc_low (buf[t])][1];
|
|
|
|
427 2 m ++;
|
|
|
|
428 2 ascii[m] =0x20;
|
|
|
|
429 2 m ++;
|
|
|
|
430 2 #else
|
|
|
|
|
|
|
|
ascii[m] = 0x30+m;
|
|
|
|
m++;
|
|
|
|
ascii[m] = 0x30+m;
|
|
|
|
m++;
|
|
|
|
ascii[m] = 0x30+m;
|
|
|
|
m++;
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
441 2 }
|
|
|
|
442 1 }
|
|
|
|
443
|
|
|
|
444 /// cguHex2Char[0][0] = 0x00 cguHex2Char[0][1] = 0x30
|
|
|
|
445 unsigned char code cguHex2Char[16][2]
|
|
|
|
446 ={
|
|
|
|
447 0x00,'0',
|
|
|
|
448 0x01,'1',
|
|
|
|
449 0x02,'2',
|
|
|
|
450 0x03,'3',
|
|
|
|
451 0x04,'4',
|
|
|
|
452 0x05,'5',
|
|
|
|
453 0x06,'6',
|
|
|
|
454 0x07,'7',
|
|
|
|
455 0x08,'8',
|
|
|
|
456 0x09,'9',
|
|
|
|
457 0x0A,'A',
|
|
|
|
458 0x0B,'B',
|
|
|
|
459 0x0C,'C',
|
|
|
|
460 0x0D,'D',
|
|
|
|
461 0x0E,'E',
|
|
|
|
462 0x0F,'F'
|
|
|
|
463 };
|
|
|
|
464
|
|
|
|
465
|
|
|
|
466 void Lc_for_int16(U16 i)
|
|
|
|
467 {
|
|
|
|
468 1 U16 m;
|
|
|
|
469 1 for(m=i;m>0;m--)
|
|
|
|
470 1 {
|
|
|
|
471 2 ///L0_Delay_1ms();
|
|
|
|
472 2 }
|
|
|
|
473 1 }
|
|
|
|
474
|
|
|
|
475 U32 Lc_abs(vS32 a,vS32 b)
|
|
|
|
476 {
|
|
|
|
477 1 if(a >= b)
|
|
|
|
478 1 {
|
|
|
|
479 2 return a - b;
|
|
|
|
480 2 }
|
|
|
|
481 1 return b - a;
|
|
|
|
482 1 }
|
|
|
|
483
|
|
|
|
484 void Lc_encrypt_id(U8 *enc_dst, U8 *enc_src, U32 enc_key, U8 src_len)
|
|
|
|
485 {
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 9
|
|
|
|
|
|
|
|
486 1 U8 i = 0,key0,key1,key2,key3;
|
|
|
|
487 1 key0 = enc_key >> 24 & 0xFF;
|
|
|
|
488 1 key1 = enc_key >> 16 & 0xFF;
|
|
|
|
489 1 key2 = enc_key >> 8 & 0xFF;
|
|
|
|
490 1 key3 = enc_key >> 0 & 0xFF;
|
|
|
|
491 1
|
|
|
|
492 1 for(i=0;i<src_len;i++)
|
|
|
|
493 1 {
|
|
|
|
494 2 enc_dst[i] = (((enc_src[i] << key0) + key1) ^ key2) + key3;
|
|
|
|
495 2 }
|
|
|
|
496 1 }
|
|
|
|
497
|
|
|
|
498 void Lc_encrypt_id1(U8 *enc_dst, U8 *enc_src, U8 enc_key[], U8 src_len)
|
|
|
|
499 {
|
|
|
|
500 1 U8 i;
|
|
|
|
501 1 for(i=0;i<src_len;i++)
|
|
|
|
502 1 {
|
|
|
|
503 2 enc_dst[i] = (((enc_src[i] << enc_key[0]) + enc_key[1]) ^ enc_key[2]) + enc_key[3];
|
|
|
|
504 2 }
|
|
|
|
505 1 }
|
|
|
|
506
|
|
|
|
507 int Lc_strlen(const char *str)
|
|
|
|
508 {
|
|
|
|
509 1 int i;
|
|
|
|
510 1 i = 0;
|
|
|
|
511 1 while((*str++)!='\0')
|
|
|
|
512 1 {
|
|
|
|
513 2 i++;
|
|
|
|
514 2 }
|
|
|
|
515 1 return i;
|
|
|
|
516 1 }
|
|
|
|
517 u8 Lc_ocr8(const u8 *d,u8 len)
|
|
|
|
518 {
|
|
|
|
519 1 unsigned char i = 0;
|
|
|
|
520 1 u16 sum = 0;
|
|
|
|
521 1 for(i = 0;i < len;i ++)
|
|
|
|
522 1 {
|
|
|
|
523 2 sum += *d;
|
|
|
|
524 2 d ++;
|
|
|
|
525 2 }
|
|
|
|
526 1 return ((u8)(sum&0x00ff));
|
|
|
|
527 1 }
|
|
|
|
528
|
|
|
|
529
|
|
|
|
530 int Lc_memset(U8 *buf,U8 c,U16 len)
|
|
|
|
531 {
|
|
|
|
532 1 U16 i;
|
|
|
|
533 1 for(i=0;i<len;i++)
|
|
|
|
534 1 {
|
|
|
|
535 2 buf[i] = c;
|
|
|
|
536 2 }
|
|
|
|
537 1 return 0;
|
|
|
|
538 1 }
|
|
|
|
539
|
|
|
|
540
|
|
|
|
541 #if 0
|
|
|
|
//判断是否大端字节序
|
|
|
|
int isBigEndianOrder(void)
|
|
|
|
{
|
|
|
|
int iVal = 1;
|
|
|
|
char *pChar = (char*)(&iVal);
|
|
|
|
if(*pChar == 1) //低字节在低地址(小端)
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 10
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 1; //(0x00000001) 低字节在高地址(大端) Aix采用的是大端法
|
|
|
|
}
|
|
|
|
|
|
|
|
U32 ntohl(U32 dat)
|
|
|
|
{
|
|
|
|
U32 res = 0;
|
|
|
|
if(dat == 0 || isBigEndianOrder()){
|
|
|
|
res = dat;
|
|
|
|
}else{
|
|
|
|
res = (((dat >> 0) & 0xFF) << 24) | (((dat >> 8) & 0xFF) << 16) | (((dat >> 16) & 0xFF) << 8) | ((
|
|
|
|
-(dat >> 24) & 0xFF) << 0);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
U32 htonl(U32 dat)
|
|
|
|
{
|
|
|
|
U32 res = 0;
|
|
|
|
if(dat == 0 || isBigEndianOrder()){
|
|
|
|
res = dat;
|
|
|
|
}else{
|
|
|
|
res = (((dat >> 0) & 0xFF) << 24) | (((dat >> 8) & 0xFF) << 16) | (((dat >> 16) & 0xFF) << 8) | ((
|
|
|
|
-(dat >> 24) & 0xFF) << 0);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
U16 ntohs(U16 dat)
|
|
|
|
{
|
|
|
|
U16 res = 0;
|
|
|
|
if(dat == 0 || isBigEndianOrder()){
|
|
|
|
res = dat;
|
|
|
|
}else{
|
|
|
|
res = (((dat >> 0) & 0xFF) << 8) | (((dat >> 8) & 0xFF) << 0) ;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
U16 htons(U16 dat)
|
|
|
|
{
|
|
|
|
U16 res = 0;
|
|
|
|
if(dat == 0 || isBigEndianOrder()){
|
|
|
|
res = dat;
|
|
|
|
}else{
|
|
|
|
res = (((dat >> 0) & 0xFF) << 8) | (((dat >> 8) & 0xFF) << 0) ;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
596
|
|
|
|
597 #if 0///#ifdef D_flash_max
|
|
|
|
|
|
|
|
|
|
|
|
// 0--9 '0'
|
|
|
|
// ABCEDF------0X41-- 87-6= 81
|
|
|
|
U8 Lc_Hex2Char(U8 CharStr)
|
|
|
|
{
|
|
|
|
U8 rd;
|
|
|
|
if (CharStr >9)//A 10-9+
|
|
|
|
{
|
|
|
|
rd = (CharStr - 10 + 'A') ;
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 11
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rd = (CharStr + '0') ;
|
|
|
|
}
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
// 0x30'0'----'9'--> 0x0----0x09
|
|
|
|
//0x61--'a'---'f'--> 0x0a---0x0f
|
|
|
|
//0x41 'A'--'F'--> 0x0a---0x0f
|
|
|
|
U8 Lc_Char2Hex(U8 CharStr)
|
|
|
|
{
|
|
|
|
U8 rd;
|
|
|
|
if (CharStr >= 'a')//0x61--'a'---'f'--> 0x0a---0x0f
|
|
|
|
{
|
|
|
|
rd = (CharStr - 'a' + 0x0a) ;
|
|
|
|
}
|
|
|
|
else if (CharStr >= 'A')//0x61--'a'---'f'--> 0x0a---0x0f
|
|
|
|
{
|
|
|
|
rd = (CharStr - 'A' + 0x0a) ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rd = (CharStr - '0') ;
|
|
|
|
}
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
//catch_protocol(s,d);
|
|
|
|
// 从 d中提取出协议,一般用于协议打包后的调试和透传,
|
|
|
|
// *s="iicsend:12 34 56 78 9a \r\n";
|
|
|
|
// i: 012345678
|
|
|
|
// 返回协议字节数量
|
|
|
|
// extern int strpos (const char *s, char c);
|
|
|
|
unsigned char catch_protocol (const char *d_src,char d_protocol[])
|
|
|
|
{
|
|
|
|
unsigned char n = 0,len = 0;//,i = 0;
|
|
|
|
int i = 0;
|
|
|
|
i = strpos(d_src, (char)':');
|
|
|
|
i ++;
|
|
|
|
len = strlen (d_src) - 2;
|
|
|
|
while(i < len)
|
|
|
|
{
|
|
|
|
d_protocol[n] = Lc_Char2Hex(*(d_src+i))*16;
|
|
|
|
i ++;
|
|
|
|
d_protocol[n] += Lc_Char2Hex(*(d_src+i));
|
|
|
|
i ++;i ++;
|
|
|
|
n ++;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 函数名:itoa 不同类型的cpu不一样 并且支持的最大数据取决于i = 1000000;D_value_m
|
|
|
|
-ax
|
|
|
|
* 描述 :将整形数据转换成字符串
|
|
|
|
* 输入 :-radix =10 表示10进制,其他结果为0
|
|
|
|
* -value 要转换的整形数
|
|
|
|
* -buf 转换后的字符串
|
|
|
|
* -radix = 10
|
|
|
|
* 输出 :无
|
|
|
|
* 返回 :无
|
|
|
|
* 调用 :被USART1_printf()调用
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 12
|
|
|
|
|
|
|
|
|
|
|
|
Lc_int2a
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
#define D_value_max 100000
|
|
|
|
char *Lc_int2a(vS32 value, char *string, UN_TYPE radix)
|
|
|
|
{
|
|
|
|
vS32 i, d;
|
|
|
|
UN_TYPE flag = 0;
|
|
|
|
vU16 U16temp = 0;
|
|
|
|
char *ptr = string;
|
|
|
|
|
|
|
|
/* This implementation only works for decimal numbers. */
|
|
|
|
//value
|
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
*ptr++ = 0x30;
|
|
|
|
*ptr = 0;
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
U16temp = value;
|
|
|
|
switch(radix)
|
|
|
|
{//%X2 %X4 %X6
|
|
|
|
case '2':
|
|
|
|
*ptr++ = Lc_Hex2Char((U16temp>>4)&0x0f);
|
|
|
|
*ptr++ = Lc_Hex2Char((U16temp)&0x0f);
|
|
|
|
*ptr = 0;
|
|
|
|
return string;
|
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
*ptr++ = Lc_Hex2Char((U16temp>>12)&0x0f);
|
|
|
|
*ptr++ = Lc_Hex2Char((U16temp>>8)&0x0f);
|
|
|
|
*ptr++ = Lc_Hex2Char((U16temp>>12)&0x0f);
|
|
|
|
*ptr++ = Lc_Hex2Char((U16temp>>8)&0x0f);
|
|
|
|
*ptr++ = Lc_Hex2Char((U16temp>>4)&0x0f);
|
|
|
|
*ptr++ = Lc_Hex2Char((U16temp)&0x0f);
|
|
|
|
*ptr = 0;
|
|
|
|
return string;
|
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
case '8':
|
|
|
|
*ptr++ = Lc_HexToChar((value>>24)&0x0f);
|
|
|
|
*ptr++ = Lc_HexToChar((value>>20)&0x0f);
|
|
|
|
*ptr++ = Lc_HexToChar((value>>16)&0x0f);
|
|
|
|
*ptr++ = Lc_HexToChar((value>>12)&0x0f);
|
|
|
|
*ptr++ = Lc_HexToChar((value>>8 )&0x0f);
|
|
|
|
*ptr++ = Lc_HexToChar((value>>4 )&0x0f);
|
|
|
|
*ptr++ = Lc_HexToChar((value)&0x0f);
|
|
|
|
*ptr = 0;
|
|
|
|
return string;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 10:
|
|
|
|
/* if this is a negative value insert the minus sign. */
|
|
|
|
if (value < 0)
|
|
|
|
{
|
|
|
|
*ptr++ = '-';
|
|
|
|
|
|
|
|
/* Make the value positive. */
|
|
|
|
value *= -1;
|
|
|
|
}
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 13
|
|
|
|
|
|
|
|
i = D_value_max;
|
|
|
|
if (value > i)
|
|
|
|
{
|
|
|
|
value = i;
|
|
|
|
}
|
|
|
|
for (;i > 0; i /= 10)
|
|
|
|
{
|
|
|
|
d = value / i;
|
|
|
|
|
|
|
|
if (d || flag)
|
|
|
|
{
|
|
|
|
*ptr++ = (char)(d + 0x30);
|
|
|
|
value -= (d * i);
|
|
|
|
flag = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Null terminate the string. */
|
|
|
|
*ptr = 0;
|
|
|
|
|
|
|
|
return string;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*ptr++ = 0x30;
|
|
|
|
*ptr = 0;
|
|
|
|
return string;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} /* NCL_Itoa */
|
|
|
|
/// bits:生成的字符共几位数据
|
|
|
|
void Lc_int2D(vS16 value, char *string,char bits)
|
|
|
|
{
|
|
|
|
vS16 i, d;
|
|
|
|
UN_TYPE flag = 0;
|
|
|
|
// vU16 U16temp = 0;
|
|
|
|
char *ptr = string;
|
|
|
|
|
|
|
|
/* This implementation only works for decimal numbers. */
|
|
|
|
//value
|
|
|
|
|
|
|
|
// U16temp = value;
|
|
|
|
/* if this is a negative value insert the minus sign. */
|
|
|
|
if (value < 0)
|
|
|
|
{
|
|
|
|
*ptr++ = '-';
|
|
|
|
value *= -1;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
*ptr++ = ' ';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i = us2fun2[bits-1];
|
|
|
|
for (;i > 0; i /= 10)
|
|
|
|
{
|
|
|
|
d = value / i;
|
|
|
|
if((0 == d)&&(0 == flag)&&(1 != i))
|
|
|
|
{///
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 14
|
|
|
|
|
|
|
|
*ptr++ = ' ';
|
|
|
|
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
flag = 1;///第一个非零的数据出现
|
|
|
|
*ptr = (char)(d + 0x30);
|
|
|
|
*ptr++;
|
|
|
|
value -= (d * i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* NCL_Itoa */
|
|
|
|
|
|
|
|
|
|
|
|
//void (*L0_uart0_uc)(U8 ww);
|
|
|
|
|
|
|
|
// 带buf的printf fixme: 需要精简地方
|
|
|
|
void Lc_print_buf(char *dat4,...)
|
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
vS32 d;
|
|
|
|
char buf[64]; ///取决于cpu的内存大小,如果出现问题,请先定位到此处
|
|
|
|
// char send[16];
|
|
|
|
char n = 0;
|
|
|
|
char *dat = 0;
|
|
|
|
va_list ap;//va_list 是一个字符指针,可以理解为指向当前参数的一个指针,
|
|
|
|
//取参必须通过这个指针进行。
|
|
|
|
//<Step 1> 在调用参数表之前,定义一个 va_list 类型的变量,
|
|
|
|
//(假设va_list 类型变量被定义为ap);
|
|
|
|
va_start(ap, dat);
|
|
|
|
// 然后应该对ap 进行初始化,让它指向可变参数表里面的第一个参数,
|
|
|
|
//这是通过 va_start 来实现的,第一个参数是 ap 本身,第二个参数是在
|
|
|
|
//变参表前面紧挨着的一个变量,即“...”之前的那个参数;
|
|
|
|
|
|
|
|
dat = dat4;
|
|
|
|
// <Step 3> 然后是获取参数,调用va_arg,它的第一个参数是ap,
|
|
|
|
//第二个参数是要获取的参数的指定类型,然后返回这个指定类型的值,
|
|
|
|
//并且把 ap 的位置指向变参表的下一个变量位置;
|
|
|
|
//"e645654675y73\0"
|
|
|
|
while ( *dat != 0) // 判断是否到达字符串结束符
|
|
|
|
{
|
|
|
|
if ( *dat == 0x5c ) //'\'
|
|
|
|
{
|
|
|
|
switch ( *++dat )
|
|
|
|
{
|
|
|
|
case 'r': //回车符
|
|
|
|
ts_uart_send_depot.buf[n ++] = 0x0d;//L0pf_send_uc(0x0d);
|
|
|
|
dat ++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n': //换行符
|
|
|
|
ts_uart_send_depot.buf[n ++] = 0x0a;//L0pf_send_uc(0x0a);
|
|
|
|
dat ++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': //
|
|
|
|
ts_uart_send_depot.buf[n ++] = 0x09;//L0pf_send_uc(0x09);
|
|
|
|
dat ++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dat ++;
|
|
|
|
break;
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 15
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( *dat == '%')
|
|
|
|
{ //
|
|
|
|
switch ( *++dat )
|
|
|
|
{
|
|
|
|
case 'C':
|
|
|
|
case 'c': //字符
|
|
|
|
//va_arg()里的任务就是根据指定的参数类型
|
|
|
|
//取得本参数的值,并且把指针调到下一
|
|
|
|
//个参数的起始地址
|
|
|
|
//#define va_arg(ap,t)
|
|
|
|
//( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
|
|
|
|
|
|
|
|
//char *ap; %c " , 0x30,
|
|
|
|
s = va_arg(ap, const char *); // 0x30
|
|
|
|
ts_uart_send_depot.buf[n ++] = (char)s;// L0pf_send_uc((char)s); // '0'
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
case 'd': //十进制
|
|
|
|
//" %d",0x30,
|
|
|
|
//" %d",48,
|
|
|
|
// int i = 48;
|
|
|
|
//" %d",i,
|
|
|
|
|
|
|
|
d = va_arg(ap, int); // 0x30 =48d
|
|
|
|
Lc_int2a(d, buf, 10); //"buf="48" buf[0]='4' buf[1]='8'
|
|
|
|
for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s
|
|
|
|
{ //\0
|
|
|
|
ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s);
|
|
|
|
//printf("%c",*s);
|
|
|
|
}
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
case 'x': //字符串
|
|
|
|
d = va_arg(ap, int); // 0x30 =48d
|
|
|
|
dat++;//%X2 %X4 %X8
|
|
|
|
Lc_int2a(d, buf, *dat); //"buf="48" buf[0]='4' buf[1]='8'
|
|
|
|
for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s
|
|
|
|
{ //\0
|
|
|
|
ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s);
|
|
|
|
}
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
case 's': //字符串
|
|
|
|
s = va_arg(ap, const char *);
|
|
|
|
for ( ; *s; s++)
|
|
|
|
{
|
|
|
|
ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s);
|
|
|
|
}
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
case 'f': //十进制
|
|
|
|
d = va_arg(ap, int);
|
|
|
|
Lc_int2a(d, buf, 10);
|
|
|
|
for (s = buf; *s; s++)
|
|
|
|
{
|
|
|
|
ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s);
|
|
|
|
|
|
|
|
}
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 16
|
|
|
|
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* end of else if */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ts_uart_send_depot.buf[n ++] = (*dat++);//L0pf_send_uc( *dat++);
|
|
|
|
}
|
|
|
|
}//end while....
|
|
|
|
ts_uart_send_depot.max = n;
|
|
|
|
ts_uart_send_depot.p = ts_uart_send_depot.buf;
|
|
|
|
L0_uart0_sendbuf();
|
|
|
|
}//
|
|
|
|
#endif
|
|
|
|
934
|
|
|
|
935 #if 0 //5436345673456
|
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* 名称: L0_Usend_uc_hex
|
|
|
|
* 说明: 例如:L0_Usend_uc_hex(0x0c); output " 0c "
|
|
|
|
* 功能: 发送数据
|
|
|
|
* 调用: SendHUc()Lc_HexToChar()
|
|
|
|
* 输入:
|
|
|
|
* 返回值: 无
|
|
|
|
***********************************************************************/
|
|
|
|
void Lc_uc_hex(char ww)
|
|
|
|
{
|
|
|
|
L0_uart0_uc(Lc_Hex2Char((ww>>4)&0x0f));
|
|
|
|
L0_uart0_uc(Lc_Hex2Char(ww&0x0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lc_us_hex(U16 ww)
|
|
|
|
{//
|
|
|
|
U8 t;
|
|
|
|
t = (U8)(((ww >> 8)&0x00ff));
|
|
|
|
Lcp_uc_hex(t);
|
|
|
|
t = (U8)(((ww )&0x00ff));
|
|
|
|
Lcp_uc_hex(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lc_print_NC(char *dat,...)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
// 非缓存模式的打印 fixme: 发送16进制数据时有bug
|
|
|
|
void Lc_print33333(char *dat4,...)
|
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
vS32 d;
|
|
|
|
char buf[16];//char t;
|
|
|
|
char *dat = NULL;
|
|
|
|
va_list ap;//va_list 是一个字符指针,可以理解为指向当前参数的一个指针,
|
|
|
|
//取参必须通过这个指针进行。
|
|
|
|
//<Step 1> 在调用参数表之前,定义一个 va_list 类型的变量,
|
|
|
|
//(假设va_list 类型变量被定义为ap);
|
|
|
|
va_start(ap, dat4);
|
|
|
|
// 然后应该对ap 进行初始化,让它指向可变参数表里面的第一个参数,
|
|
|
|
//这是通过 va_start 来实现的,第一个参数是 ap 本身,第二个参数是在
|
|
|
|
//变参表前面紧挨着的一个变量,即“...”之前的那个参数;
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 17
|
|
|
|
|
|
|
|
dat =dat4;
|
|
|
|
// <Step 3> 然后是获取参数,调用va_arg,它的第一个参数是ap,
|
|
|
|
//第二个参数是要获取的参数的指定类型,然后返回这个指定类型的值,
|
|
|
|
//并且把 ap 的位置指向变参表的下一个变量位置;
|
|
|
|
//"e645654675y73\0"
|
|
|
|
while ( *dat != 0) // 判断是否到达字符串结束符
|
|
|
|
{
|
|
|
|
if ( *dat == 0x5c ) //'\'
|
|
|
|
{
|
|
|
|
switch ( *++dat )
|
|
|
|
{
|
|
|
|
case 'r': //回车符
|
|
|
|
L0_uart0_uc(0x0d);
|
|
|
|
dat ++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n': //换行符
|
|
|
|
L0_uart0_uc(0x0a);
|
|
|
|
dat ++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': //
|
|
|
|
L0_uart0_uc(0x09);
|
|
|
|
dat ++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dat ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( *dat == '%')
|
|
|
|
{ //
|
|
|
|
switch ( *++dat )
|
|
|
|
{
|
|
|
|
case 'C':
|
|
|
|
case 'c': //字符
|
|
|
|
//va_arg()里的任务就是根据指定的参数类型
|
|
|
|
//取得本参数的值,并且把指针调到下一
|
|
|
|
//个参数的起始地址
|
|
|
|
//#define va_arg(ap,t)
|
|
|
|
//( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
|
|
|
|
|
|
|
|
//char *ap; %c " , 0x30,
|
|
|
|
s = va_arg(ap, const char *); // 0x30
|
|
|
|
L0_uart0_uc((char)s); // '0'
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
case 'd': //十进制
|
|
|
|
//" %d",0x30,
|
|
|
|
//" %d",48,
|
|
|
|
// int i = 48;
|
|
|
|
//" %d",i, //#define va_arg(ap,t) (((t *)ap)++[0]) //(((int *)ap)++[0])
|
|
|
|
|
|
|
|
d = va_arg(ap, int); // 0x30 =48d
|
|
|
|
d >>= 8;
|
|
|
|
Lc_int2a(d, buf, 10); //"buf="48" buf[0]='4' buf[1]='8'
|
|
|
|
for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s
|
|
|
|
{ //\0
|
|
|
|
L0_uart0_uc(*s);
|
|
|
|
//printf("%c",*s);
|
|
|
|
}
|
|
|
|
dat++;
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 18
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
case 'x': //字符串
|
|
|
|
d = va_arg(ap, int); // 0x30 =48d
|
|
|
|
d >>= 8;
|
|
|
|
dat++;//%X2 %X4 %X8
|
|
|
|
Lc_int2a(d, buf, *dat); //"buf="48" buf[0]='4' buf[1]='8'
|
|
|
|
for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s
|
|
|
|
{ //\0
|
|
|
|
L0_uart0_uc(*s);
|
|
|
|
}
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
case 's': //字符串
|
|
|
|
s = va_arg(ap, const char *);
|
|
|
|
for ( ; *s; s++)
|
|
|
|
{
|
|
|
|
L0_uart0_uc(*s);
|
|
|
|
}
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
case 'f': //十进制
|
|
|
|
d = va_arg(ap, int);
|
|
|
|
Lc_int2a(d, buf, 10);
|
|
|
|
for (s = buf; *s; s++)
|
|
|
|
{
|
|
|
|
L0_uart0_uc(*s);
|
|
|
|
|
|
|
|
}
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dat++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* end of else if */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
L0_uart0_uc(*dat ++);
|
|
|
|
//t = *dat;
|
|
|
|
//L0pf_send_uc = L0_uart0_uc;
|
|
|
|
//L0pf_send_uc(t);
|
|
|
|
//L0_uart0_uc(t);
|
|
|
|
//dat++;
|
|
|
|
}
|
|
|
|
}//end while....斯蒂芬
|
|
|
|
}//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///计算CRC校验码
|
|
|
|
unsigned int CRC16(unsigned char *ptr, unsigned char len)
|
|
|
|
{
|
|
|
|
unsigned int crc=0xffff;
|
|
|
|
unsigned char i;
|
|
|
|
while(len--)
|
|
|
|
{
|
|
|
|
crc ^=*ptr++;
|
|
|
|
for(i=0;i<8;i++)
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 19
|
|
|
|
|
|
|
|
{
|
|
|
|
if(crc & 0x1)
|
|
|
|
{
|
|
|
|
crc>>=1;
|
|
|
|
crc^=0xa001;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
crc>>=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///检测CRC校验码是否正确
|
|
|
|
unsigned char CheckCRC(unsigned char *ptr,unsigned char len)
|
|
|
|
{
|
|
|
|
unsigned int crc;
|
|
|
|
crc = (unsigned int)CRC16(ptr,(len-2));
|
|
|
|
if(ptr[len-1]==(crc>>8) && ptr[len-2]==(crc & 0x00ff))
|
|
|
|
{
|
|
|
|
return 0xff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *strstr(const char *str1, const char *str2)
|
|
|
|
{
|
|
|
|
char *cp = (char*)str1;
|
|
|
|
char *s1, *s2;
|
|
|
|
|
|
|
|
if (!*str2)
|
|
|
|
return((char *)str1);
|
|
|
|
|
|
|
|
while (*cp)
|
|
|
|
{
|
|
|
|
s1 = cp;
|
|
|
|
s2 = (char *)str2;
|
|
|
|
|
|
|
|
while (*s1 && *s2 && !(*s1 - *s2))
|
|
|
|
s1++, s2++;
|
|
|
|
|
|
|
|
if (!*s2)
|
|
|
|
return(cp);
|
|
|
|
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//40
|
|
|
|
void Lc_int2str_4(U32 ui_in,char *d)
|
|
|
|
{
|
|
|
|
U8 m = 0;//,i;
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 20
|
|
|
|
|
|
|
|
|
|
|
|
if (ui_in >= ul2fun2[3])// 1,000 12345
|
|
|
|
{
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*(d+m) = ' ';
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui_in >= ul2fun2[2])// 100 12345
|
|
|
|
{
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*(d+m) = ' ';
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
{
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*(d+m) = ' ';
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 123
|
|
|
|
void Lc_int2str_3(U32 ui_in,char *d)
|
|
|
|
{
|
|
|
|
U8 m = 0;//,i;
|
|
|
|
|
|
|
|
if (ui_in >= ul2fun2[2])// 100 12345
|
|
|
|
{
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*(d+m) = ' ';
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
{
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*(d+m) = ' ';
|
|
|
|
m ++;
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 21
|
|
|
|
|
|
|
|
}
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Lc_int2str(123456, 5,3,&str[0]');
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
blank 填充字符 ' '或者其他unsigned char *blank)//保留以后使用
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Lc_int2str(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d)
|
|
|
|
{
|
|
|
|
U8 m = 0,i;
|
|
|
|
for(i = 0;i < len;i++)
|
|
|
|
{
|
|
|
|
if(point != 0)
|
|
|
|
{
|
|
|
|
if(point == (len-i+1))
|
|
|
|
{
|
|
|
|
*(d+m) = '.';
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ui_in>=ul2fun2[len-i])
|
|
|
|
{
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,(len-i));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*(d+m) = ' ';
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*(d+m) = 0x30 + Lc_WEI(ui_in,1);
|
|
|
|
m++;
|
|
|
|
*(d+m) = 0x00;
|
|
|
|
//*(d+m) = 'e';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// input: 123456d
|
|
|
|
// output: '1' '2' '3'....
|
|
|
|
//对应的点阵 为 0123456789. ,最后为空格,专为显示点阵类的数值使用
|
|
|
|
void Lc_int2number(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d)
|
|
|
|
{
|
|
|
|
U8 i,m = 0; //uc_temp,
|
|
|
|
for(i = len+1;i != 0;i--)// len + 1 point 占用一位
|
|
|
|
{
|
|
|
|
if(point == (len-i))
|
|
|
|
{
|
|
|
|
d[len-m] = '.';//'.'
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
if (ui_in>=ul2fun2[i-1])
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 22
|
|
|
|
|
|
|
|
{
|
|
|
|
d[len-m] = (U8)((ui_in/ul2fun2[i-1])%10);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d[len-m] = ' ';//' '
|
|
|
|
}
|
|
|
|
m ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d[len-m] = (U8)(ui_in%10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lc_Byte_cp(BYTE *src,BYTE *dis, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < len ;i ++)
|
|
|
|
{
|
|
|
|
*dis = *src;
|
|
|
|
dis ++;
|
|
|
|
src ++;
|
|
|
|
}
|
|
|
|
//return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
void Lc_Byte_print(BYTE *src,int len)
|
|
|
|
{
|
|
|
|
int i, d;
|
|
|
|
for(i = 0; i < len ;i ++)
|
|
|
|
{
|
|
|
|
*dis = *src;
|
|
|
|
dis ++;
|
|
|
|
src ++;
|
|
|
|
}
|
|
|
|
//return 0;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// -10........+10
|
|
|
|
|
|
|
|
U32 L2_fun_number_show(int i,char str[4])
|
|
|
|
{
|
|
|
|
U8 c;
|
|
|
|
int cint;
|
|
|
|
|
|
|
|
if(i >= 0)
|
|
|
|
{
|
|
|
|
cint = i;
|
|
|
|
str[0] =' ';
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cint = 0 - i;
|
|
|
|
str[0] ='-';
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
c = Lc_WEI(cint,1);
|
|
|
|
if(0 == c)
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 23
|
|
|
|
|
|
|
|
{
|
|
|
|
str[1] =' ';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str[1] = 0x30+ c;
|
|
|
|
|
|
|
|
}
|
|
|
|
str[2] = 0x30+ Lc_WEI(cint,0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//L1_lkt_write(s_room_val.ui_t3,s_room_val.ui_t3,s_task_lkt.din);
|
|
|
|
//U_uluiuc
|
|
|
|
|
|
|
|
void Lc_2ui2buf(vU32 ui_t2,vU32 ui_t3,volatile BYTE out[])
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
volatile U_uluiuc t;
|
|
|
|
//s_temp[]
|
|
|
|
t.uiv[0] = ui_t2;
|
|
|
|
t.uiv[1] = ui_t3;
|
|
|
|
|
|
|
|
|
|
|
|
Lc_Byte_cp(t.dv,out,8);
|
|
|
|
|
|
|
|
out[3] = D_ul2uc_0( ui_t2);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[2] = D_ul2uc_0( ui_t2);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[1] = D_ul2uc_0( ui_t2);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[0] = D_ul2uc_0( ui_t2);
|
|
|
|
|
|
|
|
|
|
|
|
out[7] = D_ul2uc_0( ui_t3);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[6] = D_ul2uc_0( ui_t3);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[5] = D_ul2uc_0( ui_t3);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[4] = D_ul2uc_0( ui_t3);
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
out[0] = D_ul2uc_0( ui_t2);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[1] = D_ul2uc_0( ui_t2);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[2] = D_ul2uc_0( ui_t2);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[3] = D_ul2uc_0( ui_t2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
out[4] = D_ul2uc_0( ui_t3);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[5] = D_ul2uc_0( ui_t3);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[6] = D_ul2uc_0( ui_t3);
|
|
|
|
ui_t2 >>= 8;
|
|
|
|
out[7] = D_ul2uc_0( ui_t3);
|
|
|
|
*/
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 24
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void L1_buf22ui(volatile BYTE in[],vU32 *ui_t2,vU32 *ui_t3)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
volatile U_uluiuc t;
|
|
|
|
Lc_Byte_cp(in,t.dv,8);
|
|
|
|
*ui_t2 = t.uiv[0];
|
|
|
|
*ui_t3 = t.uiv[1];
|
|
|
|
*ui_t2 = 0;
|
|
|
|
*ui_t2|= (U32)in[3];
|
|
|
|
*ui_t2|= (U32)(in[2]<<8);
|
|
|
|
*ui_t2|= (U32)(in[1]<<16);
|
|
|
|
*ui_t2|= (U32)(in[0]<<24);
|
|
|
|
|
|
|
|
*ui_t3 = 0;
|
|
|
|
*ui_t3|= (U32)in[7];
|
|
|
|
*ui_t3|= (U32)(in[6]<<8);
|
|
|
|
*ui_t3|= (U32)(in[5]<<16);
|
|
|
|
*ui_t3|= (U32)(in[4]<<24);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
*ui_t2 = 0;
|
|
|
|
*ui_t2|= (U32)in[0];
|
|
|
|
*ui_t2|= (U32)(in[1]<<8);
|
|
|
|
*ui_t2|= (U32)(in[2]<<16);
|
|
|
|
*ui_t2|= (U32)(in[3]<<24);
|
|
|
|
/*
|
|
|
|
*ui_t3 = 0;
|
|
|
|
*ui_t3|= (INT32U)in[4];
|
|
|
|
*ui_t3|= (INT32U)(in[5]<<8);
|
|
|
|
*ui_t3|= (INT32U)(in[6]<<16);
|
|
|
|
*ui_t3|= (INT32U)(in[7]<<24);
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
U32 Lc_abs(vU32 a,vU32 b,vU32 *diff)
|
|
|
|
{
|
|
|
|
if(a >= b)
|
|
|
|
{
|
|
|
|
*diff = a-b;
|
|
|
|
return 1;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
*diff = b-a;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static U8 count_n(u8 n,u8 d)
|
|
|
|
{
|
|
|
|
if(n < d)
|
|
|
|
{
|
|
|
|
return MAX_OUT_NUM + n - d ;
|
|
|
|
}
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 25
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return n-d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
U32 Abs(S32 a)
|
|
|
|
{
|
|
|
|
if(a < 0)
|
|
|
|
{
|
|
|
|
a = -a;
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif //#if 0 //5436345673456
|
|
|
|
1494
|
|
|
|
1495
|
|
|
|
1496
|
|
|
|
1497 //12,34
|
|
|
|
1498 void Lc_int2str_2_2(U32 ui_in,char *d)
|
|
|
|
1499 {
|
|
|
|
1500 1 U8 m = 0;//,i;
|
|
|
|
1501 1
|
|
|
|
1502 1 if (ui_in >= ul2fun2[4])// 1000 123456
|
|
|
|
1503 1 {
|
|
|
|
1504 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1505 2 m ++;
|
|
|
|
1506 2 }
|
|
|
|
1507 1 else
|
|
|
|
1508 1 {
|
|
|
|
1509 2 *(d+m) = ' ';
|
|
|
|
1510 2 m ++;
|
|
|
|
1511 2 }
|
|
|
|
1512 1 if (ui_in >= ul2fun2[3])// 1000 12345
|
|
|
|
1513 1 {
|
|
|
|
1514 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1515 2 m ++;
|
|
|
|
1516 2 }
|
|
|
|
1517 1 else
|
|
|
|
1518 1 {
|
|
|
|
1519 2 *(d+m) = ' ';
|
|
|
|
1520 2 m ++;
|
|
|
|
1521 2 }
|
|
|
|
1522 1
|
|
|
|
1523 1 if (ui_in >= ul2fun2[2])// 100 12345
|
|
|
|
1524 1 {
|
|
|
|
1525 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1526 2 m ++;
|
|
|
|
1527 2 }
|
|
|
|
1528 1 else
|
|
|
|
1529 1 {
|
|
|
|
1530 2 *(d+m) = '0';
|
|
|
|
1531 2 m ++;
|
|
|
|
1532 2 }
|
|
|
|
1533 1
|
|
|
|
1534 1 *(d+m) = '.';
|
|
|
|
1535 1 m ++;
|
|
|
|
1536 1 if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 26
|
|
|
|
|
|
|
|
1537 1 {
|
|
|
|
1538 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1539 2 m ++;
|
|
|
|
1540 2 }
|
|
|
|
1541 1 else
|
|
|
|
1542 1 {
|
|
|
|
1543 2 *(d+m) = '0';
|
|
|
|
1544 2 m ++;
|
|
|
|
1545 2 }
|
|
|
|
1546 1 *(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
1547 1
|
|
|
|
1548 1 m ++;
|
|
|
|
1549 1 *(d+m) = 0;
|
|
|
|
1550 1
|
|
|
|
1551 1 }
|
|
|
|
1552
|
|
|
|
1553 /// 0-999
|
|
|
|
1554 void Lc_int2str_3(U32 ui_in,char *d)
|
|
|
|
1555 {
|
|
|
|
1556 1 U8 m = 0;//,i;
|
|
|
|
1557 1 if (ui_in >= ul2fun2[3])
|
|
|
|
1558 1 {
|
|
|
|
1559 2 ui_in = 999;
|
|
|
|
1560 2 }
|
|
|
|
1561 1 if (ui_in >= ul2fun2[2])// 100 12345
|
|
|
|
1562 1 {
|
|
|
|
1563 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1564 2 }
|
|
|
|
1565 1 else
|
|
|
|
1566 1 {
|
|
|
|
1567 2 *(d+m) = ' ';
|
|
|
|
1568 2 }
|
|
|
|
1569 1 m ++;
|
|
|
|
1570 1
|
|
|
|
1571 1 if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
1572 1 {
|
|
|
|
1573 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1574 2 }
|
|
|
|
1575 1 else
|
|
|
|
1576 1 {
|
|
|
|
1577 2 *(d+m) = ' ';
|
|
|
|
1578 2 }
|
|
|
|
1579 1 m ++;
|
|
|
|
1580 1 *(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
1581 1 m ++;
|
|
|
|
1582 1 *(d+m) = 0;
|
|
|
|
1583 1 }
|
|
|
|
1584 /// 0-99
|
|
|
|
1585 void Lc_int2str_2(U32 ui_in,char *d)
|
|
|
|
1586 {
|
|
|
|
1587 1 U8 m = 0;//,i;
|
|
|
|
1588 1 if (ui_in >= ul2fun2[2])
|
|
|
|
1589 1 {
|
|
|
|
1590 2 ui_in = 99;
|
|
|
|
1591 2 }
|
|
|
|
1592 1
|
|
|
|
1593 1 if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
1594 1 {
|
|
|
|
1595 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1596 2 }
|
|
|
|
1597 1 else
|
|
|
|
1598 1 {
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 27
|
|
|
|
|
|
|
|
1599 2 *(d+m) = ' ';
|
|
|
|
1600 2 }
|
|
|
|
1601 1 m ++;
|
|
|
|
1602 1 *(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
1603 1 m ++;
|
|
|
|
1604 1 *(d+m) = 0;
|
|
|
|
1605 1 }
|
|
|
|
1606 void Lc_uc2str_2(U8 ui_in,char *d)
|
|
|
|
1607 {
|
|
|
|
1608 1 U8 m = 0;//,i;
|
|
|
|
1609 1 if (ui_in >= ul2fun2[2])
|
|
|
|
1610 1 {
|
|
|
|
1611 2 ui_in = 99;
|
|
|
|
1612 2 }
|
|
|
|
1613 1
|
|
|
|
1614 1 if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
1615 1 {
|
|
|
|
1616 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1617 2 }
|
|
|
|
1618 1 else
|
|
|
|
1619 1 {
|
|
|
|
1620 2 *(d+m) = ' ';
|
|
|
|
1621 2 }
|
|
|
|
1622 1 m ++;
|
|
|
|
1623 1 *(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
1624 1 m ++;
|
|
|
|
1625 1 *(d+m) = 0;
|
|
|
|
1626 1 }
|
|
|
|
1627
|
|
|
|
1628 // 123.4
|
|
|
|
1629
|
|
|
|
1630 void Lc_int2str_3_1(U32 ui_in,char *d)
|
|
|
|
1631 {
|
|
|
|
1632 1 U8 m = 0;//,i;
|
|
|
|
1633 1 if (ui_in >= ul2fun2[4])// 1000 12345
|
|
|
|
1634 1 {
|
|
|
|
1635 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1636 2 m ++;
|
|
|
|
1637 2 }
|
|
|
|
1638 1 else
|
|
|
|
1639 1 {
|
|
|
|
1640 2 *(d+m) = ' ';
|
|
|
|
1641 2 m ++;
|
|
|
|
1642 2 }
|
|
|
|
1643 1
|
|
|
|
1644 1
|
|
|
|
1645 1 if (ui_in >= ul2fun2[3])// 1000 12345
|
|
|
|
1646 1 {
|
|
|
|
1647 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1648 2 m ++;
|
|
|
|
1649 2 }
|
|
|
|
1650 1 else
|
|
|
|
1651 1 {
|
|
|
|
1652 2 *(d+m) = ' ';
|
|
|
|
1653 2 m ++;
|
|
|
|
1654 2 }
|
|
|
|
1655 1
|
|
|
|
1656 1 if (ui_in >= ul2fun2[2])// 100 12345
|
|
|
|
1657 1 {
|
|
|
|
1658 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1659 2 m ++;
|
|
|
|
1660 2 }
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 28
|
|
|
|
|
|
|
|
1661 1 else
|
|
|
|
1662 1 {
|
|
|
|
1663 2 *(d+m) = ' ';
|
|
|
|
1664 2 m ++;
|
|
|
|
1665 2 }
|
|
|
|
1666 1
|
|
|
|
1667 1 if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
1668 1 {
|
|
|
|
1669 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1670 2 m ++;
|
|
|
|
1671 2 }
|
|
|
|
1672 1 else
|
|
|
|
1673 1 {
|
|
|
|
1674 2 *(d+m) = '0';
|
|
|
|
1675 2 m ++;
|
|
|
|
1676 2 }
|
|
|
|
1677 1 *(d+m) = '.';
|
|
|
|
1678 1 m ++;
|
|
|
|
1679 1 *(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
1680 1 m ++;
|
|
|
|
1681 1 *(d+m) = 0;
|
|
|
|
1682 1
|
|
|
|
1683 1 }
|
|
|
|
1684
|
|
|
|
1685
|
|
|
|
1686 //-123
|
|
|
|
1687 void Lc_sint2str_3(int i_in,char *d)
|
|
|
|
1688 {
|
|
|
|
1689 1 U8 m = 0;//,i;
|
|
|
|
1690 1 U32 ui_in;
|
|
|
|
1691 1 if(i_in < 0)
|
|
|
|
1692 1 {
|
|
|
|
1693 2 ui_in = (U32)(0-i_in);
|
|
|
|
1694 2 *(d+m) = '-';
|
|
|
|
1695 2 }else
|
|
|
|
1696 1 {
|
|
|
|
1697 2 ui_in = (U32)(i_in);
|
|
|
|
1698 2 *(d+m) = ' ';
|
|
|
|
1699 2 }
|
|
|
|
1700 1 m ++;
|
|
|
|
1701 1 if (ui_in >= ul2fun2[2])// 100 12345
|
|
|
|
1702 1 {
|
|
|
|
1703 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1704 2 }
|
|
|
|
1705 1 else
|
|
|
|
1706 1 {
|
|
|
|
1707 2 *(d+m) = ' ';
|
|
|
|
1708 2 }
|
|
|
|
1709 1 m ++;
|
|
|
|
1710 1 if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
1711 1 {
|
|
|
|
1712 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1713 2 }
|
|
|
|
1714 1 else
|
|
|
|
1715 1 {
|
|
|
|
1716 2 *(d+m) = ' ';
|
|
|
|
1717 2 }
|
|
|
|
1718 1 m ++;
|
|
|
|
1719 1 *(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
1720 1 m ++;
|
|
|
|
1721 1 *(d+m) = 0;
|
|
|
|
1722 1 }
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 29
|
|
|
|
|
|
|
|
1723
|
|
|
|
1724 //-32.1
|
|
|
|
1725 void Lc_sint2str_2_1(int i_in,char *d)
|
|
|
|
1726 {
|
|
|
|
1727 1 U8 m = 0;//,i;
|
|
|
|
1728 1 U32 ui_in;
|
|
|
|
1729 1 if(i_in < 0)
|
|
|
|
1730 1 {
|
|
|
|
1731 2 ui_in = (U32)(0-i_in);
|
|
|
|
1732 2 *(d+m) = '-';
|
|
|
|
1733 2 }else
|
|
|
|
1734 1 {
|
|
|
|
1735 2 ui_in = (U32)(i_in);
|
|
|
|
1736 2 *(d+m) = ' ';
|
|
|
|
1737 2 }
|
|
|
|
1738 1 m ++;
|
|
|
|
1739 1
|
|
|
|
1740 1 if (ui_in >= ul2fun2[3])// 1000 12345
|
|
|
|
1741 1 {
|
|
|
|
1742 2 ui_in = 999;
|
|
|
|
1743 2 }
|
|
|
|
1744 1
|
|
|
|
1745 1 if (ui_in >= ul2fun2[2])// 100 12345
|
|
|
|
1746 1 {
|
|
|
|
1747 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1748 2 }
|
|
|
|
1749 1 else
|
|
|
|
1750 1 {
|
|
|
|
1751 2 *(d+m) = ' ';
|
|
|
|
1752 2 }
|
|
|
|
1753 1 m ++;
|
|
|
|
1754 1 if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
1755 1 {
|
|
|
|
1756 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1757 2 }
|
|
|
|
1758 1 else
|
|
|
|
1759 1 {
|
|
|
|
1760 2 *(d+m) = '0';
|
|
|
|
1761 2 }
|
|
|
|
1762 1 m ++;
|
|
|
|
1763 1 *(d+m) = '.';
|
|
|
|
1764 1 m ++;
|
|
|
|
1765 1 *(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
1766 1 m ++;
|
|
|
|
1767 1 *(d+m) = 0;
|
|
|
|
1768 1 }
|
|
|
|
1769
|
|
|
|
1770 // 12345
|
|
|
|
1771
|
|
|
|
1772 void Lc_int2str_5(U32 ui_in,char *d)
|
|
|
|
1773 {
|
|
|
|
1774 1 U8 m = 1;//,i;
|
|
|
|
1775 1 *(d+0) = ' ';
|
|
|
|
1776 1 if (ui_in >= ul2fun2[4])// 10,000 12345
|
|
|
|
1777 1 {
|
|
|
|
1778 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1779 2 m ++;
|
|
|
|
1780 2 }
|
|
|
|
1781 1 else
|
|
|
|
1782 1 {
|
|
|
|
1783 2 *(d+m) = ' ';
|
|
|
|
1784 2 m ++;
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 30
|
|
|
|
|
|
|
|
1785 2 }
|
|
|
|
1786 1
|
|
|
|
1787 1
|
|
|
|
1788 1 if (ui_in >= ul2fun2[3])// 1,000 12345
|
|
|
|
1789 1 {
|
|
|
|
1790 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1791 2 m ++;
|
|
|
|
1792 2 }
|
|
|
|
1793 1 else
|
|
|
|
1794 1 {
|
|
|
|
1795 2 *(d+m) = ' ';
|
|
|
|
1796 2 m ++;
|
|
|
|
1797 2 }
|
|
|
|
1798 1
|
|
|
|
1799 1 if (ui_in >= ul2fun2[2])// 100 12345
|
|
|
|
1800 1 {
|
|
|
|
1801 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1802 2 m ++;
|
|
|
|
1803 2 }
|
|
|
|
1804 1 else
|
|
|
|
1805 1 {
|
|
|
|
1806 2 *(d+m) = ' ';
|
|
|
|
1807 2 m ++;
|
|
|
|
1808 2 }
|
|
|
|
1809 1
|
|
|
|
1810 1 if (ui_in >= ul2fun2[1])// 10 12345
|
|
|
|
1811 1 {
|
|
|
|
1812 2 *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10);
|
|
|
|
1813 2 m ++;
|
|
|
|
1814 2 }
|
|
|
|
1815 1 else
|
|
|
|
1816 1 {
|
|
|
|
1817 2 *(d+m) = ' ';
|
|
|
|
1818 2 m ++;
|
|
|
|
1819 2 }
|
|
|
|
1820 1
|
|
|
|
1821 1 *(d+m) = 0x30 + Lc_WEI(ui_in,0);
|
|
|
|
1822 1
|
|
|
|
1823 1 }
|
|
|
|
1824
|
|
|
|
1825 /******************************************************************************
|
|
|
|
1826 ** End Of File
|
|
|
|
1827 ******************************************************************************/
|
|
|
|
1828
|
|
|
|
*** WARNING C291 IN LINE 293 OF ..\source\clib\c_lib.c: not every exit path returns a value
|
|
|
|
*** WARNING C291 IN LINE 329 OF ..\source\clib\c_lib.c: not every exit path returns a value
|
|
|
|
*** WARNING C291 IN LINE 366 OF ..\source\clib\c_lib.c: not every exit path returns a value
|
|
|
|
*** WARNING C291 IN LINE 395 OF ..\source\clib\c_lib.c: not every exit path returns a value
|
|
|
|
|
|
|
|
|
|
|
|
MODULE INFORMATION: STATIC OVERLAYABLE
|
|
|
|
CODE SIZE = 7107 ----
|
|
|
|
CONSTANT SIZE = 82 ----
|
|
|
|
XDATA SIZE = 263 ----
|
|
|
|
PDATA SIZE = ---- ----
|
|
|
|
DATA SIZE = ---- ----
|
|
|
|
IDATA SIZE = ---- ----
|
|
|
|
BIT SIZE = ---- ----
|
|
|
|
EDATA SIZE = ---- ----
|
|
|
|
HDATA SIZE = ---- ----
|
|
|
|
XDATA CONST SIZE = ---- ----
|
|
|
|
FAR CONST SIZE = ---- ----
|
|
|
|
C51 COMPILER V9.54 C_LIB 06/11/2024 15:41:13 PAGE 31
|
|
|
|
|
|
|
|
END OF MODULE INFORMATION.
|
|
|
|
|
|
|
|
|
|
|
|
C51 COMPILATION COMPLETE. 4 WARNING(S), 0 ERROR(S)
|