Beispiel #1
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();
  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize LED driver */
  BSP_LedsInit();
  /* Setting state of leds*/
  BSP_LedSet(0);
  BSP_LedSet(1);

  /* Initialize SLEEP driver, no calbacks are used */
  SLEEP_Init(NULL, NULL);
#if (configSLEEP_MODE < 3)
  /* do not let to sleep deeper than define */
  SLEEP_SleepBlockBegin((SLEEP_EnergyMode_t)(configSLEEP_MODE+1));
#endif

  /* Parameters value for taks*/
  static TaskParams_t parametersToTask1 = { pdMS_TO_TICKS(1000), 0 };
  static TaskParams_t parametersToTask2 = { pdMS_TO_TICKS(500), 1 };

  /*Create two task for blinking leds*/
  xTaskCreate( LedBlink, (const char *) "LedBlink1", STACK_SIZE_FOR_TASK, &parametersToTask1, TASK_PRIORITY, NULL);
  xTaskCreate( LedBlink, (const char *) "LedBlink2", STACK_SIZE_FOR_TASK, &parametersToTask2, TASK_PRIORITY, NULL);

  /*Start FreeRTOS Scheduler*/
  vTaskStartScheduler();

  return 0;
}
//
// Function Name: bootloadGpioInit
// Description:   This function selects the chip's GPIO configuration. These
//                settings are the minimum base configuration needed to
//                support the bootloader functionality. These settings can
//                be modified for custom applications as long as the base
//                settings are preserved.
// Parameters:    none
// Returns:       none
//
void bootloadGpioInit(void)
{
  halInternalEnableWatchDog();

  #ifndef NO_LED
    BSP_LedsInit();
  #endif
}
Beispiel #3
0
static void prvSetupHardware( void )
{
	/* Library initialisation routines. */
	CHIP_Init();
	BSP_TraceProfilerSetup();
	SLEEP_Init( NULL, NULL );
	BSP_LedsInit();

	SLEEP_SleepBlockBegin( configENERGY_MODE );
}
void LOS_EvbLedInit(void)
{

#ifdef EFM32PG1B200F256GM48
		/* Initialize LED driver */
	BSP_LedsInit();
	BSP_LedSet(0);
	BSP_LedClear(1);
#endif

	return ;
}
Beispiel #5
0
/***************************************************************************//**
 *                                BSPOS_Init()
 * @brief      Board Support Package Initialization.
 *
 * @param[in]  none
 * @exception  none
 * @return     none
 *
 ******************************************************************************/
void  BSPOS_Init (void)
{
    /* Initialize LEDs */
    BSP_LedsInit();

    /* Set external crystal oscillator */
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

    /* Enable module clocks */
    CMU_ClockEnable(cmuClock_GPIO, true);
    CMU_ClockEnable(cmuClock_HFPER, true);
}
Beispiel #6
0
/** \brief the main function of the project
 *  check current state and switch apps respectively
 * \param 
 * \param 
 * \return 
 *
 */     
int main(void)
{
    /* Chip errata */
    CHIP_Init();

    /* If first word of user data page is non-zero, enable eA Profiler trace */
    BSP_TraceProfilerSetup();

    ////////////////////////////////////////////////////////////////////////
    setupSWO();
    /* Initialize LED driver */
    BSP_LedsInit();
    initButtons();
    initClock();
    initActivity();
    initVariables();
    SegmentLCD_Init(false);  /* Enable LCD without voltage boost */

    state = main_screen;

    /* Infinite blink loop */
    while (1)
    {
        //NOTE maybe button A(change state) must be checked here
        if(screen_notification == true)    // don't update screen until user reaction
        {
            EMU_EnterEM2(true);
            button = NO_BUTTON;
        }
        else
        {
            switch (state)
            {
            case main_screen:
                mainScreenApp();
                break;
            case pomodoro_screen:
                pomodoroApp();
                break;
            case activity_screen:
                activityApp();
                break;
            case time_setup_screen:
                setupTimeApp();
                break;
            case alarm_setup_screen:
                setupAlarmApp();
                break;
            }
        }
    }
}
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  setupSWO();

  /* Enable HFXO */
  CMU_OscillatorEnable(cmuOsc_HFXO, true, true);

  /* Switch HFCLK to HFXO */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Turn off HFRCO */
  CMU_OscillatorEnable(cmuOsc_HFRCO, false, false);

  BSP_LedsInit();

  while (1)
  {
    /* Blink led three times, with a factor 1 million delay */
    blink_led(1000000, 3);

    /* Turn on LFRCO */
    CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);

    /* Select LFRCO */
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_LFRCO);

    /* Maximum prescaling for smalles frequency (64 Hz) */
    CMU_ClockDivSet(cmuClock_CORE, cmuClkDiv_512);

    /* Turn off HFXO */
    CMU_OscillatorEnable(cmuOsc_HFXO, false, false);

    /* Blink led three times, with a factor 1 delay */
    blink_led(1, 3);

    /* Turn on HFXO */
    CMU_OscillatorEnable(cmuOsc_HFXO, true, true);

    /* Select HFXO */
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

    /* No prescaling for maximum clock frequency (32 MHz) */
    CMU_ClockDivSet(cmuClock_CORE, cmuClkDiv_1);

    /* Turn off LFRCO */
    CMU_OscillatorEnable(cmuOsc_LFRCO, false, false);
  }
}
Beispiel #8
0
/**************************************************************************//**
 * @brief main - the entrypoint after reset.
 *****************************************************************************/
int main( void )
{
    CHIP_Init();
    /* If first word of user data page is non-zero, enable eA Profiler trace */
    BSP_TraceProfilerSetup();

    CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
    CMU_OscillatorEnable(cmuOsc_LFXO, true, false);

    /* Initialize LCD driver */
    SegmentLCD_Init(false);
    SegmentLCD_Write("usbcomp");
    SegmentLCD_Symbol(LCD_SYMBOL_GECKO, true);

    /* Initialize LED driver */
    BSP_LedsInit();

    /* Initialize SLEEP driver, no calbacks are used */
    SLEEP_Init(NULL, NULL);
#if (configSLEEP_MODE < 3)
    /* do not let to sleep deeper than define */
    SLEEP_SleepBlockBegin((SLEEP_EnergyMode_t)(configSLEEP_MODE + 1));
#endif

    /* Parameters value for taks*/
    static LedTaskParams_t parametersToTask1 = { 1000 / portTICK_RATE_MS, 0 };
    static LedTaskParams_t parametersToTask2 = { 500 / portTICK_RATE_MS, 1 };

    static AdcTaskParams_t parametersToAdc =
    {
        .adcChannelsMask = 0x32,
        .uPrsChannel = 5,
        .uSampleRate = 1,
        .uTimer = 3
    };

    /*Create two task for blinking leds*/
    xTaskCreate( UsbCDCTask, "UsbCDC", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL);
//   xTaskCreate( LedTask, (const char *) "LedBlink1", STACK_SIZE_FOR_TASK, &parametersToTask1, TASK_PRIORITY, NULL);
//   xTaskCreate( LedTask, (const char *) "LedBlink2", STACK_SIZE_FOR_TASK, &parametersToTask2, TASK_PRIORITY, NULL);
    xTaskCreate( vAdcTask, "ADC", STACK_SIZE_FOR_TASK, &parametersToAdc, TASK_PRIORITY + 1, NULL);
    xTaskCreate( vDacTask, "DAC", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL);
    xTaskCreate( vEchoTask, "echo", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL);

    NVIC_SetPriority(USB_IRQn, 7);
    NVIC_SetPriority(ADC0_IRQn, 7);
    vTaskStartScheduler();
}
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  setupSWO();

  BSP_LedsInit();

  /* Enable clock for GPIO module */
  CMU_ClockEnable(cmuClock_GPIO, true);

  /* Configure interrupt for Push Button 0 */
  GPIO_PinModeSet(PB0_PORT, PB0_PIN, gpioModeInput, 1);
#if defined(_EFM32_GIANT_FAMILY)
  NVIC_EnableIRQ(GPIO_ODD_IRQn);
#else
  NVIC_EnableIRQ(GPIO_EVEN_IRQn);
#endif
  GPIO_IntConfig(PB0_PORT, PB0_PIN, false, true, true);

  /* By turning on retention in EM4, the state of the GPIO pins
   * can be retained in all energy modes */
  GPIO->CTRL = GPIO_CTRL_EM4RET;

  /* Uncomment to drive LED in all energy modes */
  /* BSP_LedSet(0);*/

  while (1)
  {
    switch (STATE)
    {
    case EM0:
      break;
    case EM1:
      EMU_EnterEM1();
      break;
    case EM2:
      EMU_EnterEM2(true);
      break;
    case EM3:
      EMU_EnterEM3(true);
    case EM4:
      EMU_EnterEM4();
      break;
    }
  }
}
Beispiel #10
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize gpio */
  gpioSetup();

  /* Initialize LED driver */
  BSP_LedsInit();

  /* Infinite loop */
  while (1);
}
Beispiel #11
0
/**************************************************************************//**
 * @brief
 *   Main function is a CMSIS RTOS thread in itself
 *
 * @note
 *   This example uses threads, memory pool and message queue to demonstrate the
 *   usage of these CMSIS RTOS features. In this simple example, the same
 *   functionality could more easily be achieved by doing everything in the main
 *   loop.
 *****************************************************************************/
int main(void)
{
  int count = 0;

  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize LED driver */
  BSP_LedsInit();

  /* Initialize the LCD driver */
  SegmentLCD_Init(false);

  /* Initialize CMSIS RTOS structures */
  /* create memory pool */
  mpool = osPoolCreate(osPool(mpool));
  /* create msg queue */
  msgBox = osMessageCreate(osMessageQ(msgBox), NULL);
  /* create thread 1 */
  osThreadCreate(osThread(PrintLcdThread), NULL);

  /* Infinite loop */
  while (1)
  {
    count = (count+1)&0xF;
    BSP_LedsSet(count);

    /* Send message to PrintLcdThread */
    /* Allocate memory for the message */
    lcdText_t *mptr = osPoolAlloc(mpool);
    /* Set the message content */
    (*mptr)[0] = count>=10 ? '1' : '0';
    (*mptr)[1] = count%10 + '0';
    (*mptr)[2] = '\0';
    /* Send message */
    osMessagePut(msgBox, (uint32_t)mptr, osWaitForever);

    /* Wait now for half a second */
    osDelay(500);
  }
}
Beispiel #12
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  /* Initialize LED driver */
  BSP_LedsInit();

  /* Infinite blink loop */
  while (1)
  {
    BSP_LedToggle(0);
    Delay(100);
  }
}
Beispiel #13
0
static void prvSetupHardware( void )
{
EMU_DCDCInit_TypeDef xDCDInit = EMU_DCDCINIT_STK_DEFAULT;
CMU_HFXOInit_TypeDef xHFXOInit = CMU_HFXOINIT_STK_DEFAULT;

	/* Chip errata */
	CHIP_Init();

	/* Init DCDC regulator and HFXO with kit specific parameters */
	EMU_DCDCInit( &xDCDInit );
	CMU_HFXOInit( &xHFXOInit );

	/* Switch HFCLK to HFXO and disable HFRCO */
	CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
	CMU_OscillatorEnable( cmuOsc_HFRCO, false, false );

	/* Initialize LED driver. */
	BSP_LedsInit();
	BSP_LedSet( 0 );
	BSP_LedClear( 1 );
}
Beispiel #14
0
int main( void ) 
{
	setupBSP();

	Delay_Init();
 
	setupMEM();
	setupFPGA();
	setupINT();

	setupCMU();

	setupPRS();

	setupDAC();
	setupDMA();
	setupADC();

	setupTIMER();

	Delay_Init();

	BSP_LedsInit();
	BSP_LedsSet(0);

	while(1) {

		//test_and_display();
		BSP_LedToggle(0);
		Delay(1000);
		BSP_LedsSet(0);
		Delay(500);

	}
	
}
/**************************************************************************//**
 * @brief RTC Setup
 * Produce an interrupt every second
 *****************************************************************************/
void rtc_setup(void)
{
  /* Starting LFXO and waiting until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, true);

  /* Routing the LFXO clock to the RTC */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
  CMU_ClockEnable(cmuClock_RTC, true);

  /* Enabling clock to the interface of the low energy modules */
  CMU_ClockEnable(cmuClock_CORELE, true);

  const RTC_Init_TypeDef rtcInit =
  {
    .enable   = true,
    .debugRun = false,
    .comp0Top = true,
  };

  RTC_Init(&rtcInit);

  /* Produce interrupt every second */
  RTC_CompareSet(0, 32768);

  /* Enable interrupt for compare register 0 */
  RTC_IntEnable(RTC_IFC_COMP0);

  /* Enabling interrupt from RTC */
  NVIC_EnableIRQ(RTC_IRQn);
}

