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

📄 bl78k0_kx2_time.c

📁 NEC upd78f0300的自编程序样例
💻 C
字号:
//==============================================================================
// PROJECT      = Bootloader
// MODULE       = bl78k0_kx2_time.c
// SHORT DESC.  = time control module
// DEVICE       = 78K0/Kx2
// VERSION      = 1.0
// DATE         = 05.12.2006
// LAST CHANGE  =
// =============================================================================
// By:          NEC Electronics (Europe) GmbH
//              Arcadiastrasse 10
//              D-40472 Duesseldorf
// =============================================================================



#include "io78f0547_80.h"
#include <intrinsics.h>
#include "bl78k0_kx2_user.h"
#include "bl78k0_kx2_time.h"





//*****************************************************************************
// globale variable
//*****************************************************************************
__saddr u08 overflow_counter = 0;         // overflow counter
__saddr u08 def_overflow_fact = 0;        // defined overflow count boundary



//*****************************************************************************
// Function:    init_timer_50ms
// Parameter:   void
// Return:      void
// Description: Init Timer50 as interval timer for 50ms interval
//*****************************************************************************
void init_timer_50ms(void){
  TMC50 = 0x00;	            // initialize Timer50

  #if CLOCK_FREQUENCY == 20
    TCL50 = 0x07;	    // set input clock to fxp(20 MHz) / 2^13 = 2441 Hz
    CR50  = 0x7A;           // set interval time to 50 ms at 20MHz
  #elif CLOCK_FREQUENCY == 12
    TCL50 = 0x07;	    // set input clock to fxp(12 MHz) / 2^13 = 1465 Hz
    CR50  = 0x49;           // set interval time to 50 ms at 12MHz
  #else
    #error ERROR: Frequency not supported! Change const. CLOCK_FREQUENCY!
  #endif


}




//*****************************************************************************
// Function:    initTimeoutDetect
// Parameter:   u16:
//                  timer_factor: this is a overflow factor
//                  Example:  timer_factor = 5
//                            timer is init. for 2ms interval
//                            5 x 2ms = 10ms
//                            Check with isTimeout() whether timeout occured.
// Return:      void
// Description: With this function you can define the waiting time and
//              start the timer.
//*****************************************************************************

__callt void initTimeoutDetect(u08 timer_factor)
{
  TCE50 = 0;	                          // stop and reset Timer50
  TMIF50 = 0;                             // reset interrupt request
  def_overflow_fact = timer_factor;       // set overflow count
  overflow_counter = 0;                   // reset overflow counter
  TCE50 = 1;		                  // start Timer start timer
}



//*****************************************************************************
// Function:    resetTimeoutDetect
// Parameter:   None
// Return:      void
// Description: Reset timeout detection(see also initTimeoutDetect() )
//*****************************************************************************
__callt void resetTimeoutDetect(void)
{
  TCE50 = 0;	                          // stop and reset Timer50
  TMIF50 = 0;                             // reset interrupt request
  overflow_counter = 0;                   // reset overflow counter
}



//*****************************************************************************
// Function:    isTimeout
// Parameter:   None
// Return:      u08
//              1:  timeout is occured
//              0:  no timeout
// Description: With this function you get the timeout status
//              see also initTimeoutDetect()
//*****************************************************************************

__callt u08 isTimeout(void)
{
  if(TMIF50)                              // is timer irq?
  {
    overflow_counter += 1;                // increment overflow counter
    TMIF50 = 0;                           // reset interrupt request
    if(overflow_counter == def_overflow_fact)     // is overflow ?
    {
      return 1;                           // overflow!
    }
  }
  return 0;                               // no overflow
}



//*****************************************************************************
// Function:    setTimerIntervall_50ms
// Parameter:   None
// Return:      void
// Description: Init timer for 50ms interval.
//*****************************************************************************
__callt void setTimerIntervall_50ms(void)
{
  TCE50 = 0;	                        // stop and reset Timer50
  #if CLOCK_FREQUENCY == 20
    CR50  = 0x7A;                       // set interval time to 50 ms at 20MHz
  #elif CLOCK_FREQUENCY == 12
    CR50  = 0x49;                       // set interval time to 50 ms at 12MHz
  #else
    #error ERROR: Frequency not supported! Change const. CLOCK_FREQUENCY!
  #endif

}


//*****************************************************************************
// Function:    setTimerIntervall_2ms
// Parameter:   None
// Return:      void
// Description: Init timer for 2ms interval.
//*****************************************************************************
__callt void setTimerIntervall_2ms(void)
{
  TCE50 = 0;	                          // stop and reset Timer50
  TMIF50 = 0;                             // reset interrupt request

  #if CLOCK_FREQUENCY == 20
    CR50  = 0x04;                         // set interval time to 2 ms at 20MHz
  #elif CLOCK_FREQUENCY == 12
    CR50  = 0x03;                         // set interval time to 2 ms at 12MHz
  #else
    #error ERROR: Frequency not supported! Change const. CLOCK_FREQUENCY!
  #endif
}

⌨️ 快捷键说明

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