Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include "stm32f10x.h"
  2.  
  3. typedef enum {FALSE = 0, TRUE = !FALSE} bool;
  4. void GPIO_Config(void);
  5. void NVIC_Config(void);
  6. int main(void)
  7. {
  8. //deklaracja zmiennych
  9. volatile unsigned long int i;
  10. unsigned int pozWlaczLED=0x0100;
  11. unsigned int stanGPIOB;
  12. bool kierunekLewo;
  13. //konfiguracja systemu
  14. GPIO_Config();
  15. NVIC_Config();
  16. //wylaczanie diod 1-8 (porty 8-15)
  17. GPIO_ResetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
  18. //pobranie aktualnego stanu calego portu B
  19. stanGPIOB=GPIO_ReadOutputData(GPIOB);
  20. //wyzerowanie bitow odpowiedzialnych za LEDy
  21. stanGPIOB=stanGPIOB&0x00FF;
  22. //zapisanie nowego stanu portow
  23. while (1) {
  24. GPIO_Write(GPIOB, pozWlaczLED | stanGPIOB);
  25. if (pozWlaczLED<0x8000) { //jesli pozycja jest mniejsza niz pozycja diody 8
  26. pozWlaczLED=pozWlaczLED<<1; //przesun pozycje o jeden w lewo
  27. } else {
  28. pozWlaczLED=0x0100; // jesli byla wlaczona dioda 8, ustaw pozycje 1
  29. }
  30. for(i=0;i<0x250000ul; i++); // czekanie okolo 0.25s przy 72MHz
  31. };
  32. return 0;
  33. }
  34. void NVIC_Config(void)
  35. //Konfigurowanie kontrolera przerwan NVIC
  36. {
  37. }
  38. void GPIO_Config(void)
  39. //konfigurowanie portow GPIO
  40. {
  41. GPIO_InitTypeDef GPIO_InitStructure; //struktura opisujaca konfiguracje
  42. //wlacz taktowanie portu GPIO B
  43. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  44. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  45. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  46. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  47. GPIO_Init(GPIOB, &GPIO_InitStructure);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement