Пример #1
0
void main() {
trisb=0b11111011;
uart1_init(2400);
PWM1_Init(30000);
PWM1_Set_Duty(127);
PWM1_Start();
for(;;){
if(portb.f0==0)
{
uart1_write('a');
}while(portb.f0==0);
if(portb.f4==0)
{
uart1_write('a');
}while(portb.f4==0);
if(portb.f5==0)
{
uart1_write('b');
}while(portb.f5==0);
if(portb.f6==0)
{
uart1_write('c');
}while(portb.f6==0);
}

}
Пример #2
0
// Triggered whenever a character is recv'd
__declspec(interrupt) void uart1_isr() {
	if(MCF_UART1_USR & MCF_UART_USR_RXRDY) {
		MCF_UART1_UCR = MCF_UART_UCR_RX_ENABLED;
		uint8_t rc = (uint8_t)MCF_UART1_URB;
		
		if(rc == PACKET_ID_DL) {
			map_dl_pos_x = 0;
			map_dl_pos_y = 0;
			
			// Signal we are ready for the map
			uart1_write(PACKET_ID_GET);
		} else {
			if(map_dl_pos_y > 8 || map_dl_pos_x > 8)
				return;
			
			dl_map[map_dl_pos_y][map_dl_pos_x] = rc;
			
			// If we've written the last byte of the map, send an acknowledge and copy the man into init_map
			if(map_dl_pos_y == 7 && map_dl_pos_x == 7) {
				uart1_write(PACKET_ID_ACK);
				pacman_set_init_map(dl_map);
			}
			
			// Next column
			map_dl_pos_x++;
			
			// Move to the next row
			if(map_dl_pos_x == 8) {
				map_dl_pos_x = 0;
				map_dl_pos_y++;
			}
		}
	}
}
Пример #3
0
void data_hub_send_telemetry(char buf[PAGE_SIZE]){
  static __xdata u16 sequence_num = 0;
  u16 crc = crc16(buf, PAGE_SIZE,
      crc16((u8 *)&(++sequence_num), sizeof(sequence_num), 0));
  if(uart1_tx_margin() < (
      sizeof(protocol_header) + sizeof(sequence_num) + PAGE_SIZE + sizeof(crc))){
    return;
  }
  uart1_write(protocol_header, sizeof(protocol_header));
  uart1_write((u8 *)&sequence_num, sizeof(sequence_num));
  uart1_write(buf, PAGE_SIZE);
  uart1_write((u8 *)&crc, sizeof(crc));
}
Пример #4
0
void telemeter_send(char buf[SYLPHIDE_PAGESIZE]){
  static __xdata u16 sequence_num = 0;
  u16 crc;
  if((!telemeter_ready)
      || (uart1_tx_margin() < (
        sizeof(sylphide_protocol_header) + sizeof(sequence_num)
          + SYLPHIDE_PAGESIZE + sizeof(crc)))){
    return;
  }
  crc = crc16(buf, SYLPHIDE_PAGESIZE,
      crc16((u8 *)&(++sequence_num), sizeof(sequence_num), 0));
  uart1_write(sylphide_protocol_header, sizeof(sylphide_protocol_header));
  uart1_write((u8 *)&sequence_num, sizeof(sequence_num));
  uart1_write(buf, SYLPHIDE_PAGESIZE);
  uart1_write((u8 *)&crc, sizeof(crc));
}
Пример #5
0
void main() {
unsigned int x=0;
char txt[7];
char pins;
unsigned int clpin[8];
config();
flash();
uart1_init(9600);
uart1_write_text("hello");
clpin[0]=touch(0);
clpin[1]=touch(1);
clpin[2]=touch(2);
clpin[3]=touch(3);
clpin[4]=touch(8);
clpin[5]=touch(9);
clpin[6]=touch(10);
clpin[7]=touch(12);
while(1)
{
//delay_ms(100);
uart1_write_text("pin=");
x=touch(2);
inttostr(x,txt);
uart1_write_text(txt);
uart1_write(13);
uart1_write_text("pin=");
pins=get_touch(clpin);
inttostr(pins,txt);
uart1_write_text(txt);
uart1_write(13);

led(pins);


}




}
Пример #6
0
void uart1_write(char c)
{
	unsigned int oldmask;

	oldmask = irq_getmask();
	irq_setmask(0);

	if (c == '\n')
		uart1_write('\r');

	while (!(readb(&uart1->lsr) & (LM32_UART_LSR_THRR | LM32_UART_LSR_TEMT)))
		;
	writeb(c, &uart1->rxtx);

	irq_setmask(oldmask);
}
Пример #7
0
void uart1_write_byte( unsigned char Byte)
{
	uart1_write(&Byte, 1);
}
Пример #8
0
int main(void)
{
   uint8_t status;

   init2();

   wait(1000);
   uart1_reset();
   uart1_write("+", 1);
   flash_init();
   uart1_write("++", 2);

   status = MDPROTO_STATUS_OK;

   while (1) {
      wait(1000);
      uart1_reset();
      status = read_cmd();
      if (status == MDPROTO_STATUS_OK) {
	 switch (buf.data.id) {
	    case MDPROTO_CMD_PING:
	       write_cmd_response(MDPROTO_CMD_PING_RESPONSE, "PONG", strlen("PONG"));
	       break;
	    case MDPROTO_CMD_MEM_READ:
	       if (MDPROTO_CMD_SIZE(buf) != 9)
		  status = MDPROTO_STATUS_WRONG_PARAM;
	       else {
		  uint32_t from, to;
		  from = (buf.data.p[1] << 24)
		     | (buf.data.p[2] << 16)
		     | (buf.data.p[3] << 8)
		     | (buf.data.p[4]);
		  to = (buf.data.p[5] << 24)
		     | (buf.data.p[6] << 16)
		     | (buf.data.p[7] << 8)
		     | (buf.data.p[8]);

		  if (to < from)
		     status = MDPROTO_STATUS_WRONG_PARAM;
		  else {
		     union {
			uint32_t u32;
			uint16_t u16[2];
			uint8_t u8[4];
		     } __attribute__((packed)) chunk;
		     unsigned pkt_size, chunk_size;

		     pkt_size = mdproto_pkt_init(&buf, MDPROTO_CMD_MEM_READ_RESPONSE, NULL, 0);

		     /* Alligned read */
		     while (from <= to) {
			/* read chunk */
			if ( ((from % 4) == 0) && ( to-from+1 >= 4 )) {
			   uint32_t volatile *from_u32 __attribute__((aligned(__alignof__(uint32_t))));
			   from_u32 = (uint32_t *)from;
			   chunk_size = 4;
			   chunk.u32 = *from_u32;
			}else if ( ((from % 2) == 0) && ( to-from+1 >= 2 )  ) {
			   uint16_t volatile *from_u16 __attribute__((aligned(__alignof__(uint16_t))));
			   from_u16 = (uint16_t *)from;
			   chunk_size = 2;
			   chunk.u16[0] = *from_u16;
			}else {
			   chunk_size=1;
			   chunk.u8[0] = *(uint8_t *)from;
			}
			from += chunk_size;

			/* Append chunk to packet */
			pkt_size = mdproto_pkt_append(&buf, &chunk.u8[0], chunk_size);

			/* Flush full packet */
			if (MDPROTO_CMD_SIZE(buf)+8 > MDPROTO_CMD_MAX_RAW_DATA_SIZE) {
			   uart1_write((void *)&buf, pkt_size);
			   pkt_size = (unsigned)mdproto_pkt_init(&buf, MDPROTO_CMD_MEM_READ_RESPONSE, NULL, 0);
			}
		     } /* while (from <= to) */

		     if (MDPROTO_CMD_SIZE(buf) > 0)
			uart1_write((void *)&buf, pkt_size);
		  }
	       }
void main() {
int i;
int temp1;
char test[32];
uart1_init(2400);
CE_DIR=0;
CSN_DIR=0;
CSK_DIR=0;
MOSI_DIR=0;
MISO_DIR=1;
delay_ms(500);
nrf24_config();
CSN=1;
CE=1;




lcd_init();
Lcd_Cmd(_LCD_CURSOR_OFF);
//lcd_out(2,1,"welcome");

trisb.f0=0;
rb0_bit=0;
trisd.f0=0;
for(i=0;i<30;i++)
{
rd0_bit=1;
delay_us(400);
rd0_bit=0;
delay_us(19600);

}
uart1_write_text("TEST");
uart1_write(13);

//lcd_out(1,1,"S");
while(1)
{
  temp1=read_add(0x07);
if(((temp1&0b01000000)>>6)==1)
{
CE=0;
delay_ms(50);
//lcd_out(1,1,"data");
read_buff(0x61,test,32);
uart1_write_text(test);
lcd_out(1,1,test);
reset();
CE=1;

}


















 if(uart1_data_ready())
 {
  rfid[idx]=uart1_read();

   ///////////////////////////////////////////////////////////03002e2838
  if(rfid[idx]=='0'&&valid2<10)
  {
   valid2++;
  }
   else if(rfid[idx]=='3'&&valid2<10)
  {
   valid2++;
  }
   else if(rfid[idx]=='2'&&valid2<10)
  {
   valid2++;
  }
  else if(rfid[idx]=='E'&&valid2==5)
  {
   valid2++;
  }
  else if(rfid[idx]=='8'&&valid2<10)
  {
   valid2++;
   }
  else
  {
  valid2=0;
  }



   if(rfid[idx]=='0'&&valid1<10) //03002e90b0
  {
   valid1++;
  }
   else if(rfid[idx]=='3'&&valid1==1)
  {
   valid1++;
  }
   else if(rfid[idx]=='2'&&valid1==4)
  {
   valid1++;
  }
  else if(rfid[idx]=='E'&&valid1==5)
  {
   valid1++;
  }
  else if(rfid[idx]=='9'&&valid1==6)
  {
   valid1++;
  }
    else if(rfid[idx]=='B'&&valid1==8)
  {
   valid1++;
  }
  else
  {
  valid1=0;
  }








  if(valid2>=10)
  {
  lcd_out(2,1,"User2 : 03002E2838");
  delay_ms(1000);
   lcd_cmd(_lcd_clear);
   lcd_out(2,1,"UnValid");
   valid2=0;
   for(i=0;i<30;i++)
{
rd0_bit=1;
delay_us(400);
rd0_bit=0;
delay_us(19600);

}
   delay_ms(1000);
   lcd_cmd(_lcd_clear);
  }



 if(valid1>=10)
  {
  lcd_out(2,1,"User1 : 03002E90B0");
     delay_ms(1000);
   lcd_cmd(_lcd_clear);
   lcd_out(2,1,"Valid");
   valid1=0;
   for(i=0;i<30;i++)
{
rd0_bit=1;
delay_us(1500);
rd0_bit=0;
delay_us(18500);

}
   delay_ms(1000);
    for(i=0;i<30;i++)
{
rd0_bit=1;
delay_us(400);
rd0_bit=0;
delay_us(19600);

}
   
   
   
   lcd_cmd(_lcd_clear);
  }

 }



}






}
Пример #10
0
void uart1_puts(const char *s)
{
	while (*s)
		uart1_write(*s++);
}
Пример #11
0
void main() {
char rec;
int x,y;
int f[5];
char send[7];

uart1_init(9600);

trisc=0b10000000;
DI=1;
CLK=1;
uart1_write_text("hello");
while(1)
{
  if(uart1_data_ready())
  {
    rec=uart1_read();
    if(rec=='1')
    audio(1);
    if(rec=='2')
    audio(2);
    if(rec=='3')
    audio(3);
    if(rec=='4')
    audio(4);
    if(rec=='5')
    audio(5);
  }

f[0]=adc_read(12);
f[1]=adc_read(10);
f[2]=adc_read(8);
f[3]=adc_read(9);
f[4]=adc_read(11);
x=adc_read(0);
y=adc_read(1);
inttostr(f[0],send);
uart1_write_text("f0=");
uart1_write_text(send);
uart1_write(13);
IntToStr(f[1],send);
uart1_write_text("f1=");
uart1_write_text(send);
uart1_write(13);
IntToStr(f[2],send);
uart1_write_text("f2=");
uart1_write_text(send);
uart1_write(13);
IntToStr(f[3],send);
uart1_write_text("f3=");
uart1_write_text(send);
uart1_write(13);
IntToStr(f[4],send);
uart1_write_text("f4=");
uart1_write_text(send);
uart1_write(13);
IntToStr(x,send);
uart1_write_text("x=");
uart1_write_text(send);
uart1_write(13);
IntToStr(y,send);
uart1_write_text("y=");
uart1_write_text(send);
uart1_write(13);
delay_ms(1000);


if(f[0]<170&&f[1]<180&&f[2]<180&&f[3]>250)
{
 audio(2);
 delay_ms(5000);
}

else if(f[0]<170&&f[1]<180&&f[2]<180&&f[3]<170&&rec!='c')
{
 audio(1);
 delay_ms(5000);
}


else if(f[0]>230&&f[1]>230&&f[2]>230&&f[3]>230&&x<280)
{
  audio(3);
  delay_ms(5000);
}



else if(f[0]<170&&f[1]<180&&f[2]<180&&f[3]<170&&rec=='c')
{
 audio(4);
 rec=0;
 delay_ms(5000);
}

else if(f[0]>230&&f[1]>230&&f[2]>230&&f[3]>230&&x>350&&rec=='b')
{
 audio(5);
 rec=0;
 delay_ms(5000);
}


}

}
Пример #12
0
void main()
{
  unsigned char i;
  unsigned char tmp;
  unsigned int tmpi;
  unsigned int tout;

  char str[6];

  ADCON1=0x06;
  TRISA=0xC3;
  TRISB=0x01;
  TRISC=0x01;
  TRISD=0x00;
  TRISE=0x00;

  NOT_RBPU_bit=0;

  lcd_init();
  UART1_Init(9600);
  adc_init();


/*
//dip
  TRISB=0x03;
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("Ligue todos DIP"));
  lcd_cmd(_LCD_SECOND_ROW);
  lcd_out_cp(codetxt_to_ramtxt("Press. RB1"));
  while(RB1_bit);
*/

//testa caracter especial
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("   Teste LCD"));

  lcd_cmd(0x40);//endere�o

  lcd_chr_cp(0x11);
  lcd_chr_cp(0x19);
  lcd_chr_cp(0x15);
  lcd_chr_cp(0x13);
  lcd_chr_cp(0x13);
  lcd_chr_cp(0x15);
  lcd_chr_cp(0x19);
  lcd_chr_cp(0x11);

  lcd_chr_cp(0x0E);
  lcd_chr_cp(0x11);
  lcd_chr_cp(0x0E);
  lcd_chr_cp(0x05);
  lcd_chr_cp(0x0E);
  lcd_chr_cp(0x14);
  lcd_chr_cp(0x0A);
  lcd_chr_cp(0x11);


  lcd_cmd(_LCD_SECOND_ROW);

  for(i=0;i<16;i++)
  {
    lcd_chr_cp(i%2);
    delay_ms(100);
  }

//teste lcd
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("   Teste LCD"));
  
  for(i=32;i<128;i++)
  {
    if((i%16) == 0)lcd_cmd(_LCD_SECOND_ROW);
    lcd_chr_cp(i);
    delay_ms(50);
  }

  delay_ms(100);
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("   Teste LCD"));
  lcd_cmd(_LCD_SECOND_ROW);
  lcd_out_cp(codetxt_to_ramtxt("       Ok"));
  delay_ms(500);




//testa display 7s

  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("   Teste 7 Seg"));


   ADCON1=0x06;
    for(i=0;i<4;i++)
    {
      switch(i)
      {
         case 0: 
           PORTA=0x20;
           break;
         case 1: 
           PORTA=0x10;
           break;
         case 2: 
           PORTA=0x08;
           break;
         case 3: 
           PORTA=0x04;
           break;
       }

      for(tmp=0;tmp<16;tmp++)
      {
        PORTD=display7s(tmp);         
        delay_ms(200);
      }
    }

  ADCON1=0x02;
  PORTD=0;

/*
//dip
  TRISB=0x03;
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("Desligue RTC DIP"));
  lcd_cmd(_LCD_SECOND_ROW);
  lcd_out_cp(codetxt_to_ramtxt("Press. RB1"));
  while(RB1_bit);
*/

//testa LEDs
  TRISB=0x00;
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW+3);
  lcd_out_cp(codetxt_to_ramtxt("Teste LEDs"));

  for(tmp=0;tmp<3;tmp++)
    {
      for(i=1;i > 0;i=i*2)
      { 
        PORTB=i;
        PORTD=i; 
        delay_ms(200);
      }
    }
  PORTB=0;
  PORTD=0;
  for(i=0;i<4;i++)
  {
    PORTB^=0xFF;
    PORTD^=0xFF;
    delay_ms(200);
  }  

//testa chaves


  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("  Teste Chaves"));

  tmp=0;
  ADCON1=0x06;
  TRISA|=0x20;

  while((tmp & 0x7F) != 0x7F)
  {
    TRISB=0x3F;

    if(RB0_bit == 0)
    {
      tmp|=0x01;
    }
    if(RB1_bit == 0)
    {
      tmp|=0x02;
    }
    if(RB2_bit == 0)
    {
      tmp|=0x04;
    }
    if(RB3_bit == 0)
    {
      tmp|=0x08;
    }
    if(RB4_bit == 0)
    {
      tmp|=0x10;
    }
    if(RB5_bit == 0)
    {
      tmp|=0x20;
    }
    if(RA5_bit == 0)
    {
      tmp|=0x40;
    }

    
    TRISB=0x00;
    PORTB=tmp;
    delay_ms(10);
  }

    delay_ms(500);

  PORTB=0; 
  ADCON1=0x02;


 




  TRISC7_bit=1; //RX
  TRISC6_bit=0; //TX

//teste serial
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("Teste Serial TX"));
  lcd_cmd(_LCD_SECOND_ROW+4);
  lcd_out_cp(codetxt_to_ramtxt("9600 8N1"));

  uart1_write_text(codetxt_to_ramtxt("\r\n Picsimlab\r\n Teste Serial TX\r\n"));

  for(i=0;i<4;i++)
  {
    uart1_write(i+0x30);
    uart1_write_text(codetxt_to_ramtxt(" PicsimLab\r\n"));
  }
  delay_ms(1000);

  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("Teste Serial RX"));
  uart1_write_text(codetxt_to_ramtxt(" Digite!\r\n"));
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(_LCD_SECOND_ROW);
       uart1_write_text(codetxt_to_ramtxt("\r\n"));
    }
    
    tout=0;
    while((!uart1_data_ready())&&(tout<2000))
    {
      tout++;
      delay_ms(1);
    }
    if(uart1_data_ready())
    {
      tmp=uart1_read();
    }
    else
    {
      tmp='-';
    }
    lcd_chr_cp(tmp);
    uart1_write(tmp);
  }
  delay_ms(100);



//teste ADC
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt(" Teste ADC (P1)"));

  for(i=0; i< 200; i++)
  {
    tmp=(adc_read(0)*10)/204;
    lcd_cmd(_LCD_SECOND_ROW+6);
    inttostr(tmp,str);
    if(str[4] == ' ')
      lcd_chr_cp('0');
    else
      lcd_chr_cp(str[4]);
    lcd_chr_cp(',');
    lcd_chr_cp(str[5]);
    lcd_chr_cp('V');
    delay_ms(10);
  }

  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt(" Teste ADC (P2)"));

  for(i=0; i< 200; i++)
  {
    tmp=((unsigned int)adc_read(1)*10)/204;
    lcd_cmd(_LCD_SECOND_ROW+6);
    inttostr(tmp,str);
    if(str[4] == ' ')
      lcd_chr_cp('0');
    else
      lcd_chr_cp(str[4]);
    lcd_chr_cp(',');
    lcd_chr_cp(str[5]);
    lcd_chr_cp('V');
    delay_ms(10);
  }


//teste RELE

  TRISC0_bit=0;
  TRISE0_bit=0;

  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("Teste RELE 1 2"));

  
  for(i=0;i<5;i++)
  {
    RC0_bit^=1;
    RE0_bit^=1;
    delay_ms(500);
  }
  RC0_bit=0;
  RE0_bit=0;
    
  /*
  lcd_cmd(_LCD_CLEAR);
  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("Teste RELE 2"));

  for(i=0;i<5;i++)
  {
    RE0_bit^=1;
    delay_ms(500);
  }
  RE0_bit=0;
 */
 

//fim teste 
  lcd_cmd(_LCD_CLEAR);

  lcd_cmd(_LCD_FIRST_ROW);
  lcd_out_cp(codetxt_to_ramtxt("      Fim"));
/*
  lcd_cmd(_LCD_SECOND_ROW);
  lcd_out_cp(codetxt_to_ramtxt(" Pressione RST"));
  */
  uart1_write_text(codetxt_to_ramtxt("\r\n FIM!\r\n"));


   while(1);

}
Пример #13
0
static void expect(FIL *file){
  enum {
    INIT,
    BEFORE_SEND,
    SENDING,
    SENDING_ESCAPE,
    SENDING_ESCAPE_HEX1,
    SENDING_ESCAPE_HEX2,
    BEFORE_EXPECT,
    EXPECTING,
    EXPECT_FAILED,
    EXPECT_TIMEOUT,
    BEFORE_WAIT,
    WAITING,
    IGNORE_LINE,
  } state = INIT;

  char c;
  char buf[8];
  u8 buf_length, expect_index;
  u16 read_size;

  telemeter_ready = 0;

  while((f_read(file, &c, sizeof(c), &read_size) == FR_OK)
      && (read_size > 0)){
    unsigned char is_endline = ((c == '\r') || (c == '\n'));
    switch(state){
      case INIT:
        if(c == '$'){
          while(uart1_read(buf, sizeof(buf)) > 0); // clear RX buffer
          state = BEFORE_SEND;
        }else if(c == '>'){
          state = BEFORE_EXPECT;
          buf_length = expect_index = 0;
          do{
            u8 timeout = FALSE;
            timeout_10ms = 0;
            while(!uart1_read(&c, sizeof(c))){
              if(timeout_10ms >= 100){
                timeout = TRUE;
                break;
              }
            }
            if(timeout){
              buf_length = 0;
              break;
            }else if(c == '\r' || c == '\n'){
              if(buf_length > 0){break;}
            }else if(buf_length < sizeof(buf)){
              buf[buf_length++] = c;
            }
          }while(1);
        }else if(c == '@'){
          state = BEFORE_WAIT;
        }else if(!isspace(c)){
          state = IGNORE_LINE;
        }
        break;
      case BEFORE_SEND:
        if(isspace(c)){
          if(is_endline){state = INIT;}
          break;
        }
        state = SENDING;
      case SENDING:
        if(is_endline){
          state = INIT;
        }else if(c == '\\'){ // escape char
          state = SENDING_ESCAPE;
        }else{
          uart1_write(&c, sizeof(c));
        }
        break;
      case SENDING_ESCAPE:
        if(c == 'x'){
          state = SENDING_ESCAPE_HEX1;
          break;
        }
        switch(c){
          case 'r': c = '\r'; break;
          case 'n': c = '\n'; break;
          case '\\': c = '\\'; break;
        }
        uart1_write(&c, sizeof(c));
        state = SENDING;
        break;
      case SENDING_ESCAPE_HEX1:
        buf[0] = ((c & 0x0F) + (c >= 'A' ? 10 : 0)) << 4;
        state = SENDING_ESCAPE_HEX2;
        break;
      case SENDING_ESCAPE_HEX2:
        buf[0] += ((c & 0x0F) + (c >= 'A' ? 10 : 0));
        uart1_write(buf, 1);
        state = SENDING;
        break;
      case BEFORE_EXPECT:
        if(isspace(c)){
          if(is_endline){state = INIT;} // match any including timeout(buf_length == 0)
          break;
        }else if(buf_length == 0){
          state = EXPECT_TIMEOUT;
          return;
        }
        state = EXPECTING;
      case EXPECTING:
        if(is_endline){
          state = INIT;
        }else if(expect_index < buf_length){
          if(c != buf[expect_index++]){
            state = EXPECT_FAILED;
            return;
          }
        }
        break;
      case BEFORE_WAIT:
        if(isspace(c)){
          if(is_endline){state = INIT;}
          break;
        }
        buf_length = 0;
        state = WAITING;
      case WAITING:
        if(is_endline){
          buf[buf_length] = '\0';
          wait_ms((unsigned int)atol(buf));
          state = INIT;
        }else if(buf_length < (sizeof(buf) - 1)){
          buf[buf_length++] = c;
        }
        break;
      case IGNORE_LINE:
        if(is_endline){state = INIT;}
        break;
    }
  }

  telemeter_ready = 1;
}