📄 gpt1.c
字号:
//****************************************************************************
// @Module General Purpose Timer Unit (GPT1)
// @Filename GPT1.C
// @Project PEC.dav
//----------------------------------------------------------------------------
// @Controller Infineon XC164CM-8F40
//
// @Compiler Keil
//
// @Codegenerator 0.2
//
// @Description This file contains functions that use the GPT1 module.
//
//----------------------------------------------------------------------------
// @Date 2006-8-15 15:54:58
//
//****************************************************************************
// 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)
unsigned int PEC_Source[10] = {0,1,2,3,4,5,6,7,8,9};
unsigned int PEC_Des[10];
// 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 2006-8-15
//
//****************************************************************************
// 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 8
/// -----------------------------------------------------------------------
/// Configuration of the GPT1 Core Timer 3:
/// -----------------------------------------------------------------------
/// - timer 3 works in timer mode
/// - external up/down control is disabled
/// - prescaler factor is 1024
/// - up/down control bit is reset
/// - alternate output function T3OUT (P3.3) is disabled
/// - timer 3 output toggle latch (T3OTL) is set to 0
/// - timer 3 run bit is reset
GPT12E_T3CON = 0x0007; // load timer 3 control register
GPT12E_T3 = 0x676A; // load timer 3 register
/// -----------------------------------------------------------------------
/// Configuration of the GPT1 Auxiliary Timer 2:
/// -----------------------------------------------------------------------
/// - timer 2 works in timer mode
/// - external up/down control is disabled
/// - prescaler factor is 1024
/// - up/down control bit is reset
GPT12E_T2CON = 0x0007; // load timer 2 control register
GPT12E_T2 = 0x676A; // load timer 2 register
/// -----------------------------------------------------------------------
/// Configuration of the GPT1 Auxiliary Timer 4:
/// -----------------------------------------------------------------------
/// - timer 4 works in timer mode
/// - external up/down control is disabled
/// - prescaler factor is 8
/// - 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
/// -----------------------------------------------------------------------
/// Configuration of the used GPT1 Port Pins:
/// -----------------------------------------------------------------------
/// -----------------------------------------------------------------------
/// Configuration of the used GPT1 Interrupts:
/// -----------------------------------------------------------------------
/// timer 2 service request node configuration:
/// - timer 2 interrupt priority level (ILVL) = 12
/// - timer 2 interrupt group level (GLVL) = 1
/// - timer 2 group priority extension (GPX) = 0
GPT12E_T2IC = 0x0071;
/// Use PEC channel 1 for GPT1 T2 INT:
/// - decrement counter
/// - increment destination and source pointers
/// - transfer a word
/// - service End of PEC interrrupt by a EOP interrupt node is enabled
/// - End of PEC intrrupt request is enabled
PECC1 = 0x560A; // load PECC1 control register
//// - SOURCE-POINTER for PECC channel 1 is set because it is selected for
//// user defined
SRCP1 = _sof_(0x0000); //set source pointer
//// - DESTINATION-POINTER for PECC channel 1 is set because it is selected
//// for user defined
DSTP1 = _sof_(0x0000); //set destination pointer
// USER CODE BEGIN (GPT1_Function,3)
// manual define the source and destination address
SRCP1 = _sof_(PEC_Source); //set source pointer
DSTP1 = _sof_(PEC_Des); //set destination pointer
// USER CODE END
GPT12E_T2CON_T2R = 1; // set timer 2 run bit
} // End of function GPT1_vInit
//****************************************************************************
// @Function void GPT1_viTmr2(void)
//
//----------------------------------------------------------------------------
// @Description This is the interrupt service routine for the GPT1 timer 2.
// It is called up in the case of over or underflow of the
// timer 2 register.
// If the incremental interface mode is selected and the
// interrupt for this mode is not disabled it is called up if
// count edge or count direction was detected.
//
// Please note that you have to add application specific code
// to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2006-8-15
//
//****************************************************************************
// USER CODE BEGIN (Tmr2,1)
// USER CODE END
void GPT1_viTmr2(void) interrupt T2INT
{
// USER CODE BEGIN (Tmr2,2)
// USER CODE END
// USER CODE BEGIN (Tmr2,5)
// USER CODE END
} // End of function GPT1_viTmr2
// USER CODE BEGIN (GPT1_General,10)
// USER CODE END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -