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"
- int licznik1 = 0;
- int licznik2 = 0;
- void TIM3_IRQHandler(void) {
- if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) {
- if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11)) {
- licznik1++;
- }
- else {
- licznik1--;
- if(licznik1 > 0) {
- GPIO_SetBits(GPIOD, GPIO_Pin_12);
- for(int i = 0; i < 1000; i++);
- }
- if(licznik1 == 0) {
- GPIO_ResetBits(GPIOD, GPIO_Pin_12);
- for(int i = 0; i < 1000; i++);
- }
- }
- // if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12)) {
- // licznik2++;
- // }
- // else {
- // licznik2--;
- // if(licznik2 > 0) {
- // GPIO_SetBits(GPIOD, GPIO_Pin_13);
- // for(int i = 0; i < 1000; i++);
- // }
- // if(licznik2 == 0) {
- // GPIO_ResetBits(GPIOD, GPIO_Pin_13);
- // for(int i = 0; i < 1000; i++);
- // }
- // }
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
- }
- }
- int main(void) {
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); // LEDs
- GPIO_InitTypeDef GPIO_InitDef;
- GPIO_InitDef.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13;
- GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
- GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOD, &GPIO_InitDef);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); // buttons
- GPIO_InitTypeDef GPIO_BUTTONS;
- GPIO_BUTTONS.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
- GPIO_BUTTONS.GPIO_Mode = GPIO_Mode_IN;
- GPIO_BUTTONS.GPIO_OType = GPIO_OType_PP;
- GPIO_BUTTONS.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_BUTTONS.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOB, &GPIO_BUTTONS);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); // timer 3
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_TimeBaseStructure.TIM_Period = 999;
- 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);
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
- TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
- GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13);
- for(;;) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement