Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- #include "stm32f4xx_rcc.h"
- #include "stm32f4xx_gpio.h"
- #include "misc.h"
- #include "stm32f4xx_exti.h"
- #include "stm32f4xx_syscfg.h"
- #define PS2_CLOCK GPIO_Pin_5
- #define PS2_DATA GPIO_Pin_4
- #define PS2_PORT GPIOC
- static uint8_t znak = 0x00;
- volatile static uint8_t liczba_bitow = 11;
- void GPIO_config();
- void InterruptConfig();
- void GPIO_config(){
- GPIO_InitTypeDef gpio_sett; //struktura do ustawien
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //wlaczenie taktowania zegara dla wszystkich pinow PA
- GPIO_StructInit(&gpio_sett);
- gpio_sett.GPIO_Pin = PS2_DATA | PS2_CLOCK;
- gpio_sett.GPIO_Mode = GPIO_Mode_IN; //jako wejscie
- gpio_sett.GPIO_PuPd = GPIO_PuPd_NOPULL;
- gpio_sett.GPIO_Mode = GPIO_Speed_100MHz; //speed na 100
- GPIO_Init(PS2_PORT,&gpio_sett);
- }
- void InterruptConfig(){
- EXTI_InitTypeDef exti_sett;
- NVIC_InitTypeDef nvic_sett;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource5);
- EXTI_StructInit(&exti_sett);
- exti_sett.EXTI_Mode = EXTI_Mode_Interrupt; //jako przerwanie
- exti_sett.EXTI_Trigger = EXTI_Trigger_Falling; //na zbocze opadajace
- exti_sett.EXTI_Line = EXTI_Line5; //linia 5 bo pin PC5
- exti_sett.EXTI_LineCmd = ENABLE;
- EXTI_Init(&exti_sett);
- EXTI_ClearITPendingBit(EXTI9_5_IRQn);
- nvic_sett.NVIC_IRQChannel = EXTI9_5_IRQn; //wywolywane przez EXTI
- nvic_sett.NVIC_IRQChannelPreemptionPriority = 0;
- nvic_sett.NVIC_IRQChannelSubPriority = 0;
- nvic_sett.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&nvic_sett);
- NVIC_ClearPendingIRQ(EXTI9_5_IRQn);
- }
- void EXTI9_5_IRQHandler(){
- uint8_t pomiar;
- if(EXTI_GetITStatus(EXTI_Line5) != RESET)
- {
- pomiar = GPIO_ReadInputDataBit(PS2_PORT, PS2_DATA);
- if (liczba_bitow==11)
- {
- znak = 0x00;
- if (0 == pomiar)
- {
- --liczba_bitow;
- }
- } else
- if (liczba_bitow<11 && liczba_bitow>2)
- {
- znak = (znak >> 1);
- if (0 != pomiar)
- znak = znak + 0x80;
- --liczba_bitow;
- } else
- {
- if (--liczba_bitow == 0)
- {
- liczba_bitow = 11;
- }
- }
- EXTI_ClearITPendingBit(EXTI_Line5);
- }
- }
- int main(void)
- {
- GPIO_config();
- InterruptConfig();
- while(1){}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement