⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer_user.ppl

📁 the timer control demo source for the NEC mcu
💻 PPL
📖 第 1 页 / 共 3 页
字号:
  488 : 
  489 : /*
  490 : *******************************************************************************
  491 : **
  492 : **  This device driver was created by Applilet for the 78K0/KB2, 78K0/KC2,
  493 : **  78K0/KD2, 78K0/KE2 and 78K0/KF2 8-Bit Single-Chip Microcontrollers.
  494 : **
  495 : **  Filename :  timer.h
  496 : **  Abstract :  This file implements a device driver for the timer module
  497 : **  Device :    uPD78F0547
  498 : **  Compiler:   NEC/CC78K0
  499 : **
  500 : *******************************************************************************
  501 : */
  502 : 
  503 : 
  504 : 
  505 : 
  506 : 
  507 : 
  508 : #define _HDTIMER_
  509 : 
  510 : /*
  511 : *******************************************************************************
  512 : **  Function proto type
  513 : *******************************************************************************
  514 : */
  515 : 
  516 : 
  517 : void TM00_Init(void);
  518 : void TM00_Enable(void);
  519 : void TM00_Disable(void);
  520 : 
  521 : 
  522 : 
  523 : void TM01_Init(void);
  524 : void TM01_Enable(void);
  525 : void TM01_Disable(void);
  526 : 
  527 : 
  528 : 
  529 : 
  530 : 
  531 : 
  532 : 
  533 : 
  534 : 
  535 : 
  536 : 
  537 : 
  538 : /*
  539 : *******************************************************************************
  540 : **  MacroDefine
  541 : *******************************************************************************
  542 : */
  543 : 



/*
78K/0 Series C Compiler V3.60 Preprocess List                                                           Date: 9 Oct 2005 Page:  11
*/

  544 : 
  545 : static unsigned long tm00_pulse0_old0=0;
  546 : static unsigned long tm00_pulse0_old1=0;
  547 : unsigned long tm00_pulse0_pos=0;
  548 : unsigned long tm00_pulse0_neg=0;
  549 : unsigned char tm00_pulse0_ovf=0;
  550 : 
  551 : static unsigned long tm00_pulse1_old0=0;
  552 : static unsigned long tm00_pulse1_old1=0;
  553 : unsigned long tm00_pulse1_pos=0;
  554 : unsigned long tm00_pulse1_neg=0;
  555 : unsigned char tm00_pulse1_ovf=0;
  556 : 
  557 : 
  558 : 
  559 : 
  560 : 
  561 : static unsigned long tm01_pulse0_old0=0;
  562 : unsigned long tm01_pulse0_pos=0;
  563 : unsigned long tm01_pulse0_neg=0;
  564 : 
  565 : 
  566 : 
  567 : 
  568 : /*
  569 : **-----------------------------------------------------------------------------
  570 : **
  571 : **  Abstract:
  572 : **      TM00 INTTM000 interrupt service routine
  573 : **      
  574 : **  Parameters:
  575 : **      None
  576 : **
  577 : **  Returns:
  578 : **      None    
  579 : **
  580 : **-----------------------------------------------------------------------------
  581 : */
  582 : __interrupt void HD_INTTM000( )
  583 : {
  584 : 
  585 : 
  586 :         /* Measurement of two pulse widths with free-running counter */
  587 :         unsigned long tm00_pulse1_cur0=0;
  588 :         unsigned long tm00_pulse1_cur1=0;
  589 :         unsigned char tm00_pulse1_out = P0 & 0x2;       /* pin state */
  590 :         unsigned char tm00_pulse_ovf = TMC00 & TM0n_TMC0n_OverflowFlag; /* overflow state */
  591 :         OVF00 = 0;                      /* OVF00 clear */
  592 :         
  593 :         tm00_pulse0_ovf = tm00_pulse_ovf;
  594 :         if(tm00_pulse1_out){                            /* input high level */
  595 :                 if((tm00_pulse0_ovf == 1)||( tm00_pulse1_ovf == 1)){/*overflow generated */
  596 :                         tm00_pulse1_cur0 = (unsigned long)CR000;
  597 :                         tm00_pulse1_neg = tm00_pulse1_cur0 + 0x10000 - tm00_pulse1_old0;
  598 :                 }
  599 :                 else{



/*
78K/0 Series C Compiler V3.60 Preprocess List                                                           Date: 9 Oct 2005 Page:  12
*/

  600 :                         tm00_pulse1_cur0 = (unsigned long)CR000;
  601 :                         tm00_pulse1_neg = tm00_pulse1_cur0 - tm00_pulse1_old0;
  602 :                 }
  603 :                 tm00_pulse1_old1 = tm00_pulse1_cur0;
  604 :         }
  605 :         else{                                           /* input low level */
  606 :                 if((tm00_pulse0_ovf == 1)||( tm00_pulse1_ovf == 1)){/*overflow generated */
  607 :                         tm00_pulse1_cur1 = (unsigned long)CR000;
  608 :                         tm00_pulse1_pos = tm00_pulse1_cur1 + 0x10000 - tm00_pulse1_old1;
  609 :                 }
  610 :                 else{
  611 :                         tm00_pulse1_cur1 = (unsigned long)CR000;
  612 :                         tm00_pulse1_pos = tm00_pulse1_cur1 - tm00_pulse1_old1;
  613 :                 }
  614 :                 tm00_pulse1_old0 = tm00_pulse1_cur1;
  615 :         }
  616 :         tm00_pulse1_ovf = 0;
  617 : 
  618 : 
  619 :         /*TODO*/
  620 : }
  621 : 
  622 : 
  623 : 
  624 : /*
  625 : **-----------------------------------------------------------------------------
  626 : **
  627 : **  Abstract:
  628 : **      TM00 INTTM010 interrupt service routine.
  629 : **
  630 : **  Parameters:
  631 : **      None
  632 : **
  633 : **  Returns:
  634 : **      None
  635 : **
  636 : **-----------------------------------------------------------------------------
  637 : */
  638 : __interrupt void HD_INTTM010( )
  639 : {
  640 : 
  641 :         unsigned long tm00_pulse0_cur0=0;
  642 :         unsigned long tm00_pulse0_cur1=0;
  643 :         unsigned char tm00_pulse0_out = P0 & 0x1;       /* pin state */
  644 :         unsigned char tm00_pulse_ovf = TMC00 & TM0n_TMC0n_OverflowFlag; /* overflow state */
  645 :         OVF00 = 0;                      /* OVF00 clear */
  646 :                 
  647 : 
  648 :         /* Measurement of two pulse widths with free-running counter */
  649 :         tm00_pulse1_ovf = tm00_pulse_ovf;
  650 :         if(tm00_pulse0_out){                            /* input high level */
  651 :                 if((tm00_pulse0_ovf == 1)||( tm00_pulse1_ovf == 1)){/*overflow generated */
  652 :                         tm00_pulse0_cur0 = (unsigned long)CR010;
  653 :                         tm00_pulse0_neg = tm00_pulse0_cur0 + 0x10000 - tm00_pulse0_old0;
  654 :                 }
  655 :                 else{



/*
78K/0 Series C Compiler V3.60 Preprocess List                                                           Date: 9 Oct 2005 Page:  13
*/

  656 :                         tm00_pulse0_cur0 = (unsigned long)CR010;
  657 :                         tm00_pulse0_neg = tm00_pulse0_cur0 - tm00_pulse0_old0;
  658 :                 }
  659 :                 tm00_pulse0_old1 = tm00_pulse0_cur0;
  660 :         }
  661 :         else{                                           /* input low level */
  662 :                 if((tm00_pulse0_ovf == 1)||( tm00_pulse1_ovf == 1)){/*overflow generated */
  663 :                         tm00_pulse0_cur1 = (unsigned long)CR010;
  664 :                         tm00_pulse0_pos = tm00_pulse0_cur1 + 0x10000 - tm00_pulse0_old1;
  665 :                 }
  666 :                 else{
  667 :                         tm00_pulse0_cur1 = (unsigned long)CR010;
  668 :                         tm00_pulse0_pos = tm00_pulse0_cur1 - tm00_pulse0_old1;
  669 :                 }
  670 :                 tm00_pulse0_old0 = tm00_pulse0_cur1;
  671 :         }
  672 :         tm00_pulse0_ovf = 0;
  673 : 
  674 : 
  675 :         /*TODO*/
  676 : }
  677 : 
  678 : 
  679 : 
  680 : 
  681 : 
  682 : /*
  683 : **-----------------------------------------------------------------------------
  684 : **
  685 : **  Abstract:
  686 : **      TM01 INTTM011 interrupt service routine.
  687 : **
  688 : **  Parameters:
  689 : **      None
  690 : **
  691 : **  Returns:
  692 : **      None
  693 : **
  694 : **-----------------------------------------------------------------------------
  695 : */
  696 : __interrupt void HD_INTTM011( )
  697 : {
  698 : 
  699 :         unsigned long tm01_pulse0_cur0=0;
  700 :         unsigned long tm01_pulse0_cur1=0;
  701 :         unsigned char tm01_pulse0_out = P0 & 0x20;      /* pin state */
  702 :         unsigned char tm01_pulse_ovf = TMC01 & TM0n_TMC0n_OverflowFlag; /* overflow state */
  703 :         OVF00 = 0;                      /* OVF00 clear */
  704 :                 
  705 : 
  706 :         /* Free-running counter and two capture registers */
  707 :         tm01_pulse0_cur0 = (unsigned long)CR011;
  708 :         tm01_pulse0_cur1 = (unsigned long)CR001;
  709 : 
  710 :         if(tm01_pulse_ovf){                     /*overflow generated */
  711 :                 if(tm01_pulse0_cur0 < tm01_pulse0_cur1){



/*
78K/0 Series C Compiler V3.60 Preprocess List                                                           Date: 9 Oct 2005 Page:  14
*/

  712 :                         tm01_pulse0_pos = tm01_pulse0_cur1 - tm01_pulse0_old0;
  713 :                         tm01_pulse0_neg = (0x10000 + tm01_pulse0_cur0) - tm01_pulse0_cur1;
  714 :                 }
  715 :                 else{
  716 :                         tm01_pulse0_pos = (0x10000 + tm01_pulse0_cur1) - tm01_pulse0_old0;
  717 :                         tm01_pulse0_neg = tm01_pulse0_cur0 - tm01_pulse0_cur1;
  718 :                 }
  719 :         }
  720 :         else{
  721 :                 tm01_pulse0_pos = tm01_pulse0_cur1 - tm01_pulse0_old0;
  722 :                 tm01_pulse0_neg = tm01_pulse0_cur0 - tm01_pulse0_cur1;
  723 :         }
  724 :         tm01_pulse0_old0 = tm01_pulse0_cur0;
  725 : 
  726 : 
  727 :         /* TODO */
  728 : }
  729 : 
  730 : 
  731 : 
  732 : 
  733 : 
  734 : 
  735 : 
  736 : 
  737 : 


/*
 Target chip : uPD78F0547_80
 Device file : V2.00 
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -