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.
- ******************************************************************************
- */
- // pod pin Pin_6 podpinamy jeden wyświetlacza np.1
- // pod piny Pin_7,Pin_8,Pin_9,Pin_10 podpinamy jeden segment segmenty następująco a-7, b-8,f-9,g-10
- // pod piny Pin_11,Pin_12,Pin_13,Pin_14 podpinamy przyciski
- #include "stm32f4xx.h"
- #include "stm32f4_discovery.h"
- int a=0;
- int b=0;
- int f=0;
- int g=0;
- void TIM3_IRQHandler(void){
- if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET){
- // miejsce na kod wywolywany w momencie wystapienia przerwania
- if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_11) == 0){
- if(a==0) a=1;
- else a=0;
- for(int i=0;i<10000;i++);
- }
- if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_12) == 0){
- if(b==0) b=1;
- else b=0;
- for(int i=0;i<10000;i++);
- }
- if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_13) == 0){
- if(f==0) f=1;
- else f=0;
- for(int i=0;i<10000;i++);
- }
- if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_14) == 0){
- if(g==0) g=1;
- else g=0;
- for(int i=0;i<10000;i++);
- }
- if(a==1){
- GPIO_ToggleBits(GPIOE,GPIO_Pin_7 );
- }
- else if(b==1){
- GPIO_ToggleBits(GPIOE,GPIO_Pin_8);
- }
- else if(f==1){
- GPIO_ToggleBits(GPIOE,GPIO_Pin_9);
- }
- else if(g==1){
- GPIO_ToggleBits(GPIOE,GPIO_Pin_10);
- }
- // wyzerowanie flagi wyzwolonego przerwania
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
- }
- }
- int main(void)
- {
- //timer
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_TimeBaseStructure.TIM_Period = 5249;
- TIM_TimeBaseStructure.TIM_Prescaler = 3999;
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
- TIM_Cmd(TIM3, ENABLE);
- //ustawienie trybu pracy priorytetów przerwan
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitTypeDef NVIC_InitStructure;
- //numer przerwania
- NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
- //priorytet glowny
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
- //subpriorytet
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
- //uruchom dany kanal
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- //zapisz wypelniona strukture do rejestrow
- NVIC_Init(&NVIC_InitStructure);
- // wyczyszczenie przerwania od timera 3 (wystapilo przy konfiguracji timera)
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
- // zezwolenie na przerwania od przepelnienia dla timera 3
- TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin =
- GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- GPIO_InitTypeDef GPIO_buttonIn;
- GPIO_buttonIn.GPIO_Pin =
- GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
- GPIO_buttonIn.GPIO_Mode = GPIO_Mode_IN;
- GPIO_buttonIn.GPIO_OType = GPIO_OType_PP;
- GPIO_buttonIn.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_buttonIn.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Init(GPIOE, &GPIO_buttonIn);
- GPIO_SetBits(GPIOE,GPIO_Pin_6);
- GPIO_SetBits(GPIOE,GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);
- for(;;){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement