📄 common_function.lst
字号:
C51 COMPILER V7.09 COMMON_FUNCTION 09/17/2008 16:41:29 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE COMMON_FUNCTION
OBJECT MODULE PLACED IN .\output\common_function.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE gprs\common_function.c LARGE BROWSE INCDIR(audio\;eeprom\;extendUART\;flash
-\;gps\;inter\;key\;mcu\;menu\;usb\;gprs\;main\;1wire\) DEBUG OBJECTEXTEND PRINT(.\output\common_function.lst) OBJECT(.\o
-utput\common_function.obj)
line level source
1 #include "typedef.h"
2 #include "string.h"
3 #include "common_function.h"
4
5
6
7 /*little endian*/
8 void swap_ulong(Uchar *uldata)
9 {
10 1 Uchar uch[4];
11 1 memcpy(uch,uldata,4);
12 1 uldata[0]=uch[3];
13 1 uldata[1]=uch[2];
14 1 uldata[2]=uch[1];
15 1 uldata[3]=uch[0];
16 1 }
17
18 void swap_uint(Uchar *uidata)
19 {
20 1 Uchar uch[2];
21 1 memcpy(uch,uidata,2);
22 1 uidata[0]=uch[1];
23 1 uidata[1]=uch[0];
24 1 }
25
26
27
28
29 /*字符复制,包括'\0'*/
30 Uint8 stcpy(char *strDest, const char *strSrc)
31 {
32 1 if((strDest!=NULL) && (strSrc !=NULL))
33 1 {
34 2 while( (*strDest ++ = *strSrc ++) != '\0' )
35 2 {};
36 2
37 2 *strDest = *strSrc;
38 2 return (0);
39 2 }
40 1
41 1 else
42 1 {
43 2 return (1);
44 2 }
45 1
46 1 }
47
48 /*复制不重叠的内存块*/
49 Uint8 mecpy(void *strDest, const void *strSrc, Uint8 len)
50 {
51 1 if((strDest!=NULL) && (strSrc !=NULL))
52 1 {
53 2 Byte *pDest = (Byte *) strDest;
C51 COMPILER V7.09 COMMON_FUNCTION 09/17/2008 16:41:29 PAGE 2
54 2 Byte *pSrc = (Byte *) strSrc;
55 2
56 2 for ( ; len>0; len--)
57 2 {
58 3 *pDest ++ = *pSrc ++;
59 3 }
60 2 return (0);
61 2 }
62 1
63 1 else
64 1 {
65 2 return (1);
66 2 }
67 1
68 1 }
69
70
71 /*内存快清0*/
72 void clean(Uchar *ptr)
73 {
74 1 Int16 i;
75 1 for(i=0;i<=4;i++)
76 1 *(ptr+i)=0;
77 1 }
78
79
80 /*逐个比较*/
81 Uchar compare(Uchar *ptra,Uchar *ptrb, Int16 len)
82 {
83 1 Int16 i;
84 1 Int16 chk=0;
85 1
86 1 for(i=0;i<len;i++)
87 1 {
88 2 if((*(ptra+i))==(*(ptrb+i)))
89 2 {
90 3 chk++;
91 3 }
92 2
93 2 }
94 1 if(chk==len)
95 1 {
96 2 return(0);
97 2 }
98 1 else
99 1 {
100 2 return(1);
101 2 }
102 1 }
103
104 /*求字符长度,包括'\0'*/
105 Uint8 stlen(const Int8 *str)
106 {
107 1 Uint8 len=0;
108 1
109 1 if(str != NULL)
110 1 {
111 2 while( *str ++ != '\0' )
112 2 len++;
113 2
114 2 len++;
115 2 }
C51 COMPILER V7.09 COMMON_FUNCTION 09/17/2008 16:41:29 PAGE 3
116 1 return (len);
117 1 }
118
119 #define OSC15M
120 #define DELAYMSVALUE_11M 230
121 #define DELAYMSVALUE_15M 319
122 #define DELAYMSVALUE_22M 581
123 void delayMs(unsigned int timeMs)
124 {
125 1 unsigned int i, ms;
126 1
127 1 #ifdef OSC11M
for(ms=0; ms<timeMs; ms++)
for(i=0; i<DELAYMSVALUE_11M; i++); /*optimization1:145 optimization8:581*/
#endif
131 1 #ifdef OSC15M
132 1 for(ms=0; ms<timeMs; ms++)
133 1 for(i=0; i<DELAYMSVALUE_15M; i++);
134 1 #endif
135 1 #ifdef OSC22M
for(ms=0; ms<timeMs; ms++)
for(i=0; i<DELAYMSVALUE_22M; i++); /*optimization1:145 optimization8:581*/
#endif
139 1 }
140 /*
141 void delayMs(unsigned int timeMs)
142 {
143 unsigned int i, ms;
144
145 for(ms=0; ms<timeMs; ms++)
146 for(i=0; i<581; i++); //optimization1:145 optimization8:581
147 } */
148
149 unsigned char bin2bcd(unsigned char binValue)
150 {
151 1 unsigned char tmp;
152 1
153 1 tmp = binValue % 10;
154 1 tmp += (binValue /10) << 4;
155 1 return(tmp);
156 1 }
157
158 unsigned char bcd2bin(unsigned char bcdValue)
159 {
160 1 unsigned char tmp;
161 1
162 1 tmp = bcdValue % 16;
163 1 tmp += (bcdValue / 16) * 10;
164 1 return(tmp);
165 1 }
166
167 /**将两个字节压缩BCD码转换成uint,其中高位在前,低位在后*/
168 unsigned int bcd2uint(unsigned char *pBuf)
169 {
170 1 unsigned int tmp1, tmp2;
171 1 tmp1 = bcd2bin(*pBuf);
172 1 tmp2 = bcd2bin(*(pBuf+1));
173 1 return (tmp1*100+tmp2);
174 1 }
175
176 /**************************************
177 *检验buf中是否全部为0
C51 COMPILER V7.09 COMMON_FUNCTION 09/17/2008 16:41:29 PAGE 4
178 *OK:不全部为0
179 *KO:全部为0
180 **************************************/
181 Byte check_buf_zero(Byte *pBuf, Byte len)
182 {
183 1 Byte i;
184 1 for (i=0; i<len; i++)
185 1 {
186 2 if (pBuf[i] != 0)
187 2 return OK;
188 2 }
189 1 return KO;
190 1 }
191 /***********************************
192 *检验buf中是否全部为0xff
193 *OK:不全部为0xff
194 *KO:全部为0xff
195 ***********************************/
196 Byte check_buf_allff(Byte *pBuf, Byte len)
197 {
198 1 Byte i;
199 1 for (i=0; i<len; i++)
200 1 {
201 2 if (pBuf[i] != 0xff)
202 2 return OK;
203 2 }
204 1 return KO;
205 1 }
206
207 //将BCD数组转换成ASCII数组
208 Uint8 bcdArray_to_asciiArray(Uint8 *bcddata,char *pAscii, char bcdLen)
209 {
210 1 char i;//,j
211 1
212 1 if(pAscii != NULL)
213 1 {
214 2
215 2 for (i = 0;i < bcdLen;i ++)
216 2 {
217 3 *pAscii ++ = ((*bcddata)>>4) + 48;
218 3 *pAscii = ((*bcddata) & 0x0f) + 48;
219 3 pAscii ++;
220 3 bcddata ++;
221 3 }
222 2 return (OK);
223 2 }
224 1
225 1 else
226 1 {
227 2 return (KO);
228 2 }
229 1 }
230
231 //将ASCII数组转换成BCD数组
232 Uint8 asciiArray_to_bcdArray(char *pAscii, Uint8 *pBcddata, char bcdLen)
233 {
234 1 char i;
235 1
236 1 if(pAscii != NULL)
237 1 {
238 2 for (i = 0;i < bcdLen;i ++)
239 2 {
C51 COMPILER V7.09 COMMON_FUNCTION 09/17/2008 16:41:29 PAGE 5
240 3 ascii_to_bcd(pBcddata, pAscii);
241 3 pBcddata ++;
242 3 pAscii += 2;
243 3 }
244 2
245 2 return (OK);
246 2 }
247 1
248 1 else
249 1 {
250 2 return (KO);
251 2 }
252 1
253 1 }
254
255
256 /*一个字节的压缩BCD码转化为两个字节的ASCII码*/
257 Uint8 bcd_to_ascii(char *pAscii, Uint8 bcddata)
258 {
259 1 unsigned char tmp, result;
260 1 if(pAscii != NULL)
261 1 {
262 2 result = bcddata>>4;
263 2 *pAscii ++ = result + 48;
264 2 tmp = bcddata & 0x0f;
265 2 *pAscii = tmp + 48;
266 2
267 2 return (result*10+tmp);
268 2 }
269 1
270 1 else
271 1 {
272 2 return 0;
273 2 }
274 1
275 1 }
276
277
278
279 /*两个字节的ASCII码转化为一个字节的压缩BCD码*/
280 Uint8 ascii_to_bcd(Uint8 *pBcddata, char *pAscii)
281 {
282 1 Uint8 bcddata;
283 1 if(pAscii != NULL)
284 1 {
285 2 bcddata = (*pAscii - 48)<<4;
286 2 bcddata += *(pAscii+1) - 48;
287 2 *pBcddata = bcddata;
288 2
289 2 return (OK);
290 2 }
291 1
292 1 else
293 1 {
294 2 return (KO);
295 2 }
296 1
297 1 }
298
299
300 /*将汉字显示在偶数列上,若计算出的显示位置位于奇数列则显示在下一列上。*/
301 Uint8 odd_to_even(Uint8 disRow)
C51 COMPILER V7.09 COMMON_FUNCTION 09/17/2008 16:41:29 PAGE 6
302 {
303 1
304 1 if (disRow & 1 == 1) /*此时是奇数*/
305 1 {
306 2 disRow -= 1;
307 2 return (disRow);
308 2 }
309 1 return (disRow); /*此时是偶数*/
310 1 }
311
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1276 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 77
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -