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

📄 gpt1.c

📁 Infineon单片机XC164CMADC模数转换模块和定时器中断例程
💻 C
字号:
//****************************************************************************
// @Module        General Purpose Timer Unit (GPT1)
// @Filename      GPT1.C
// @Project       164.dav
//----------------------------------------------------------------------------
// @Controller    Infineon XC164CM-4F40
//
// @Compiler      Keil
//
// @Codegenerator 1.1
//
// @Description   This file contains functions that use the GPT1 module.
//
//----------------------------------------------------------------------------
// @Date          2007-5-4 22:13:47
//
//****************************************************************************

// USER CODE BEGIN (GPT1_General,1)

// USER CODE END



//****************************************************************************
// @Project Includes
//****************************************************************************

#include "MAIN.H"

// USER CODE BEGIN (GPT1_General,2)

// USER CODE END


//****************************************************************************
// @Macros
//****************************************************************************

// USER CODE BEGIN (GPT1_General,3)

// USER CODE END


//****************************************************************************
// @Defines
//****************************************************************************

// USER CODE BEGIN (GPT1_General,4)

// USER CODE END


//****************************************************************************
// @Typedefs
//****************************************************************************

// USER CODE BEGIN (GPT1_General,5)

// USER CODE END


//****************************************************************************
// @Imported Global Variables
//****************************************************************************

// USER CODE BEGIN (GPT1_General,6)

// USER CODE END


//****************************************************************************
// @Global Variables
//****************************************************************************

// USER CODE BEGIN (GPT1_General,7)

// USER CODE END


//****************************************************************************
// @External Prototypes
//****************************************************************************

// USER CODE BEGIN (GPT1_General,8)

// USER CODE END


//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************

// USER CODE BEGIN (GPT1_General,9)

// USER CODE END


//****************************************************************************
// @Function      void GPT1_vInit(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the initialization function of the GPT1 function 
//                library. It is assumed that the SFRs used by this library 
//                are in reset state. 
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2007-5-4
//
//****************************************************************************

// USER CODE BEGIN (Init,1)

// USER CODE END

void GPT1_vInit(void)
{
  // USER CODE BEGIN (Init,2)

  // USER CODE END

  ///  -----------------------------------------------------------------------
  ///  Configuration of Timer Block Prescaler 1:
  ///  -----------------------------------------------------------------------
  ///  - prescaler for timer block 1 is 4


  ///  -----------------------------------------------------------------------
  ///  Configuration of the GPT1 Core Timer 3:
  ///  -----------------------------------------------------------------------
  ///  - timer 3 works in timer mode
  ///  - external up/down control is disabled
  ///  - prescaler factor is 4
  ///  - up/down control bit is reset
  ///  - alternate output function T3OUT (P3.3) is disabled
  ///  - timer 3 output toggle latch (T3OTL) is set to 0

  GPT12E_T3CON   =  0x0800;      // load timer 3 control register
  GPT12E_T3      =  0x0000;      // load timer 3 register
GPT12E_T3IC=0X0010;
GPT12E_T3=0xfc18;
GPT12E_T3IC_IE=1;
  ///  -----------------------------------------------------------------------
  ///  Configuration of the GPT1 Auxiliary Timer 2:
  ///  -----------------------------------------------------------------------
  ///  - timer 2 works in timer mode
  ///  - external up/down control is disabled
  ///  - prescaler factor is 4
  ///  - up/down control bit is reset
  ///  - timer 2 run bit is reset

  GPT12E_T2CON   =  0x0000;      // load timer 2 control register
  GPT12E_T2      =  0x0000;      // load timer 2 register
GPT12E_T2IC=0X0008;
GPT12E_T2=0xfc18;
GPT12E_T2IC_IE=0;
  ///  -----------------------------------------------------------------------
  ///  Configuration of the GPT1 Auxiliary Timer 4:
  ///  -----------------------------------------------------------------------
  ///  - timer 4 works in timer mode
  ///  - external up/down control is disabled
  ///  - prescaler factor is 4
  ///  - up/down control bit is reset
  ///  - timer 4 run bit is reset

  GPT12E_T4CON   =  0x0000;      // load timer 4 control register
  GPT12E_T4      =  0x0000;      // load timer 4 register
GPT12E_T4IC=0X0004;
GPT12E_T4=0xfc18;
GPT12E_T4IC_IE=0;
  ///  -----------------------------------------------------------------------
  ///  Configuration of the used GPT1 Port Pins:
  ///  -----------------------------------------------------------------------


  ///  -----------------------------------------------------------------------
  ///  Configuration of the used GPT1 Interrupts:
  ///  -----------------------------------------------------------------------

  // USER CODE BEGIN (GPT1_Function,3)

  // USER CODE END

  GPT12E_T3CON_T3R  =  1;        // set timer 3 run bit
  GPT12E_T2CON_T2R  =  0;        // set timer 3 run bit
  GPT12E_T4CON_T4R  =  0;        // set timer 3 run bit

} //  End of function GPT1_vInit


//****************************************************************************
// @Function      ubyte GPT1_ubCheckRotation(ubyte TimerNr) 
//
//----------------------------------------------------------------------------
// @Description   This function returns the status of the bit TxCHDIR of 
//                selected TimerNr and resets the status bit. If return value 
//                is 1 change of count direction was detected.
//                
//                Note:
//                Use this function only for TimerNr wich works in 
//                incremental interface mode (rotation detection mode) AND 
//                the interrupt for this mode is disabled.
//                
//                The following definitions are available for TimerNr:
//                GPT1_TIMER_2
//                GPT1_TIMER_3
//                GPT1_TIMER_4
//
//----------------------------------------------------------------------------
// @Returnvalue   1 if count direction was changed, else 0
//
//----------------------------------------------------------------------------
// @Parameters    TimerNr: 
//                The name of the timer to be used
//
//----------------------------------------------------------------------------
// @Date          2007-5-4
//
//****************************************************************************

// USER CODE BEGIN (CheckRotation,1)

// USER CODE END

ubyte GPT1_ubCheckRotation(ubyte TimerNr)
{
  ubyte ubReturnValue;

  ubReturnValue = 0;
  if(TimerNr == 2 && GPT12E_T2CON_T2CHDIR == 1)
  {
    ubReturnValue = 1;
    GPT12E_T2CON_T2CHDIR = 0;
  }

  if(TimerNr == 3 && GPT12E_T3CON_T3CHDIR == 1)
  {
    ubReturnValue = 1;
    GPT12E_T3CON_T3CHDIR = 0;
  }

  if(TimerNr == 4 && GPT12E_T4CON_T4CHDIR == 1)
  {
    ubReturnValue = 1;
    GPT12E_T4CON_T4CHDIR = 0;
  }


  return(ubReturnValue);

} //  End of function GPT1_ubCheckRotation


//****************************************************************************
// @Function      ubyte GPT1_ubCheckEdge(ubyte TimerNr) 
//
//----------------------------------------------------------------------------
// @Description   This function returns the status of the bit TxEDGE of 
//                selected TimerNr and resets the status bit. If return value 
//                is 1 successful edge was detected.
//                
//                Note:
//                Use this function only for TimerNr wich works in 
//                incremental interface mode (edge detection mode) AND the 
//                interrupt for this mode is disabled.
//                
//                The following definitions are available for TimerNr:
//                GPT1_TIMER_2
//                GPT1_TIMER_3
//                GPT1_TIMER_4
//
//----------------------------------------------------------------------------
// @Returnvalue   1 if successful edge was detected, else 0
//
//----------------------------------------------------------------------------
// @Parameters    TimerNr: 
//                The name of the timer to be used
//
//----------------------------------------------------------------------------
// @Date          2007-5-4
//
//****************************************************************************

// USER CODE BEGIN (CheckEdge,1)

// USER CODE END

ubyte GPT1_ubCheckEdge(ubyte TimerNr)
{
  ubyte ubReturnValue;

  ubReturnValue = 0;
  if(TimerNr == 2 && GPT12E_T2CON_T2EDGE == 1)
  {
    ubReturnValue = 1;
    GPT12E_T2CON_T2EDGE = 0;
  }

  if(TimerNr == 3 && GPT12E_T3CON_T3EDGE == 1)
  {
    ubReturnValue = 1;
    GPT12E_T3CON_T3EDGE = 0;
  }

  if(TimerNr == 4 && GPT12E_T4CON_T4EDGE == 1)
  {
    ubReturnValue = 1;
    GPT12E_T4CON_T4EDGE = 0;
  }


  return(ubReturnValue);

} //  End of function GPT1_ubCheckEdge




// USER CODE BEGIN (GPT1_General,10)

// USER CODE END

⌨️ 快捷键说明

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