Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #define SW1 (*((volatile unsigned long *)0x40025040))
  2. #define SW2 (*((volatile unsigned long *)0x40025004))
  3.  
  4. int count;
  5. uint32_t button_state1;
  6. uint32_t button_state2;
  7.  
  8. uint32_t pushbuttons_1(void)
  9. {
  10. //Return the state of the buttons
  11. return SW1;
  12. }
  13.  
  14. uint32_t pushbuttons_2(void)
  15. {
  16. //Return the state of the buttons
  17. return SW2;
  18. }
  19.  
  20. void SysTick_Init(void)
  21. {
  22. button_state1=0;
  23. button_state2=0;
  24. count = 0;
  25. //Initialize Systick with interrupts every 1 ms
  26. NVIC_ST_CTRL_R = 0; // disable SysTick during setup
  27. NVIC_ST_RELOAD_R = 16000 - 1; // set reload value n = 16000
  28. NVIC_ST_CURRENT_R = 0; // Reset counter value
  29. NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R&0x00FFFFFF) | 0x40000000; // priority 2
  30. NVIC_ST_CTRL_R = 0x00000007; // enable SysTick with interrupts
  31. }
  32.  
  33. void SysTick_Handler(void)
  34. {
  35. if((count % 50) == 0)
  36. {
  37. button_state1 = pushbuttons_1();
  38. button_state2 = pushbuttons_2();
  39. if(button_state1 == 0)
  40. {
  41. if((count % 250) == 0)
  42. {
  43. GPIO_PORTF_DATA_R ^= 0x02; // toggle red LED
  44. }
  45. }
  46. if(button_state2 == 0)
  47. {
  48. if((count % 500) == 0)
  49. {
  50. GPIO_PORTF_DATA_R ^= 0x02; // toggle red LED
  51. }
  52. if((count % 2000) == 0)
  53. {
  54. GPIO_PORTF_DATA_R ^= 0x04; // toggle blue LED
  55. }
  56. }
  57. if((button_state1 == 0) && (button_state2 == 0))
  58. {
  59. if((count % 5000) == 0)
  60. {
  61. GPIO_PORTF_DATA_R ^= 0x08; // toggle green LED
  62. }
  63. if((count % 250) == 0)
  64. {
  65. GPIO_PORTF_DATA_R ^= 0x02; // toggle red LED
  66. }
  67. if((count % 1000) == 0)
  68. {
  69. GPIO_PORTF_DATA_R ^= 0x04; // toggle blue LED
  70. }
  71. }
  72. }
  73.  
  74. count = count + 1;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement