📄 main.lst
字号:
190 1 (*ASCP)=(unsigned char) ( (*HexP)/16 );
191 1 if( (*ASCP)<=0x09 )
192 1 {
193 2 (*ASCP)+=0x30;
194 2 }
195 1 else
196 1 {
197 2 if( (*ASCP)<=0x0F )
198 2 {
199 3 (*ASCP)+=0x37;
200 3 }
201 2 }
202 1
203 1 ASCP++;
204 1
205 1 (*ASCP)=(unsigned char)( (*HexP)%16 );
206 1 if( (*ASCP)<=0x09 )
207 1 {
208 2 (*ASCP)+=0x30;
209 2 }
210 1 else
211 1 {
212 2 if( (*ASCP)<=0x0F )
213 2 {
214 3 (*ASCP)+=0x37;
215 3 }
216 2 }
217 1 }
218 //***************************************************************************
219 //@Function: void timer0_init(void);
220 //@description: This function initialize and start up the time0.
221 //@parameter: none
222 //@return: none
223 //***************************************************************************
224 //void timer0_init(void)
225 //{
226 // TH0=T0_TH;
227 // TL0=T0_TL;
228 // TR0=1;
C51 COMPILER V7.06 MAIN 10/23/2004 16:55:18 PAGE 5
229 //}
230 //***************************************************************************
231 //@Function: void init_timer2(void);
232 //@description: This function initialize and start up the time1.
233 //@parameter: none
234 //@return: none
235 //***************************************************************************
236 void init_timer2(void)
237 {
238 1 TH2=T2_TH;
239 1 TL2=T2_TL;
240 1 T2CON=0x81; //Timer2 work at timer mode,is clocked with 1/12 oscillator frequency.
241 1 }
242
243 //***************************************************************************************
244 //function: void init_comm(void)
245 //discription: this function initialize communication
246 //parameter: none
247 //return: none
248 //***************************************************************************************
249 void init_comm(void)
250 {
251 1 SCON=0x50;//communication mode 1
252 1 PCON=0x00;
253 1 TH1=0xfd;//20.83k
254 1 TL1=0xfd;
255 1 TR1=1;
256 1 }
257 //***************************************************************************
258 //@Function: void Project_init(void);
259 //@description: This function initializes the microcontroller.
260 //@parameter: none
261 //@return: none
262 //***************************************************************************
263 void Project_Init(void)
264 {
265 1 SYSCON = 0x20; //XMAP1=1, during access to XRAM or CAN controller WR and RD
266 1 //become active.
267 1 //and P0 and P2 used as data bus and address bus.
268 1 //XMAP0=0, enable access to CAN controller.
269 1 // EALE=0, if EA pin is forced to ground ALE is always generation
270 1 // is enabled.
271 1 // else ALE is disable when access to code memory on chip.
272 1 // ---------------- used peripherals -------------
273 1 CAN_vInit();
274 1 /// initializes the CAN module
275 1 TMOD=0x21; //Timer0 counter mode 1;Timer1 time mode 2 for RS232;
276 1 TH0=0;
277 1 TL0=0;
278 1 TR0=0;
279 1 init_timer2();
280 1 init_comm();
281 1 /// initializes A/D convertor
282 1 ad_init(0x00); //P1.0~P1.7 used as analog input port
283 1 INT_vInit();
284 1 // ---------------- SYSCON Register --------------
285 1 }
286 //****************************************************************************************************
287 //function: void int_to_bcd(unsigned char *pBCD,unsigned int Char);
288 //description: convert int variable to 3 bits BCD code ,stored into buffer pointed by pBCD
289 //parameter: pBCD---pointer of buffer to store BCD code
290 // Char---char to be converted
C51 COMPILER V7.06 MAIN 10/23/2004 16:55:18 PAGE 6
291 //return: none
292 //****************************************************************************************************
293 void int_to_bcd(unsigned char xdata *pBCD,unsigned int Char)
294 {
295 1 *(pBCD+2)=Char/100;
296 1 *(pBCD+1)=(Char%100)/10;
297 1 *pBCD=Char%10;
298 1 }
299 //****************************************************************************************************
300 //function: void float_to_bcd(unsigned char *pBCD,float Float);
301 //description: convert float variable to 6 bits BCD code ,stored into buffer pointed by pBCD
302 //parameter: pBCD---pointer of buffer to store BCD code
303 // Char---char to be converted
304 //return: none
305 //****************************************************************************************************
306 void float_to_bcd(unsigned char xdata *pBCD,float Float)
307 {
308 1 *(pBCD+5)=Float/100000;
309 1
310 1 Float-=*(pBCD+5)*100000;
311 1 *(pBCD+4)=Float/10000;
312 1
313 1 Float-=*(pBCD+4)*10000;
314 1 *(pBCD+3)=Float/1000;
315 1
316 1 Float-=*(pBCD+3)*1000;
317 1 *(pBCD+2)=Float/100;
318 1
319 1 Float-=*(pBCD+2)*100;
320 1 *(pBCD+1)=Float/10;
321 1
322 1 Float-=*(pBCD+1)*10;
323 1 *pBCD=Float;
324 1 }
325 //****************************************************************************************************
326 //function: void float_to_bcd1(unsigned char *pBCD,float Float);
327 //description: convert float variable to 6 bits BCD code ,stored into buffer pointed by pBCD,
328 // with one decimal
329 //parameter: pBCD---pointer of buffer to store BCD code
330 // Char---char to be converted
331 //return: none
332 //****************************************************************************************************
333 void float_to_bcd1(unsigned char xdata *pBCD,float Float)
334 {
335 1
336 1 *(pBCD+4)=Float/1000;
337 1 Float-=*(pBCD+4)*1000;
338 1 *(pBCD+3)=Float/100;
339 1 Float-=*(pBCD+3)*100;
340 1 *(pBCD+2)=Float/10;
341 1 Float-=*(pBCD+2)*10;
342 1 *(pBCD+1)=Float;
343 1 Float-=*(pBCD+1);
344 1 *pBCD=Float/0.1;
345 1 }
346
347 //****************************************************************************************************
348 //function: unsigned char find_data(unsigned int keyword,unsigned int *DataArrayPointer,unsigned n)
349 //description: find data by keyword(unsigned int type) from given data array that is in order,return the
-data's index
350 // the found data is always less or equal to the key word
351 //parameter: keyword---keyword which to be found; n---total data number
C51 COMPILER V7.06 MAIN 10/23/2004 16:55:18 PAGE 7
352 // DataArrayPointer---pointer of data array
353 //return: zero-base index of the keyword
354 //****************************************************************************************************
355 unsigned char find_data(unsigned int keyword,unsigned int code *DataArrayPointer,unsigned char n)
356 {
357 1 unsigned char m;//compare counter
358 1 unsigned char TempN;//index
359 1 bit ThanMax=1;//keyword more than maximal element flag
360 1 m=0;
361 1 while(m<n)//
362 1 {
363 2 if(*DataArrayPointer>keyword)//if find element more than keyword
364 2 {
365 3 if(m>0)
366 3 TempN=m-1;//get the less element's index
367 3 else
368 3 TempN=0;
369 3 m=n;//exit
370 3 ThanMax=0;//find the element
371 3 }
372 2 else if(*DataArrayPointer==keyword)//if find element equal to keyword
373 2 {
374 3 TempN=m;
375 3 m=n;//exit
376 3 ThanMax=0;//find the element
377 3 }
378 2 else
379 2 {
380 3 m++;//next element
381 3 DataArrayPointer++;
382 3 }
383 2 }
384 1 if(ThanMax)//not find element,get the maximal element's index
385 1 {
386 2 TempN=n-1;
387 2 }
388 1 return TempN;
389 1 }
390
391 //////////////////////////////main function/////////////////////////////////
392 void main(void)
393 {
394 1 unsigned char loop;
395 1 unsigned char sum;
396 1 unsigned int loop1;
397 1 unsigned int loop2;
398 1 unsigned int loop3;
399 1 unsigned char WaitTimer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -