Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- #include "stm32f10x.h"
- void TIM2_IRQHandler()
- {
- if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
- {
- TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
- if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_5))
- GPIO_ResetBits(GPIOA, GPIO_Pin_5);
- else
- GPIO_SetBits(GPIOA, GPIO_Pin_5);
- // zapal wszystkie diody
- GPIO_SetBits(GPIOC, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);
- }
- if (TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET)
- {
- TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
- GPIO_ResetBits(GPIOC, GPIO_Pin_0);
- }
- if (TIM_GetITStatus(TIM2, TIM_IT_CC2) == SET)
- {
- TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
- GPIO_ResetBits(GPIOC, GPIO_Pin_1);
- }
- if (TIM_GetITStatus(TIM2, TIM_IT_CC3) == SET)
- {
- TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);
- GPIO_ResetBits(GPIOC, GPIO_Pin_2);
- }
- if (TIM_GetITStatus(TIM2, TIM_IT_CC4) == SET)
- {
- TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);
- GPIO_ResetBits(GPIOC, GPIO_Pin_3);
- }
- }
- int main(void)
- {
- GPIO_InitTypeDef gpio;
- TIM_TimeBaseInitTypeDef tim;
- NVIC_InitTypeDef nvic;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
- GPIO_StructInit(&gpio);
- gpio.GPIO_Pin = GPIO_Pin_5;
- gpio.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOA, &gpio);
- gpio.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
- GPIO_Init(GPIOC, &gpio);
- TIM_TimeBaseStructInit(&tim);
- tim.TIM_CounterMode = TIM_CounterMode_Up;
- tim.TIM_Prescaler = 64000 - 1;
- tim.TIM_Period = 1000 - 1;
- TIM_TimeBaseInit(TIM2, &tim);
- TIM_ITConfig(TIM2, TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4, ENABLE);
- TIM_Cmd(TIM2, ENABLE);
- TIM_SetCompare1(TIM2, 100);
- TIM_SetCompare2(TIM2, 200);
- TIM_SetCompare3(TIM2, 500);
- TIM_SetCompare4(TIM2, 900);
- nvic.NVIC_IRQChannel = TIM2_IRQn;
- nvic.NVIC_IRQChannelPreemptionPriority = 0;
- nvic.NVIC_IRQChannelSubPriority = 0;
- nvic.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&nvic);
- while (1) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement