/**
******************************************************************************
* File : main.c
* Version: V1.2.4
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "at32f4xx.h"
#include "at32_board.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitType GPIO_InitStructure;
TMR_TimerBaseInitType TMR_TMReBaseStructure = {0};
TMR_OCInitType TMR_OCInitStructure = {0};
NVIC_InitType NVIC_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void AT32_NVIC_Init(void);
void AT32_TMR3_Init(void);
/* Private functions ---------------------------------------------------------*/
int main(void){
AT32_NVIC_Init();
RCC_Configuration();
Delay_init();
AT32_LEDn_Init(LED3);
AT32_LEDn_OFF(LED3);
AT32_TMR3_Init();
TMR_INTConfig(TMR3, TMR_INT_CC1, ENABLE);
TMR_Cmd(TMR3, ENABLE);/* TMR3 enable counter */
while (1){
Delay_ms(100);
}
}
void RCC_Configuration(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_TMR1, ENABLE);
}
void AT32_NVIC_Init(void){
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = TMR3_GLOBAL_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/* TMR3 base configuration */
void AT32_TMR3_Init(void){
TMR_TimeBaseStructInit(&TMR_TMReBaseStructure);
TMR_TMReBaseStructure.TMR_Period = SystemCoreClock/10000-1;
TMR_TMReBaseStructure.TMR_DIV = 10000-1;
TMR_TMReBaseStructure.TMR_ClockDivision = 0;
TMR_TMReBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;
TMR_TimeBaseInit(TMR3, &TMR_TMReBaseStructure);
}
void TMR3_GLOBAL_IRQHandler(void){
AT32_LEDn_Toggle(LED3);
TMR_ClearITPendingBit(TMR3, TMR_INT_Overflow | TMR_INT_CC1 | TMR_INT_CC2 | TMR_INT_CC3 | TMR_INT_CC4 | TMR_INT_Trigger);
}
|