void usart_gets(RAM_SCLS char *buffer, unsigned char len) { unsigned char i; unsigned char dat; for(i=0;i<len;i++) { while(!usart_drdy()); dat = usart_getc(); *buffer = dat; buffer++; /* read until a \0 is received */ if(!dat)return; } }
int uart_GetString (char *str) { int pos=0; char *str_old = str; while ( *(str-1)!=0x0d ) { if (usart_drdy()) { *str= usart_getc(); usart_putc (*str); if (*str==0x08) str--; else str++; } } *str=0; return (str-str_old); }
// Regardless of what the USB is up to, we check the USART to see // if there's something we should be doing. static void checkEcho() { static char bDebug=0, antDebug; static int giro=0; char buffer[80]; if (usart_drdy()) { // Have a character to huh unsigned char rxByte; rxByte = usart_getc(); usart_putc(rxByte); switch (rxByte) { case ' ': bDebug=!bDebug; printf ("\n\rDebug=%d ",bDebug); setMotorsDebug (bDebug); break; case 'a': velocidad++; motorSpeed (velocidad, MOTOR_1); motorSpeed (velocidad, MOTOR_2); break; case 'z': velocidad--; motorSpeed (velocidad, MOTOR_1); motorSpeed (velocidad, MOTOR_2); break; case 'e': antDebug=bDebug; setMotorsDebug (0); printf ("\n\rEntre velocidad: "); uart_GetString(buffer); velocidad = atoi (buffer); printf ("\n\rVelocidad = %d",velocidad); motorSpeed (velocidad, MOTOR_1); motorSpeed (velocidad, MOTOR_2); setMotorsDebug (antDebug); break; case 'X': if(deviceState == DETACHED) printf("Detached\r\n"); else if(deviceState == ATTACHED) printf("Attached\r\n"); else if(deviceState == POWERED) printf("Powered\r\n"); else if(deviceState == DEFAULT) printf("Default\r\n"); else if(deviceState == ADDRESS) printf("Address\r\n"); else if(deviceState == CONFIGURED) printf("Configured\r\n"); else printf("Unknown state\r\n"); printf("UCON: %x, UCFG: %x\r\n", UCON, UCFG); break; } } }