/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  /* Enable code view */
  setupSWO();

  /* Configure peripherals */
  rtc_setup();

  BSP_LedsInit();

  while (1)
  {
    switch (STATE)
    {
    case EM0:
      break;
    case EM1:
      EMU_EnterEM1();
      break;
    case EM2:
      EMU_EnterEM2(true);
      break;
    }
  }
}
Beispiel #16
0
void halInternalInitLed(void)
{
  /* Initialize LEDs on-board */
  BSP_LedsInit();
}
Beispiel #17
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int toggleLED = 0;
  int cnt, x, y;
  bool movedown, moveright;

  /* Use 48MHZ HFXO as core clock frequency */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Initialize DK board register access */
  /* This demo currently only works in EBI mode */
  BSP_Init(BSP_INIT_DEFAULT);
  BSP_LedsInit();

  /* Setup SysTick Timer for 10 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000))
  {
    while (1) ;
  }

  /* Initialize the display module. */
  DISPLAY_Init();

  /* Retarget stdio to a text display. */
  if (RETARGET_TextDisplayInit() != TEXTDISPLAY_EMSTATUS_OK)
  {
    while (1) ;
  }

  /* Output text on Memory LCD */
  printf("Hello, EFM32 Zero Gecko world!");
  Delay(2000);

  /* Clear screen */
  printf("\f");

  cnt = x = y = 0;
  movedown = moveright = true;

  /* Update Memory LCD display forever */
  while (1)
  {
    printf("%d", cnt );

    if (movedown)
    {
      y++;
      printf( TEXTDISPLAY_ESC_SEQ_CURSOR_DOWN_ONE_LINE );
    }
    else
    {
      y--;
      printf( TEXTDISPLAY_ESC_SEQ_CURSOR_UP_ONE_LINE );
    }

    if (y >= TEXTDISPLAY_DEVICE_0_LINES-1)
      movedown=false;
    if (y == 0)
      movedown=true;
    
    if (moveright)
    {
      x++;
      if (cnt >= 10)
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
    } 
    else
    {
      x--;
      if (cnt > 10)
      {
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
      }
      else
      {
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
      }
    }

    if (x >= TEXTDISPLAY_DEVICE_0_COLUMNS-2)
      moveright=false;
    if (x == 0)
      moveright=true;

    /* Clear screen and reset counter when 100 is reached. */
    if (++cnt == 100)
    {
      printf("\f");
      cnt = x = y = 0;
      movedown = moveright = true;
    }

    /* Toggle led after each Memory LCD_displayUpdate iteration */
    if (toggleLED)
    {
      BSP_LedsSet(0x0000);
      toggleLED = 0;
    }
    else
    {
      BSP_LedsSet(0x000f);
      toggleLED = 1;
    }
    Delay(100);
  }
}
Beispiel #18
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int i;
  uint8_t data[7];
  SENSOR_DATA_TypeDef axis_converted_avg[33];
  char lcd_data[20];
  /* ADXL345 I2C driver config */
  ADXL345Handle.port = I2C1;
  ADXL345Handle.sclPort = ADXL345_I2C_SCL_PORT;
  ADXL345Handle.sclPin = ADXL345_I2C_SCL_PIN;
  ADXL345Handle.sdaPort = ADXL345_I2C_SDA_PORT;
  ADXL345Handle.sdaPin = ADXL345_I2C_SDA_PIN;
  ADXL345Handle.portLocation = ADXL345_I2C_PORT_LOC;
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Enable two leds to show we're alive */
  BSP_LedsInit();
  BSP_LedSet(0);
  BSP_LedSet(1);

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  /* Enable LCD without voltage boost */
  SegmentLCD_Init(false);
  /* Initialize I2C drivers */
  I2CSPM_Init(&ADXL345Handle);

	ADXL345_INIT(ADXL345Handle.port);
	SegmentLCD_Write("ADXL345");
	Delay(500);
	/* Read Device ID */
	SegmentLCD_Write("DEV_ID");
	Delay(500);
	ADXL345_Read_Reg(ADXL345Handle.port, DEVICEID_REG_ADDR,data,1);
	SegmentLCD_LowerHex(data[0]);
	Delay(500);
	/* Read FIFO CTL */
	SegmentLCD_Write("AXISDATA");
	Delay(500);
	/* Infinite loop with test pattern. */
   while(1)
   {
	   // axis_converted_avg.X =  0;
	   // axis_converted_avg.Y =  0;
	   // axis_converted_avg.Z =  0;
	   ADXL345_Read_Reg(ADXL345Handle.port, 0x30,data,1);
	   if(data[0]&0x02)
	   {
		   
		 ADXL345_READ_FIFO(axis_converted_avg);
		    // sprintf(lcd_data,"X:%d",(int)axis_converted_avg.X/i);
		    // SegmentLCD_Write(lcd_data);
			// Delay(500);
			// sprintf(lcd_data,"Y:%d",(int)axis_converted_avg.Y/i);
		    // SegmentLCD_Write(lcd_data);
			// Delay(500);
			// sprintf(lcd_data,"Z:%d",(int)axis_converted_avg.Z/i);
		    // SegmentLCD_Write(lcd_data);
			// Delay(500);  
		 for(i=0;i<33;i++)
		 {
			ADXL345_STEPCOUNT(axis_converted_avg[i]); 
		 }
		 

	   }
	  SegmentLCD_LowerNumber(STEP_COUNT);
	// SegmentLCD_LowerNumber(ADXL345_DATA_CONVERT(axis_data[0]));
	 Delay(500);        
	// SegmentLCD_LowerNumber(ADXL345_DATA_CONVERT(axis_data[1]));
	// Delay(500);          
	// SegmentLCD_LowerNumber(ADXL345_DATA_CONVERT(axis_data[2]));
	// Delay(500);      	
	// ADXL345_Read_Reg(ADXL345Handle.port, 0x1e,data,1);
	// SegmentLCD_LowerHex(data[0]);
	// Delay(500);   
	// ADXL345_Read_Reg(ADXL345Handle.port, 0x1f,data,1);
	// SegmentLCD_LowerHex(data[0]);
	// Delay(500);  
	// ADXL345_Read_Reg(ADXL345Handle.port, 0x20,data,1);
	// SegmentLCD_LowerHex(data[0]);
	// Delay(500);  

	// SegmentLCD_LowerHex(axis_data[1]<< 8 + axis_data[0]);
	// Delay(500);
	// SegmentLCD_LowerHex(axis_data[3]<< 8 + axis_data[2]);
	// Delay(500);
	// SegmentLCD_LowerHex(axis_data[5]<< 8 + axis_data[4]);
	// Delay(1000);
  }


}
Beispiel #19
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initial BSP led driver .  **/
  BSP_LedsInit();
  BSP_LedSet(0);
  BSP_LedClear(0);

  /* timer1 intial to generate wave. */
  enc_init();

  /* Initialize LCD controller without boost */
  SegmentLCD_Init(false);

  /* Disable all segments */
  SegmentLCD_AllOff();

  /* Copy contents of the userpage (flash) into the userData struct */
  //memcpy((void *) &userData, (void *) USERPAGE, sizeof(UserData_TypeDef));

  /* Special case for uninitialized data */
  if (userData.number > 10000)
    userData.number = 0;
  if (userData.numWrites == 0xFFFFFFFF)
    userData.numWrites = 0;

  /* Display the number */
  SegmentLCD_Number(userData.number);

  /* Setup GPIO interrupts. PB0 to increase number, PB1 to save to flash */
  gpioSetup();

  /* No save has occured yet */
  recentlySaved = false;

  /* Main loop - just scroll informative text describing the current state of
   * the system */
  while (1)
  {
	EM2Sleep(125);
#if 0
    switch (currentError)
    {
    case mscReturnInvalidAddr:
      ScrollText("     ERROR: INVALID ADDRESS      ");
      break;
    case mscReturnLocked:
      ScrollText("     ERROR: USER PAGE IS LOCKED      ");
      break;
    case mscReturnTimeOut:
      ScrollText("     ERROR: TIMEOUT OCCURED      ");
      break;
    case mscReturnUnaligned:
      ScrollText("     ERROR: UNALIGNED ACCESS     ");
    default:
      if (recentlySaved)
      {
        recentlySaved = false;
        SegmentLCD_Number(userData.numWrites);
        ScrollText("     SAVE NUMBER       ");
      }
      else
      {
        SegmentLCD_Number(userData.number);
        ScrollText("     PRESS PB0 TO INCREASE NUMBER. PB1 TO SAVE TO INTERNAL FLASH        ");
      }
      break;
    }
#endif
  }
}
Beispiel #20
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  char buffer[] = "AT";
  uint8_t delay_type = 0;

  /* Chip errata */
  CHIP_Init();

  /* initalize clocks */
  CMU->CTRL |= (1 << 14);                         // Set HF clock divider to /2 to keep core frequency <32MHz
  CMU->OSCENCMD |= 0x4;                           // Enable XTAL Oscillator
  while(! (CMU->STATUS & 0x8) );                  // Wait for XTAL osc to stabilize
  CMU->CMD = 0x2;                                 // Select HF XTAL osc as system clock source. 48MHz XTAL, but we divided the system clock by 2, therefore our HF clock should be 24MHz

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  usart_init();
  motor_init();

  usart_enable_rx_isr();

  BSP_LedsInit();
  BSP_LedSet(0);
  BSP_LedSet(1);

  usart_send_string(buffer);

  /* Infinite loop */
  while (1) {
	  BSP_LedToggle(1);

	  switch(rx_data){
	    case 'f':
		  Move_Forward();
		  delay_type = 1;
		  break;
	    case 'b':
		  Move_Backward();
		  delay_type = 1;
		  break;
	    case 'r':
		  Move_Left();
		  delay_type = 2;
		  break;
	    case 'l':
		  Move_Right();
		  delay_type = 2;
		  break;
	    default:
	      delay_type = 1;
		  Stop_Robot();
		  break;
	  }

	  rx_data = 0;

	  //Chooses the delay depending on the movement
	  if (delay_type == 1){
		  Delay(1000);
	  }else if(delay_type == 2){
		  Delay(200);
	  }

  }
}
Beispiel #21
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
	{
  CHIP_Init();                                   // This function addresses some chip errata and should be called at the start of every EFM32 application (need em_system.c)
  uint8_t i, front_back, left_right, command;
  char init_message[] = "Start!\n";

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  /* Initialize LED driver */
  BSP_LedsInit();
  BSP_LedSet(0);

  /* initalize clocks */
  CMU->CTRL |= (1 << 14);                         // Set HF clock divider to /2 to keep core frequency <32MHz
  CMU->OSCENCMD |= 0x4;                           // Enable XTAL Oscillator
  while(! (CMU->STATUS & 0x8) );                  // Wait for XTAL osc to stabilize
  CMU->CMD = 0x2;                                 // Select HF XTAL osc as system clock source. 48MHz XTAL, but we divided the system clock by 2, therefore our HF clock should be 24MHz

  usart_init();
  i2cInit();

  // Print test string
  for(i=0; init_message[i] != '\0'; i++) {
    usart_send_data(init_message[i]);
  }

  usart_enable_rx_isr();

  while (1)
  {
	performI2CTransfer();
    BSP_LedToggle(0);
    BSP_LedToggle(1);

    front_back = (uint8_t)(G[1]>>8 & 0xFF);
    left_right = (uint8_t)(G[0]>>8 & 0xFF);

/*
    usart_send_data(0xAA);
    usart_send_data(front_back);
    usart_send_data(0xBB);
    usart_send_data(left_right);
*/
    if (left_right >= 0x30 && front_back <= 0x45){
        	command = 'l';
        }else if (left_right >= 0xC0 && front_back <= 0xDF){
        	command = 'r';
        }else if(front_back >= 0xC0&& front_back <= 0xCD){
    	command = 'f';
    }else if (front_back >= 0x32 && front_back <= 0x35){
    	command = 'b';
    }

    /*else if (left_right >= 0x3E && front_back <= 0x40){
    	command = 'l';
    }else if (left_right >= 0xC4 && front_back <= 0xD0){
    	command = 'r';
    }
    */

    if(command != 0x00){
    	usart_send_data(command);
    	command = 0x00;
    }

    //usart_send_data((uint8_t)(G[0]>>8 & 0xFF));
    //usart_send_data((uint8_t)G[1] & 0xFF);

    Delay(500);
  }
}