Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- #include "stm32f4xx_gpio.h"
- #include "stm32f4xx_rcc.h"
- #include "stm32f4xx_tim.h"
- #include "misc.h"
- int i=0; //Counter
- void SetSysClockToHSE(void)
- {
- ErrorStatus HSEStartUpStatus;
- RCC_DeInit();
- RCC_HSEConfig( RCC_HSE_ON);
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
- if (HSEStartUpStatus == SUCCESS)
- {
- RCC_HCLKConfig( RCC_SYSCLK_Div1);
- RCC_PCLK2Config( RCC_HCLK_Div1);
- RCC_PCLK1Config(RCC_HCLK_Div1);
- RCC_SYSCLKConfig( RCC_SYSCLKSource_HSE);
- while (RCC_GetSYSCLKSource() != 0x04)
- {
- }
- }
- else
- while (1)
- {
- }
- }
- }
- void TIM4_IRQHandler(void)
- {
- TIM6->SR &= ~TIM_SR_UIF; //Сброс прерывания
- if(i==0) GPIO_SetBits(GPIOD, GPIO_Pin_12); // «1» на PD12
- else if(i==1) GPIO_SetBits(GPIOD, GPIO_Pin_13); // «1» на PD13
- else if(i==2) GPIO_SetBits(GPIOD, GPIO_Pin_14); // «1» на PD14
- else if(i==3) GPIO_SetBits(GPIOD, GPIO_Pin_15); // «1» на PD15
- else if(i==4)GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); //Сброс всего на «0»
- i++; //Счетчик +1
- if(i==5) i=0; //Если i=5, счетчик=0
- }
- int main(void)
- {
- SetSysClockToHSE();
- /* Initialize LED which connected to PC13 */
- GPIO_InitTypeDef GPIO_InitStructure;
- // Enable PORTC Clock
- RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
- /* Configure the GPIO_LED pin */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12| GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15; //Выбор нужного вывода;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- GPIO_ResetBits(GPIOC, GPIO_Pin_13); // Set C13 to Low level ("0")
- GPIO_ResetBits(GPIOC, GPIO_Pin_14);
- GPIO_ResetBits(GPIOC, GPIO_Pin_15);
- GPIO_ResetBits(GPIOC, GPIO_Pin_12);
- // TIMER4
- TIM_TimeBaseInitTypeDef TIMER_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
- TIM_TimeBaseStructInit(&TIMER_InitStructure);
- TIMER_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIMER_InitStructure.TIM_Prescaler = 8000;
- TIMER_InitStructure.TIM_Period = 500;
- TIM_TimeBaseInit(TIM4, &TIMER_InitStructure);
- TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
- TIM_Cmd(TIM4, ENABLE);
- /* NVIC Configuration */
- /* Enable the TIM4_IRQn Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- while(1)
- {
- }
Add Comment
Please, Sign In to add comment