Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ****************************************************************************
- * @file main.c
- * @author Ac6
- * @version V1.0
- * @date 01-December-2013
- * @brief Default main function.
- ****************************************************************************
- */
- #include "stm32f4xx.h"
- #include "stm32f4_discovery.h"
- unsigned int i = 0;
- unsigned int j = 1;
- unsigned int k =0;
- int main(void)
- {
- // ustawienie trybu pracy priorytetów przerwań
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitTypeDef NVIC_InitStructure;
- // numer przerwania
- NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
- // priorytet główny
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x10;
- // subpriorytet
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
- // uruchom dany kanał
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // zapisz wypełnioną strukturę do rejestrów
- NVIC_Init(&NVIC_InitStructure);
- NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
- // priorytet główny
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
- // subpriorytet
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
- // uruchom dany kanał
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // zapisz wypełnioną strukturę do rejestrów
- NVIC_Init(&NVIC_InitStructure);
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- /* Time base configuration */
- TIM_TimeBaseStructure.TIM_Period = 9999;
- TIM_TimeBaseStructure.TIM_Prescaler = 8399;
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
- TIM_Cmd(TIM3, ENABLE);
- // wyczyszczenie przerwania od timera 3 (wystąpiło przy konfiguracji timera)
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
- // zezwolenie na przerwania od przepełnienia dla timera 3
- TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
- /* Time base configuration */
- TIM_TimeBaseStructure.TIM_Period = 9999;
- TIM_TimeBaseStructure.TIM_Prescaler = 2099;
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
- TIM_Cmd(TIM4, ENABLE);
- // wyczyszczenie przerwania od timera 3 (wystąpiło przy konfiguracji timera)
- TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
- // zezwolenie na przerwania od przepełnienia dla timera 3
- TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
- /* Time base configuration */
- TIM_TimeBaseStructure.TIM_Period = 41999;
- TIM_TimeBaseStructure.TIM_Prescaler = 1999;
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
- TIM_Cmd(TIM2, ENABLE);
- // wyczyszczenie przerwania od timera 3 (wystąpiło przy konfiguracji timera)
- TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
- // zezwolenie na przerwania od przepełnienia dla timera 3
- TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
- GPIO_SetBits(GPIOA,GPIO_Pin_0);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- for(;;)
- {
- }
- }
- void TIM3_IRQHandler(void)
- {
- if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
- {
- switch(i)
- {
- case 0:
- {
- i++;
- GPIO_ResetBits(GPIOA,GPIO_Pin_1);
- GPIO_ResetBits(GPIOA,GPIO_Pin_2);
- GPIO_ResetBits(GPIOA,GPIO_Pin_3);
- GPIO_ResetBits(GPIOA,GPIO_Pin_4);
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA, GPIO_Pin_7);
- break;
- }
- case 1:
- {
- i++;
- GPIO_SetBits(GPIOA,GPIO_Pin_1);
- GPIO_SetBits(GPIOA,GPIO_Pin_2);
- GPIO_SetBits(GPIOA,GPIO_Pin_3);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- break;
- }
- case 2:
- {
- i++;
- GPIO_ResetBits(GPIOA,GPIO_Pin_1);
- GPIO_ResetBits(GPIOA,GPIO_Pin_3);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- break;
- }
- case 3:
- {
- i++;
- GPIO_SetBits(GPIOA,GPIO_Pin_1);
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- break;
- }
- case 4:
- {
- i++;
- GPIO_SetBits(GPIOA,GPIO_Pin_3);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_4);
- GPIO_ResetBits(GPIOA,GPIO_Pin_2);
- break;
- }
- case 5:
- {
- i++;
- GPIO_ResetBits(GPIOA,GPIO_Pin_3);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_4);
- break;
- }
- case 6:
- {
- i++;
- GPIO_ResetBits(GPIOA,GPIO_Pin_1);
- break;
- }
- case 7:
- {
- i++;
- GPIO_SetBits(GPIOA,GPIO_Pin_1);
- GPIO_SetBits(GPIOA,GPIO_Pin_2);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_4);
- break;
- }
- case 8:
- {
- i++;
- GPIO_ResetBits(GPIOA,GPIO_Pin_1);
- GPIO_ResetBits(GPIOA,GPIO_Pin_2);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- break;
- }
- case 9:
- {
- i = 0;
- GPIO_SetBits(GPIOA,GPIO_Pin_1);
- break;
- }
- }
- // wyzerowanie flagi wyzwolonego przerwania
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
- }
- }
- void TIM4_IRQHandler(void)
- {
- if(TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
- {
- switch(j)
- {
- case 1:
- {
- GPIO_ToggleBits(GPIOE,GPIO_Pin_13);
- j++;
- GPIO_ToggleBits(GPIOA,GPIO_Pin_0);
- break;
- }
- case 2:
- {
- GPIO_ToggleBits(GPIOA,GPIO_Pin_0);
- j++;
- GPIO_ToggleBits(GPIOE,GPIO_Pin_11);
- break;
- }
- case 3:
- {
- GPIO_ToggleBits(GPIOE,GPIO_Pin_11);
- j++;
- GPIO_ToggleBits(GPIOE,GPIO_Pin_12);
- break;
- }
- case 4:
- {
- GPIO_ToggleBits(GPIOE,GPIO_Pin_12);
- j =0;
- GPIO_ToggleBits(GPIOE,GPIO_Pin_13);
- break;
- }
- }
- TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement