📄 function.lst
字号:
305
306
307
308
309 UCHAR Kb_Scan(void)
310 {
311 1 UCHAR Sccode=0;
312 1 UCHAR Recode=0;
313 1 bit keyOn = 0;
314 1 P2 = 0x0f;/*发0x00行扫描码,列线输入*/
315 1 if(((P2&0x0f) != 0x0f)&& (keyOn == 0))/*若有键按下*/
316 1 {
317 2 Delay(200);/*延时去抖*/
318 2 if(((P2&0x0f) != 0x0f)&& (keyOn == 0))
319 2 {
320 3
321 3 Sccode = 0x7f;/*逐行扫描初值*/
322 3 while(((Sccode&0x08) !=0 ) && (keyOn == 0))/*扫描完毕*/
323 3 {
324 4 P2 = Sccode;/*输出行扫描码*/
325 4 if((P2&0x0f) !=0x0f )/*本行有键按下*/
326 4 {
327 5 keyOn = 1;
328 5 Recode = (P2&0x0f)|0xf0;/*|0xe1;*/ //modify 2nd,mar
329 5 Sccode = ~Sccode;
330 5 Recode = ~Recode;
331 5 }
332 4 else
333 4 Sccode = (Sccode>>1)|0x80;/*行扫描码右移*/
334 4 }
335 3 }
336 2 // goto END;
337 2 }
338 1 /* END:*/ keyOn = 0;
339 1 return(Sccode+Recode);/*返回特征字节码*/
340 1 }
341
342 void CommunicatePC(void) //communicate with PC
343 {
344 1 TOPC = 1;
345 1 Delay(255);
346 1 SerialInit();
347 1 Write_Display(dataGetProcess);
348 1 Delay5s();
349 1 if(SendAllToPC())
350 1 {
351 2 Write_Display(connectUnsuccess);
352 2 Delay5s();
353 2 }
354 1 else
355 1 {
356 2 Write_Display(overString);
357 2 Delay5s();
358 2 }
359 1 }
360
361 bit SendAllToPC(void) //发送EEPROM中的所有数据到PC
362 {
363 1 UINT EEPaddr;
364 1 UINT addTmp;
C51 COMPILER V7.09 FUNCTION 10/11/2006 16:32:11 PAGE 7
365 1 bit com_good;
366 1 UCHAR temp;
367 1 UCHAR TIMECALL=10;
368 1 Write_Display(communicateToPC);//"COMMUNICATING WITH PC.... ";
369 1 Delay5s();
370 1 do
371 1 {
372 2 if (TIMECALL==0)
373 2 {
374 3
375 3 com_good=1;
376 3 break;
377 3 }
378 2 Delay(200);
379 2 SBUF = MCUCALLPC;
380 2 while(TI == 0)
381 2 {
382 3 Write_Display(TRANSing);
383 3 }
384 2 TI = 0;
385 2
386 2 while(RI == 0)
387 2 {
388 3 Write_Display(RECIEVing);
389 3 }
390 2 RI = 0;
391 2 temp= SBUF;
392 2 TIMECALL--;
393 2 com_good=0;
394 2 }while(temp!= MCUCALLPC);//0x5b
395 1 if(com_good)
396 1 return com_good;
397 1 else
398 1 {
399 2 Write_Display(connectSuccess);
400 2 Delay5s();
401 2 Write_Display(dataGetProcess);
402 2 Delay5s();
403 2 for(EEPaddr = 0; EEPaddr < (8*EEPROMSIZE); ) //发送全部的数据
404 2 {
405 3 addTmp = EEPaddr;
406 3 AddressL= (UCHAR)(addTmp&0x00ff);
407 3 AddressH= (UCHAR)(addTmp>>8);
408 3 Read_I2c_Page(UIData,8);
409 3 addTmp = EEPaddr;
410 3 for(temp=0; temp<8; temp++) //发送已经读取的数据
411 3 {
412 4 SBUF = UIData[temp];
413 4 while(TI == 0);
414 4 TI = 0;
415 4 }
416 3 temp = (addTmp%10) + 0x30;
417 3 LCDChar(31,temp);
418 3 addTmp /= 10;
419 3
420 3 temp = (addTmp%10) + 0x30;
421 3 LCDChar(30,temp);
422 3 addTmp /= 10;
423 3
424 3 temp = (addTmp%10) + 0x30;
425 3 LCDChar(29,temp);
426 3 addTmp /= 10;
C51 COMPILER V7.09 FUNCTION 10/11/2006 16:32:11 PAGE 8
427 3
428 3 temp = (addTmp%10) + 0x30;
429 3 LCDChar(28,temp);
430 3
431 3 EEPaddr+=8;
432 3 }
433 2 SBUF = RECEIVEFILEOK; //发送结束标志
434 2 while(TI == 0);
435 2 TI = 0;
436 2 }
437 1 return com_good;
438 1 }
439
440 void SerialInit(void)
441 {
442 1 EA = 0;
443 1 SCON = 0x50;//RECIEVE DISABLE,MODE1,R/T
444 1 TR1 = 1;
445 1 RI = 0;
446 1 TI = 0;
447 1 }
448
449 void Read_I2c_Page(UCHAR * Tmp_Data,UCHAR num_array)
450 {
451 1 UCHAR num;
452 1 StartIic;
453 1 Write_8bit(Iic_Write);
454 1 Write_8bit(AddressH);
455 1 Write_8bit(AddressL);
456 1 StartIic;
457 1 Write_8bit(Iic_Read);
458 1 for(num=0;num<num_array-1;num++)
459 1 {
460 2 Tmp_Data[num]=ScanIic();
461 2 SendACK();
462 2 }
463 1 Tmp_Data[num]=ScanIic();
464 1 SendNotACK();
465 1 EndIic;
466 1 }
467
468 UCHAR Read_I2c_byte(UCHAR AddressH,UCHAR AddressL)
469 {
470 1 UCHAR num;
471 1 StartIic;
472 1 Write_8bit(Iic_Write);
473 1 Write_8bit(AddressH);
474 1 Write_8bit(AddressL); //write address to i2c;
475 1 StartIic;
476 1 Write_8bit(Iic_Read);
477 1 num=ScanIic();
478 1 SendNotACK();
479 1 EndIic;
480 1 return num;
481 1 }
482
483 void Write_I2c_Page(UCHAR * Tmp_Data, UCHAR num_array)
484 {
485 1 UCHAR num;
486 1 StartIic;
487 1 Write_8bit(Iic_Write);
488 1 Write_8bit(AddressH);
C51 COMPILER V7.09 FUNCTION 10/11/2006 16:32:11 PAGE 9
489 1 Write_8bit(AddressL);
490 1 for(num=0;num<num_array;num++)
491 1 {
492 2 Write_8bit(Tmp_Data[num]);
493 2 }
494 1 EndIic;
495 1 num=0;
496 1 while(num<250){Wait_Nop;Wait_Nop;num++;}
497 1 }
498
499 void Write_I2c_byte(UCHAR AddressH,UCHAR AddressL,UCHAR data_to_write)
500 {
501 1 UCHAR num;
502 1 StartIic;
503 1 Write_8bit(Iic_Write);
504 1 Write_8bit(AddressH);
505 1 Write_8bit(AddressL);
506 1 Write_8bit(data_to_write);
507 1 EndIic;
508 1 num=0;
509 1 while(num<250){Wait_Nop;Wait_Nop;num++;}
510 1 }
511
512
513 bit Write_8bit(UCHAR ch)
514 {
515 1 UCHAR i;
516 1 for(i=0;i<8;i++)
517 1 {
518 2 SDA=(bit)(ch&0x80);
519 2 ch<<=1;
520 2 SCL=1;
521 2 Wait_Nop;
522 2 SCL=0;
523 2 Wait_Nop;
524 2 }
525 1 return(CheckACK());
526 1 }
527
528 UCHAR ScanIic(void)
529 {
530 1 UCHAR i,j;/*IIC data*/
531 1 SDA=1;
532 1 j=0;
533 1 for(i=0;i<8;i++)
534 1 {
535 2 SCL=1;
536 2 j<<=1;/*这个指令已经有15个周期,所以无须再延时*/
537 2 j|=SDA;/*Scan 0*/ /*Scan 1*/
538 2 SCL=0;
539 2 }
540 1 return j;
541 1 }
542
543 bit CheckACK(void)
544 {
545 1 SDA=1;
546 1 SCL=1;
547 1 Wait_Nop;
548 1 if(SDA==1)return SDA;
549 1 if(SDA==1)return SDA;
550 1 if(SDA==1)return SDA;
C51 COMPILER V7.09 FUNCTION 10/11/2006 16:32:11 PAGE 10
551 1 SCL=0;
552 1 }
553
554 void SendACK(void)
555 {
556 1 SDA=0;
557 1 SCL=1;
558 1 Wait_Nop;
559 1 SCL=0;
560 1 SDA=1;
561 1
562 1 }
563
564 void SendNotACK(void)
565 {
566 1 SDA=1;
567 1 SCL=1;
568 1 Wait_Nop;
569 1 SCL=0;
570 1 SDA=0;
571 1 }
572
573
574 void SetInit()
575 {
576 1 SCON = 0xf0;
577 1 TR1 = 1;
578 1 RI = 0;
579 1 TI = 0;
580 1 EA = 1;
581 1 }
582
583 void Prepare()
584 {
585 1 UCHAR tmp,highByte,lowByte;
586 1 Write_Display(welString);//welString[32] = "SEARCHING CELLS PLEASE WAIT... ";
587 1 Delay5s();
588 1 QueryCell();
589 1 tmp = cellInfo.length; //acquire the number of cells
590 1 cellInfo.point = (cellInfo.length == 0)?0:(cellInfo.length-1); //point to the last cell
591 1 LCDClr();
592 1 LCDString(0,allNumber,16); //allNumber[16] = "ALL : CELLS ";
593 1 highByte = (tmp/10) + 0x30;//change hex to ascii
594 1 lowByte = (tmp%10) + 0x30;
595 1 LCDChar(6,highByte);
596 1 LCDChar(7,lowByte);
597 1 tmp = cellInfo.cellStack[cellInfo.point];
598 1 highByte = (tmp/10 + 0x30);
599 1 lowByte = (tmp%10 + 0x30);
600 1 LCDChar(16,highByte); //最大基站号
601 1 LCDChar(17,lowByte);
602 1 Delay5s();
603 1 }
604
605 void QueryCell() //query the cells and return the number of cells
606 {
607 1 UCHAR currentCell,highByte,lowByte,i,j;
608 1 UCHAR AddressL=1;
609 1 UCHAR AddressH=0;
610 1 bit rightFlag;
611 1 p = &QUERY;
612 1 for(currentCell=1; currentCell<=CELLMAXNUM; currentCell++)//CELLMAXNUM 可以修改CELL组数
C51 COMPILER V7.09 FUNCTION 10/11/2006 16:32:11 PAGE 11
613 1 {
614 2 highByte = (currentCell/10) + 0x30;
615 2 lowByte = (currentCell%10) + 0x30;
616 2 LCDChar(30,highByte);
617 2 LCDChar(31,lowByte); //display the querying cell
618 2 for(i = 0;i<8;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -