Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.57 KB | None | 0 0
  1. #include "stm32f4xx_conf.h"
  2. #include "stm32f4xx_gpio.h"
  3. #include "stm32f4xx_rcc.h"
  4. #include "stm32f4xx_tim.h"
  5. #define button GPIOA, GPIO_Pin_0
  6.  
  7. //Dodane moduly: RCC, GPIO, EXTI, TIM, MISC, SYSCFG
  8. int licznik=0;
  9.  
  10. GPIO_InitTypeDef GPIO_InitStructure;
  11.  
  12. //Diody
  13. void LED(){
  14.     //dodanie sygnalow zegara do portow
  15.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  16.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  17.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  18.  
  19.     // Konfigurowanie diod
  20.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15; //12-15 diody
  21.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //tryb dzialania: IN/OUT-we/wy binarne, AF- funkcja alternatywna, AN-we analogowe
  22.     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //typ wyjscia: PP-komplementarne/OD-otwarty dren
  23.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //max predkosc (2,25,50,100)
  24.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //podciaganie wyprowadzenia: NOPULL- brak, UP- do napiecia zasilania, DOWN- do masy
  25.     GPIO_Init(GPIOD, &GPIO_InitStructure); //(nazwa portu, struktura)
  26. }
  27.  
  28. void green_on(){
  29.     GPIO_SetBits(GPIOD, GPIO_Pin_12);
  30. }
  31. void green_off(){
  32.     GPIO_ResetBits(GPIOD, GPIO_Pin_12);
  33. }
  34. void orange_on(){
  35.     GPIO_SetBits(GPIOD, GPIO_Pin_13);
  36. }
  37. void orange_off(){
  38.     GPIO_ResetBits(GPIOD, GPIO_Pin_13);
  39. }
  40. void red_on(){
  41.     GPIO_SetBits(GPIOD, GPIO_Pin_14);
  42. }
  43. void red_off(){
  44.     GPIO_ResetBits(GPIOD, GPIO_Pin_14);
  45. }
  46. void blue_on(){
  47.     GPIO_SetBits(GPIOD, GPIO_Pin_15);
  48. }
  49. void blue_off(){
  50.     GPIO_ResetBits(GPIOD, GPIO_Pin_15);
  51. }
  52. void all_on(){
  53.     green_on();
  54.     orange_on();
  55.     red_on();
  56.     blue_on();
  57. }
  58. void all_off(){
  59.     green_off();
  60.     orange_off();
  61.     red_off();
  62.     blue_off();
  63. }
  64.  
  65. //Przycisk
  66. void Button(){
  67.     //dodanie sygnalow zegara do portow
  68.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  69.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  70.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  71.  
  72.         // Konfigurowanie przycisku
  73.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  74.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //tryb dzialania: IN/OUT-we/wy binarne, AF- funkcja alternatywna, AN-we analogowe
  75.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //typ wyjscia: PP-komplementarne/OD-otwarty dren
  76.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //max predkosc (2,25,50,100)
  77.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //podciaganie wyprowadzenia: NOPULL- brak, UP- do napiecia zasilania, DOWN- do masy
  78.         GPIO_Init(GPIOA, &GPIO_InitStructure); //(nazwa portu, struktura)
  79. }
  80.  
  81. void button_green_on(){
  82.         if(GPIO_ReadInputDataBit(button == 1)) green_on();
  83. }
  84. void button_green_off(){
  85.         if(GPIO_ReadInputDataBit(button == 0)) green_off();
  86. }
  87. void button_blue_on(){
  88.         if(GPIO_ReadInputDataBit(button == 1)) blue_on();
  89. }
  90. void button_blue_off(){
  91.         if(GPIO_ReadInputDataBit(button == 0)) blue_off();
  92. }
  93. void button_red_on(){
  94.     if(GPIO_ReadInputDataBit(button == 1)) red_on();
  95. }
  96. void button_red_off(){
  97.     if(GPIO_ReadInputDataBit(button == 0)) red_off();
  98. }
  99. void button_orange_on(){
  100.         if(GPIO_ReadInputDataBit(button == 1)) orange_on();
  101. }
  102. void button_orange_off(){
  103.         if(GPIO_ReadInputDataBit(button == 0)) orange_off();
  104. }
  105. void button_all_on(){    
  106.     if(GPIO_ReadInputDataBit(button == 1)) all_on();
  107. }
  108. void button_all_off(){
  109.         if(GPIO_ReadInputDataBit(button == 0)) all_off();
  110. }
  111. //Delay
  112. void Delay(__IO uint32_t nCount){
  113.   while(nCount--){
  114.   }
  115. }
  116.  
  117. int main(void)
  118. {
  119.     SystemInit();
  120.     Button();
  121.     LED();
  122.     while(1)
  123.     {
  124.         button_all_on();
  125.         button_all_off();
  126.     }
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement