Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************//**
- * @file
- * @brief Simple LED Blink Demo for EFM32GG_STK3700
- * @version 5.4.0
- *******************************************************************************
- * # License
- * <b>Copyright 2015 Silicon Labs, Inc. http://www.silabs.com</b>
- *******************************************************************************
- *
- * This file is licensed under the Silabs License Agreement. See the file
- * "Silabs_License_Agreement.txt" for details. Before using this software for
- * any purpose, you must agree to the terms of that agreement.
- *
- ******************************************************************************/
- #include <stdio.h>
- #include <stdint.h>
- #include <stdbool.h>
- #include "em_device.h"
- #include "em_chip.h"
- #include "em_cmu.h"
- #include "em_emu.h"
- #include "bsp.h"
- #include "bsp_trace.h"
- #include "em_adc.h"
- #define adcFreq 16000000
- #define BUTTON_PORT gpioPortD
- #define BUTTON_PIN 7
- #define STATUS 200
- #define BUZZER_PORT gpioPortD
- #define BUZZER_PIN 6
- volatile uint32_t msTicks; /* counts 1ms timeTicks */
- void Delay(uint32_t dlyTicks);
- /***************************************************************************//**
- * @brief SysTick_Handler
- * Interrupt Service Routine for system tick counter
- ******************************************************************************/
- void SysTick_Handler(void)
- {
- msTicks++; /* increment counter necessary in Delay()*/
- }
- /***************************************************************************//**
- * @brief Delays number of msTick Systicks (typically 1 ms)
- * @param dlyTicks Number of ticks to delay
- ******************************************************************************/
- void Delay(uint32_t dlyTicks)
- {
- uint32_t curTicks;
- curTicks = msTicks;
- while ((msTicks - curTicks) < dlyTicks) ;
- }
- /***************************************************************************//**
- * @brief Main function
- ******************************************************************************/
- int main(void)
- {
- /* Chip errata */
- CHIP_Init();
- /* If first word of user data page is non-zero, enable Energy Profiler trace */
- BSP_TraceProfilerSetup();
- /* Setup SysTick Timer for 1 msec interrupts */
- if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
- while (1) ;
- }
- GPIO_PinModeSet(gpioPortD, 1, gpioModePushPull, 0);
- GPIO_PinModeSet(gpioPortD, 2, gpioModePushPull, 1);
- GPIO_PinModeSet(BUTTON_PORT, BUTTON_PIN, gpioModeInput, 0);
- GPIO_PinModeSet(BUZZER_PORT, BUZZER_PIN, gpioModePushPull, 0);
- puts("Hello world!");
- // /* Initialize LED driver */
- // BSP_LedsInit();
- // BSP_LedSet(0);
- //
- // /* Infinite blink loop */
- while (1) {
- // BSP_LedToggle(0);
- // BSP_LedToggle(1);
- bool live_button_state = GPIO_PinInGet(BUTTON_PORT, BUTTON_PIN);
- if(live_button_state == 1) {
- GPIO_PinModeSet(BUZZER_PORT, BUZZER_PIN, gpioModePushPull, 1);
- GPIO_PinModeSet(gpioPortE, 2, gpioModePushPull, 1);
- Delay(2000);
- }
- else {
- GPIO_PinModeSet(BUZZER_PORT, BUZZER_PIN, gpioModePushPull, 0);
- GPIO_PinModeSet(gpioPortE, 2, gpioModePushPull, 0);
- }
- Delay(300);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement