定时器 可编程计数器 自动停止模式功能。
//*************************************************************************
//*************************************************************************
#include "MG32x02z__Common_DRV.H"
#include "MG32x02z_DRV.H"
void ChipInit(void);
#define Simple_CKO_Period 12000
#define Simple_CKO_Number 1000
//*************************************************************************
void Sample_TM16_AutoStop(void)
{
TM_TimeBaseInitTypeDef TM_TimeBase_InitStruct;
//===Set CSC init====
//MG32x02z_CSC_Init.h(Configuration Wizard)
//Select CK_HS source = CK_IHRCO
//Select IHRCO = 12M
//Select CK_MAIN Source = CK_HS
//Configure PLL->Select APB Prescaler = CK_MAIN/1
//Configure Peripheral On Mode Clock->TM16 = Enable
//Configure Peripheral On Mode Clock->Port B = Enable
//==Set GPIO init
//TM16_CKO pin config:
//MG32x02z_GPIO_Init.h(Configuration Wizard)->Use GPIOB->PB2
//GPIO port initial is 0xFFFF
//PB2 mode is PPO
//PB2 function TM16_CKO
TM_TimeBaseStruct_Init(&TM_TimeBase_InitStruct);
TM_TimeBase_InitStruct.TM_Period = Simple_CKO_Number - 1;
TM_TimeBase_InitStruct.TM_Prescaler = Simple_CKO_Period - 1;
TM_TimeBase_InitStruct.TM_CounterMode = Cascade;
TM_TimeBase_Init(TM16, &TM_TimeBase_InitStruct);
TM_ClearFlag(TM16, TMx_TOF);
TM_ClockOutSource_Select(TM16, PrescalerCKO);
TM_ClockOut_Cmd(TM16, ENABLE);
TM_CKOOutputState_Init(TM16, CLR);
TM_AutoStop_Cmd(TM16, ENABLE);
TM_Timer_Cmd(TM16, ENABLE);
return;
}
//***************************************************************************************************
void Sample_GPIO_RWInit(void)
{
uint16_t ReadData;
PIN_InitTypeDef PINX_InitStruct;
//===Set CSC init====
//MG32x02z_CSC_Init.h(Configuration Wizard)
//Select CK_HS source = CK_IHRCO ÄÚ²¿Ê±ÖÓ
//Select IHRCO = 11.0592M
//Select CK_MAIN Source = CK_HS
//Configure PLL->Select APB Prescaler = CK_MAIN/1
//Configure Peripheral On Mode Clock->Port A = Enable
//===GPIO Port Initial====
PINX_InitStruct.PINX_Mode = PINX_Mode_OpenDrain_O; //Ñ¡ÔñIOģʽ // 1.QB: Quasi-Bidirection mode only for PC )
PINX_InitStruct.PINX_PUResistant = PINX_PUResistant_Enable; //ÄÚ²¿ÉÏÀ
PINX_InitStruct.PINX_Speed = PINX_Speed_Low; //ÉèÖÃËÙ¶È
PINX_InitStruct.PINX_OUTDrive = PINX_OUTDrive_Level0; //Êä³öÄÜÁ¦ÉèÖÃ
PINX_InitStruct.PINX_FilterDivider = PINX_FilterDivider_Bypass; //Ñ¡ÔñÊäÈëµÄÂ˲¨·ÖƵÆ÷
PINX_InitStruct.PINX_Inverse = PINX_Inverse_Disable; //ÊäÈëÐźÅÊÇ·ñ·´×ª
PINX_InitStruct.PINX_Alternate_Function = 5; //cko
GPIO_PinMode_Config(PINB(2),&PINX_InitStruct); //PA0 ÅäÖÃ
}
//*************************************************************************
int main()
{
ChipInit();
Sample_GPIO_RWInit();
Sample_TM16_AutoStop();
while(1)
{
}
}
//*************************************************************************
|