Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*================================= VANJSKI PREKIDI =================================*/
- /* Includes */
- #include <stddef.h>
- #include "stm32f10x.h"
- #include "stm32f10x_rcc.h"
- #include "stm32f10x_gpio.h"
- #include "stm32f10x_exti.h"
- int main(void) {
- GPIO_InitTypeDef GPIO_InitStruct;
- EXTI_InitTypeDef EXTI_InitStruct;
- NVIC_InitTypeDef NVIC_InitStruct;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //jer se portovi GPIOA i GPIOB nalaze na busu APB2
- //Konfiguriranje PB0 kao izlazni (crvena ledica)
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_SET);
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- //Konfiguriranje PA0 kao ulazni (tipkalo)
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- //Konfiguriranje PA0 za koristenje vanjskog prekida
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
- EXTI_StructInit(&EXTI_InitStruct);
- EXTI_InitStruct.EXTI_Line = EXTI_Line0;
- EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStruct.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStruct);
- //Konfiguriranje NVIC
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //odabir grupe
- NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStruct.NVIC_IRQChannelSubPriority = 5;
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStruct);
- while(1) {
- }
- }
- //ISR za PB0
- void EXTI0_IRQHandler(void) {
- static uint32_t brojac = 0;
- if(brojac%2 == 0) {
- GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_RESET);
- }
- else {
- GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_SET);
- }
- brojac++;
- EXTI_ClearITPendingBit(EXTI_Line0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement