Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Simple LED Blink Demo for EFM32GG_STK3700
  4. * @version 5.4.0
  5. *******************************************************************************
  6. * # License
  7. * <b>Copyright 2015 Silicon Labs, Inc. http://www.silabs.com</b>
  8. *******************************************************************************
  9. *
  10. * This file is licensed under the Silabs License Agreement. See the file
  11. * "Silabs_License_Agreement.txt" for details. Before using this software for
  12. * any purpose, you must agree to the terms of that agreement.
  13. *
  14. ******************************************************************************/
  15. #include <stdio.h>
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include "em_device.h"
  19. #include "em_chip.h"
  20. #include "em_cmu.h"
  21. #include "em_emu.h"
  22. #include "bsp.h"
  23. #include "bsp_trace.h"
  24. #include "em_adc.h"
  25.  
  26. #define adcFreq 16000000
  27.  
  28.  
  29. #define BUTTON_PORT gpioPortD
  30. #define BUTTON_PIN 7
  31. #define STATUS 200
  32. #define BUZZER_PORT gpioPortD
  33. #define BUZZER_PIN 6
  34.  
  35.  
  36.  
  37. volatile uint32_t msTicks; /* counts 1ms timeTicks */
  38.  
  39. void Delay(uint32_t dlyTicks);
  40.  
  41. /***************************************************************************//**
  42. * @brief SysTick_Handler
  43. * Interrupt Service Routine for system tick counter
  44. ******************************************************************************/
  45. void SysTick_Handler(void)
  46. {
  47. msTicks++; /* increment counter necessary in Delay()*/
  48. }
  49.  
  50. /***************************************************************************//**
  51. * @brief Delays number of msTick Systicks (typically 1 ms)
  52. * @param dlyTicks Number of ticks to delay
  53. ******************************************************************************/
  54. void Delay(uint32_t dlyTicks)
  55. {
  56. uint32_t curTicks;
  57.  
  58. curTicks = msTicks;
  59. while ((msTicks - curTicks) < dlyTicks) ;
  60. }
  61.  
  62. /***************************************************************************//**
  63. * @brief Main function
  64. ******************************************************************************/
  65. int main(void)
  66. {
  67. /* Chip errata */
  68. CHIP_Init();
  69.  
  70. /* If first word of user data page is non-zero, enable Energy Profiler trace */
  71. BSP_TraceProfilerSetup();
  72.  
  73. /* Setup SysTick Timer for 1 msec interrupts */
  74. if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
  75. while (1) ;
  76. }
  77.  
  78. GPIO_PinModeSet(gpioPortD, 1, gpioModePushPull, 0);
  79. GPIO_PinModeSet(gpioPortD, 2, gpioModePushPull, 1);
  80. GPIO_PinModeSet(BUTTON_PORT, BUTTON_PIN, gpioModeInput, 0);
  81. GPIO_PinModeSet(BUZZER_PORT, BUZZER_PIN, gpioModePushPull, 0);
  82. puts("Hello world!");
  83.  
  84. // /* Initialize LED driver */
  85. // BSP_LedsInit();
  86. // BSP_LedSet(0);
  87. //
  88. // /* Infinite blink loop */
  89. while (1) {
  90. // BSP_LedToggle(0);
  91. // BSP_LedToggle(1);
  92. bool live_button_state = GPIO_PinInGet(BUTTON_PORT, BUTTON_PIN);
  93.  
  94. if(live_button_state == 1) {
  95. GPIO_PinModeSet(BUZZER_PORT, BUZZER_PIN, gpioModePushPull, 1);
  96. GPIO_PinModeSet(gpioPortE, 2, gpioModePushPull, 1);
  97. Delay(2000);
  98. }
  99. else {
  100. GPIO_PinModeSet(BUZZER_PORT, BUZZER_PIN, gpioModePushPull, 0);
  101. GPIO_PinModeSet(gpioPortE, 2, gpioModePushPull, 0);
  102. }
  103. Delay(300);
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement