Advertisement
daskalot

Untitled

Nov 16th, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f4_discovery.h"
  3.  
  4. /**
  5. * @brief Main program
  6. * @param None
  7. * @retval None
  8. */
  9.  
  10. int main(void){
  11. //Start the device clock
  12. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  13. //Init the Device Structure
  14. GPIO_InitTypeDef leds;
  15. leds.GPIO_Pin = 0xF000;
  16. leds.GPIO_Mode = GPIO_Mode_OUT;
  17. leds.GPIO_Speed = GPIO_Speed_2MHz;
  18. leds.GPIO_OType = GPIO_OType_PP;
  19. leds.GPIO_PuPd = GPIO_PuPd_NOPULL;
  20. GPIO_Init(GPIOD, &leds);
  21.  
  22. //Start the device(= button) clock
  23. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  24. //Init the device(=button) structure
  25. GPIO_InitTypeDef button;
  26. button.GPIO_Pin = GPIO_Pin_0;
  27. button.GPIO_Mode = GPIO_Mode_IN;
  28. button.GPIO_Speed = GPIO_Speed_2MHz;
  29. button.GPIO_OType = GPIO_OType_PP;
  30. button.GPIO_PuPd = GPIO_PuPd_NOPULL;
  31. GPIO_Init(GPIOD, &button);
  32.  
  33. //Delay util
  34. volatile uint32_t d = 0x01000000;
  35. //Temper calc
  36. volatile uint16_t calc = (uint16_t)1;
  37. while (1){
  38. if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)){
  39. GPIO_ResetBits(GPIOD, 0xF000);
  40. GPIO_SetBits(GPIOD, GPIO_Pin_12*calc);
  41. while(d--);
  42. d = 0x01000000;
  43. calc *= 2;
  44.  
  45. }
  46. if(calc>9) calc = 1;
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement