📄 term3.lst
字号:
325 1 TL1 = TH1; // init Timer1
326 1 TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload
327 1 TMOD |= 0x20;
328 1 TR1 = 1; // START Timer1
329 1 TI0 = 1; // Indicate TX0 ready
330 1 }
331
332 void SW_UART_Init (void)
333 {
334 1 PCA0MD = 0x02; //PCA counter use SYSCLK/4 as timebase
335 1 PCA0CPM1 = 0x49; //PCA0CPM1:capture triggered by
336 1 //negative edge on P0.3,enable module1
337 1 //interrupt
338 1 PCA0CPM0 = 0x11; //PCA0CPM0:software timer mode,enable
339 1 //module 0 interrupt
340 1
341 1 PCA0CN |= 0x40; //enables the PCA Counter/Timer.
342 1
343 1 CCF0 = 0;
344 1 CCF1 = 0;
345 1 SRI = 0; //????????
346 1 STI = 0; // ????????
347 1 SW_TX = 1; // TX????????
348 1 STXBSY = 0; // ??SW_UART???
349 1 SREN = 1; //????
350 1 }
351
352 //-----------------------------------------------------------------------------
353 // ???0???
354 //-----------------------------------------------------------------------------
355
356 void Timer0_Init (void)
357 {
358 1 TMOD|=0X06; //COUNT0
359 1 TL0=0X0FF; //interrupt when every pulse come
360 1 TH0=0X0FF;
361 1 EA=1;
362 1 ET0=1; //COUNT0 INT ENABLE
363 1 TR0=1; //COUNT0 START
364 1 }
C51 COMPILER V7.50 TERM3 11/21/2006 18:11:14 PAGE 7
365 /*
366 void Timer0_ISR (void) interrupt 1
367 {
368 Pulse_s++;
369 }
370 */
371 //-----------------------------------------------------------------------------
372 // ADC0_Init ADBUSY, LP tracking, no Interrupt, ADC disabled
373 //-----------------------------------------------------------------------------
374 //
375 // Configure ADC0 to use ADBUSY as conversion source, and to sense the output
376 // of the temp sensor. Disables ADC end of conversion interrupt. Leaves ADC
377 // disabled.
378 //
379 void AD_Init (void)
380 {
381 1 ADC0CN = 0x40; // ADC0 disabled; LP tracking
382 1 // mode; ADC0 conversions are initiated
383 1 // on a write to ADBusy
384 1 AMX0P = 0x0a; // Temp sensor selected at + input
385 1 AMX0N = 0x11; // Single-ended mode
386 1
387 1 ADC0CF = (SYSCLK/3000000) << 3; // ADC conversion clock <= 3MHz
388 1
389 1 ADC0CF &= ~0x04; // Make ADC0 right-justified
390 1 REF0CN = 0x0E; // enable temp sensor, VREF = VDD, bias
391 1 // generator is on.
392 1
393 1 //EIE1 |= 0x08; // Enable ADC0 interrupt
394 1 ADC0CN = 0x80;
395 1 AD0BUSY = 1;
396 1 }
397
398
399 void Timer3_ISR (void) interrupt 14 //2.5ms
400 {
401 1 TMR3CN &= ~0x80;
402 1 key_scan_time++;
403 1
404 1 count_time++;
405 1
406 1 key_press_time++;
407 1
408 1 if (LcdBackLight_Delay_AfterS2410>0) LcdBackLight_Delay_AfterS2410--;
409 1 else if (key_zt==99)
410 1 {
411 2 LcdBackLight_Delay_AfterS2410=0;
412 2 // BG_EN=0;
413 2 }
414 1
415 1 if ((key_press_time>400) && (key_zt==99))
416 1 {
417 2 // BG_EN=1;
418 2 // S2410_PWR=1;
419 2 key_press_time=0;
420 2 key_zt=0;
421 2 }
422 1
423 1
424 1 if (key_time>0) key_time--;else key_time=0;
425 1
426 1 test++;
C51 COMPILER V7.50 TERM3 11/21/2006 18:11:14 PAGE 8
427 1
428 1 if (GPS_Alarm_js>0) GPS_Alarm_js--;else GPS_Alarm_js=0;
429 1
430 1 if (GPS_time>0) GPS_time--;else GPS_time=0;
431 1
432 1 if (FM_delay>0) FM_delay--;else FM_delay=0;
433 1
434 1 }
435
436 void Measure (void)
437 {
438 1 AMX0P = 0x00;
439 1 AMX0N = 0x11;
440 1 AD0INT = 0;
441 1 AD0BUSY = 1;
442 1 while (!AD0INT); // Wait for conversion to complete
443 1 AD0INT = 0; // Clear end-of-conversion indicator
444 1 GPS_Current=ADC0; // Store latest ADC conversion
445 1 }
446
447 //-----------------------------------------------------------------------------
448 // ???3???
449 //-----------------------------------------------------------------------------
450 void Timer3_Init ()
451 {
452 1 TMR3CN = 0x00;
453 1 CKCON |= 0x40;
454 1 TMR3RL = -60000;
455 1 TMR3 = TMR3RL;
456 1 EIE1 |= 0x80;
457 1 TMR3CN |= 0x04;
458 1
459 1 }
460
461 /*****************************************
462 * Uart Interrupt
463 *
464 *****************************************/
465 void Rcv_INT(void) interrupt 4
466 {
467 1 unsigned char tmp;
468 1 RI0=0;
469 1 tmp=RecvByte;
470 1 UartBuff=SBUF0;
471 1 RecvByte++;
472 1 if (RecvByte<HeaderLength+1)
473 1 {
474 2 Header[tmp]=UartBuff;
475 2 }
476 1 if(RecvByte==HeaderLength)
477 1 {
478 2 if((Header[0]=='$')&&(Header[1]=='G')&&(Header[2]=='P')&&(Header[3]=='G')&&(Header[4]=='G')&&(Header[5
-]=='A'))
479 2 { //if it is a "$GPGGA" frame
480 3 FrameLength=1;
481 3 }
482 2 else if((Header[0]=='$')&&(Header[1]=='G')&&(Header[2]=='P')&&(Header[3]=='R')&&(Header[4]=='M')&&(Heade
-r[5]=='C'))
483 2 { //if it is a "$GPGGA" frame
484 3 FrameLength=3;
485 3 }
486 2 else
C51 COMPILER V7.50 TERM3 11/21/2006 18:11:14 PAGE 9
487 2 {
488 3 FrameLength=2; //if it is other frame,discard it
489 3 }
490 2
491 2 }
492 1
493 1 if(FrameLength==2) //deal with other frame
494 1 {
495 2 if(UartBuff==0x0D) CRByte=UartBuff; //received CR
496 2
497 2 if(UartBuff==0x0A) LFByte=UartBuff; //received LF
498 2
499 2 if(CRByte&&LFByte) //received CR and LF,end of frame
500 2 {
501 3 RecvByte=0; //clear byte counter
502 3 FrameLength=0; //clear frame length
503 3 CRByte=0; //clear CR byte
504 3 LFByte=0; //clear LF byte
505 3
506 3 for (ii=0;ii<9;ii++) // Longitude
507 3 {
508 4 Longitude[ii]=0x30;
509 4 }
510 3 for (ii=0;ii<10;ii++) // Latitude
511 3 {
512 4 Latitude[ii]=0x30;
513 4 }
514 3
515 3 DGPS=0x30;
516 3
517 3 for (ii=0;ii<4;ii++) // HDOP
518 3 {
519 4 HDOP[ii]=0x30;
520 4 }
521 3 //IsGpsFrame=1;
522 3 //gps_ok=99;
523 3 }
524 2 }
525 1
526 1 if(FrameLength==1) //deal with the "$GPGGA" frame
527 1 {
528 2 if((RecvByte>7)&&(RecvByte<18)) UTCtime[tmp-7]=UartBuff; //received UTCtime
529 2
530 2 if((RecvByte==20)&&(UartBuff==',')) FrameLength=2;//????,???????,???????
531 2 if((RecvByte>18)&&(RecvByte<28)) Longitude[tmp-18]=UartBuff; //received jing du
532 2
533 2 if((RecvByte>30)&&(RecvByte<41)) Latitude[tmp-30]=UartBuff; //received wei du
534 2
535 2 if (RecvByte==44) DGPS=UartBuff;
536 2
537 2 if((RecvByte>45)&&(RecvByte<48)) weixing[tmp-45]=UartBuff; //received weixing ge shu
538 2
539 2 else if ((RecvByte>48)&&(RecvByte<53)&&(UartBuff!=','))
540 2 {
541 3 HDOP[tmp-48]=UartBuff;
542 3 }
543 2
544 2 if(RecvByte>60) //52
545 2 {
546 3 if(UartBuff==0x0D) CRByte=UartBuff; //received CR
547 3
548 3 if(UartBuff==0x0A) LFByte=UartBuff; //receive
C51 COMPILER V7.50 TERM3 11/21/2006 18:11:14 PAGE 10
549 3
550 3 if(CRByte&&LFByte) //received CR and LF,end of frame
551 3 {
552 4 RecvByte=0; //clear byte counter
553 4 FrameLength=0; //clear frame length
554 4 CRByte=0; //clear CR byte
555 4 LFByte=0; //clear LF byte
556 4 IsGpsFrame=1;
557 4 gps_ok=99;
558 4 }
559 3 }
560 2 }
561 1
562 1 if(FrameLength==3) //deal with the "$GPGGA" frame
563 1 {
564 2 // if((RecvByte>55)&&(RecvByte<62)) riqi[tmp-55]=UartBuff; //received Data
565 2
566 2 if(RecvByte>62) //52
567 2 {
568 3 if(UartBuff==0x0D) CRByte=UartBuff; //received CR
569 3
570 3 if(UartBuff==0x0A) LFByte=UartBuff; //receive
571 3
572 3 if(CRByte&&LFByte) //received CR and LF,end of frame
573 3 {
574 4 RecvByte=0; //clear byte counter
575 4 FrameLength=0; //clear frame length
576 4 CRByte=0; //clear CR byte
577 4 LFByte=0; //clear LF byte
578 4 //IsGpsFrame=1;
579 4 //gps_ok=99;
580 4 }
581 3 }
582 2 }
583 1
584 1 TI0=0;
585 1 }
586 //---------------------------------------------------------
587 // 模拟串口数据接收
588 /*-------------------------------------------------------
589 void SW_UartRecevie(void)
590 {
591 unsigned char tmp;
592
593 if(SRI == 1)
594 {
595 SRI = 0;
596 tmp = SW_RecvByte++;
597 SW_UartBuff = RDR;
598
599 if(SW_RecvByte <= SW_HeaderLength)
600 {
601 SW_Header[tmp] = SW_UartBuff;
602 }
603 if(SW_RecvByte == SW_HeaderLength)
604 {
605 if((SW_Header[0] == "S")&&(SW_Header[1] == "J")&&(SW_Header[2] == "-")&&(SW_Header[3] == "N")&&(SW
-_Header[4] == "a")&&(SW_Header[5] == "v")&&(SW_Header[6] == "i"))
606 {
607 SW_FrameLength = 2;
608 SW_IsFrame = 1;
609 LED = 0;
C51 COMPILER V7.50 TERM3 11/21/2006 18:11:14 PAGE 11
610 }
611 else
612 SW_FrameLength = 1;
613 }
614 if(SW_FrameLength == 1)
615 {
616 // if(UartBuff==0x0D) CRByte=UartBuff; //received CR
617 // if(UartBuff==0x0A) LFByte=UartBuff; //received LF
618
619 // if(CRByte&&LFByte)
620 // {
621 SW_RecvByte=0; //clear byte counter
622 SW_FrameLength=0; //clear frame length
623 SW_CRByte=0; //clear CR byte
624 SW_LFByte=0; //clear LF byte
625 // }
626 }
627 else if(SW_FrameLength == 2) //deal with "SJ-Navi"
628 {
629 if((SW_RecvByte> 8)&&(SW_RecvByte<14)) SW_Address[tmp-8] = SW_UartBuff;
630 if((SW_RecvByte>14)&&(SW_RecvByte<17)) SW_Command[tmp-14]= SW_UartBuff;
631 // if((SW_RecvByte<17)&&(SW_RecvByte<24)) SW_Date[tmp-17] = SW_UartBuff;
632
633 if(SW_RecvByte >24)
634 {
635 if(UartBuff==0x0D) CRByte=UartBuff; //received CR
636 if(UartBuff==0x0A) LFByte=UartBuff; //received LF
637
638 if(CRByte&&LFByte)
639 {
640 SW_RecvByte=0; //clear byte counter
641 SW_FrameLength=0; //clear frame length
642 SW_CRByte=0; //clear CR byte
643 SW_LFByte=0; //clear LF byte
644 // LED = 0;
645 }
646 }
647 }
648 //---------------
649 RDR = 0;
650 }
651 }
652
653 //-------------------------------------------------------*/
654
655 void Send_GPS(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -