1.选择端口PC7 配置功能和模式
2.可配置 对比值 调节时间
3.贴上源码
#include "MG32x02z__Common_DRV.H"
#include "MG32x02z_DRV.H"
//*********************************************************************************************
void ChipInit(void);
//*********************************************************************************************
void Sample_RTC_Init (void)
{
uint32_t RTC_CNT;
/*=== 2. Configure RTC clock ===*/
UnProtectModuleReg(RTCprotect); // Unprotect RTC module
RTC_CLK_Select(RTC_CK_LS); // RTC clock source = CK_LS
RTC_PreDivider_Select(RTC_PDIV_4096); // PDIV output = RTC clock / 4096
RTC_Divider_Select(RTC_DIV_8); // DIV output = (RTC clock / 4096) / 8
RTC_OutputSignal_Select(RTC_PC); // RTC output = DIV otuput frequency
/*=== 3. Set RTC timer value ===*/
RTC_RCR_Mode_Select(RTC_RCR_MOD_ForceReload); // RTC switch to reload mode
RTC_SetReladReg(0); // Set reload data
RTC_TriggerStamp_SW(); // Trigger reload data update to RTC timer
while(RTC_GetSingleFlagStatus(RTC_RCRF) == DRV_UnHappened); // Waiting reload complete
RTC_ClearFlag(RTC_ALLF); // Clear flag
/*=== 4. Update ALM value ===*/
if(RTC_GetAlarmState() == DRV_True) // When alarm function enable
{
RTC_Alarm_Cmd(DISABLE); // Disable alarm function
while(RTC_GetSingleFlagStatus(RTC_RCRF) == DRV_UnHappened); // Waiting alarm function disable
RTC_ClearFlag(RTC_RCRF); // Clear flag RCRF
}
RTC_SetAlarmCompareValue(10); // Set alarm compare value
RTC_Alarm_Cmd(ENABLE); // Enable Alarm function
/*=== 5. Enable RTC module ===*/
RTC_Cmd (ENABLE); // Enable RTC module
/*=== 6. Wait Alarm ===*/
while(RTC_GetSingleFlagStatus(RTC_ALMF) == DRV_UnHappened); // Wait Alarm happened
RTC_ClearFlag(RTC_ALMF); // Clear Alarm flag
/*=== 7. Get RTC timer value ===*/
RTC_RCR_Mode_Select(RTC_RCR_MOD_DirectlyCapture); // RTC switch to delay capture mode
RTC_ClearFlag(RTC_PCF | RTC_RCRF); // Clear flag PCF and RCRF
RTC_TriggerStamp_SW(); // Trigger RTC capture timer data
while(RTC_GetSingleFlagStatus(RTC_RCRF) == DRV_UnHappened); // Waiting capture complete
RTC_CNT = RTC_GetCaptureReg(); // Get capture register data
if(RTC_CNT > 0)
{
}
RTC_Cmd(DISABLE); // Disable RTC module
ProtectModuleReg(RTCprotect); // Protect RTC module
}
//*********************************************************************************************
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_PushPull_O; //Ñ¡ÔñIOģʽ pp0 // 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 = 2; //Ñ¡ÔñGPIOģʽ
GPIO_PinMode_Config(PINC(7),&PINX_InitStruct); //PA0 ÅäÖÃ
}
//*********************************************************************************************
int main()
{
ChipInit();
Sample_GPIO_RWInit();
while(1)
{
Sample_RTC_Init ();
}
}
|