Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. unsigned int buftime;
  3. unsigned int waittime;
  4. int delay;
  5. int check;
  6. float timer;
  7. void SystemInit() {
  8. //enable clocking
  9. RCC->AHB1ENR|= 0x00000008; //for Port D (RCC_AHB1ENR) led
  10.  
  11. RCC->AHB1ENR|= 0x00000001; //for Port A (RCC_AHB1ENR) Button
  12.  
  13. //setup direction for PD12 (GPIOx_MODER)
  14. GPIOD->MODER|= 0x55000000; // output of port D
  15. GPIOA->MODER|= 0x00000000; // input of port A pin 0
  16.  
  17.  
  18. }
  19. int wait(unsigned int ms); // just delay
  20. //#define delay your_number_of_ms
  21. unsigned long GlobalTime;
  22. #define MAXGLOBALTIME 0x10000000
  23.  
  24. void Input()
  25. {
  26. int inp=0;
  27. while (1)
  28. {
  29. if (inp==0)
  30. {
  31. buftime=2000000;
  32. waittime=2000000;
  33. delay=100;
  34. check=0;
  35. return;
  36. }
  37. }
  38. }
  39. void Output()
  40. {
  41. return;
  42. }
  43. void GreatWork()
  44. {
  45. if (( GPIOA->IDR & 0x00000001) == 0)
  46. {
  47. if (check==1)
  48. {
  49. waittime=buftime;
  50. check=0;
  51. buftime=400000;
  52. }
  53.  
  54. GPIOD->ODR|= 0x00003000;
  55. wait(waittime*(delay/100));
  56. GPIOD->ODR &= ~0x00003000;
  57. wait(waittime);
  58. GPIOD->ODR|= 0x0000C000;
  59. wait(waittime*(delay/100));
  60. GPIOD->ODR &= ~0x0000C000;
  61. wait(waittime);
  62. }
  63. if (( GPIOA->IDR & 0x00000001) == 1)
  64. {
  65. check=1;
  66. buftime=buftime+100000;
  67.  
  68. GPIOD->ODR|= 0x00003000;
  69. wait(waittime);
  70. GPIOD->ODR &= ~0x00003000;
  71. wait(waittime*(delay/100));
  72. GPIOD->ODR|= 0x0000C000;
  73. wait(waittime);
  74. GPIOD->ODR &= ~0x0000C000;
  75. wait(waittime*(delay/100));
  76. }
  77. }
  78.  
  79.  
  80.  
  81.  
  82. int main () {
  83.  
  84. while (1)
  85. {
  86.  
  87. }
  88. }
  89.  
  90. void * const Tasks[ ] __attribute__((at(0x08001000))) = {
  91. Input,
  92. Output,
  93. GreatWork,
  94. 0
  95. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement