Exemple #1
0
int _write(int file, char *ptr, int len)
{
	int i;

	for(i = 0;i < len;i++)
	{
#ifdef USART_ADD_CRLF
		if(ptr[i] == '\n')
		{
			usart_send_data('\r');
		}
#endif
		usart_send_data(ptr[i]);
	}

	return len;
}
Exemple #2
0
void analyze_485(void)
{
	u8 data[100];
	
	memset(data,0,100);
//	printf("\r\n已进入485接收服务\r\n");
//	os_dly_wait(1);
	rt_485(USART2,data,100);
	usart_send_data(USART1,data,100);
	
	printf("\r\n");
}
Exemple #3
0
/***上传测量数据任务   100ms上传一次***/
__task void upload_refresh_data(void)
{
	u16 data[4];
	
	os_sem_init(rfsem,0);
	memset(data,0,8);
	
	while(1)
	{
		os_sem_wait(rfsem,0xffff);
		
		data[0]=refresh.yy;
		data[1]=refresh.wj;
		data[2]=refresh.yj;
		data[3]=refresh.jb;
		usart_send_data(USART2,(u8 *)data,4);
		
		os_dly_wait(1000);	
		os_sem_init(rfsem,0);
	}
}
void usart_send_string(char *str) {
	int i = 0;
	for(i = 0; str[i] != '\0'; i++) {
		usart_send_data(str[i]);
	}
}
Exemple #5
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);
  }
}