Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- #include "stm32f4xx_conf.h"
- //#include "stm32f4xx_it.h"
- static void LED_Init (void);
- static void TIM_Config(void);
- static void EnableTimer3Interrupt(void);
- TIM_TimeBaseInitTypeDef timerInitStructure;
- void TIM3_IRQHandler(void)
- {
- if(TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
- {
- TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
- GPIO_ToggleBits(GPIOG, GPIO_Pin_14);
- }
- }
- int main(void){
- TIM_Config();
- EnableTimer3Interrupt();
- LED_Init();
- GPIO_SetBits(GPIOG, GPIO_Pin_13);
- while(1){
- //GPIO_SetBits(GPIOG, GPIO_Pin_13);
- }
- }
- /*--------------------------------------------------*/
- void LED_Init (void) {
- GPIO_InitTypeDef GPIO_InitStructure; // LED Port Info
- // Enable the port clock
- RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOG, ENABLE);
- // Prepare the port info
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14; // Line 12
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // As Output
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // Push-pull
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; // At 100MHz
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // Without pull-up-down
- // Initialize the port
- GPIO_Init (GPIOG, &GPIO_InitStructure); }
- /*-------------------------------------------*/
- void EnableTimer3Interrupt(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- /* Enable the TIM3 global Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- /*--------------------------------------------------*/
- void TIM_Config(void)
- {
- /* TIM2 clock enable */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
- /* Time base configuration */
- timerInitStructure.TIM_Prescaler = 40000;
- timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
- timerInitStructure.TIM_Period =500;
- timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- timerInitStructure.TIM_RepetitionCounter = 0;
- TIM_TimeBaseInit(TIM3, &timerInitStructure);
- /* TIM Interrupts enable */
- TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
- /* TIM2 enable counter */
- TIM_Cmd(TIM3, ENABLE);
- }
- //end file
Advertisement
Add Comment
Please, Sign In to add comment