/***************************************************************************** * * Description: * Output routine that adds extra line feeds at line breaks. * * Params: * [in] charToSend - The character to print (to uart #1) * ****************************************************************************/ void uart1SendCh(tU8 charToSend) { if(charToSend == '\n') uart1SendChar('\r'); uart1SendChar(charToSend); }
void uart1SendString(char* data, int length) { int i; for(i=0; i<length; i++) { uart1SendChar(data[i]); } }
void uart1SendString(unsigned char *s) { char a; while ((a = *s++)) { uart1SendChar(a); } }
void uart1SendFloat(float data) { int i; char* ptr; ptr = (char*)&data; for (i = 0; i < 4; i++) { uart1SendChar(*(ptr + i)); } }
/********************************************************************************************************* ** Function name: UART1_IRQHandler ** Descriptions: UART1ÖжϷþÎñº¯Êý ** input parameters: none ** output parameters: none ** Returned value: none ** Created by: ** Created date: **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: *********************************************************************************************************/ void UART1_IRQHandler (void) { UART_MemMapPtr uartPtr = UART1_BASE_PTR; /* ·¢ËÍÖжϴ¦Àí³ÌÐò */ #if UART1_SEND_IRQ /* Óû§¶¨Òå */ #endif #if UART1_RECEIVE_IRQ while (UART_S1_REG(uartPtr) & UART_S1_RDRF_MASK){ /* Çå³ýÖжϱêÖ¾ */ uart1SendChar(UART_D_REG(uartPtr)); /* ·µ»Ø½ÓÊÕÊý¾Ý */ // while (!UART0_D_REG(uartPtr)); /* Çå½ÓÊÕ»º³åÇø */ } #endif }
void sendReceive(unsigned char directionL, int ref_speedL, unsigned char directionR, int ref_speedR ){ int i=0; int wait=0; unsigned char header_com=210; int time=readRTC(); uart1SendChar(header_com); uart1SendChar(directionL); uart1SendChar((unsigned char)ref_speedL); //printf("I send1 %c %c \r\n", ref_speedL, directionL); while(!uart1Signal()){ sLch = 0; //printf(" i'm busy "); wait++; if (wait>1000) {break; //goto et; } } if(uart1Signal()){ sLch = uart1GetCh(); if (i==0) {//printf("I receive left speed: \r\n"); //printf(" %d %d ",time, sLch*2); delayMS(2); } } uart1SendChar(header_com); uart1SendChar(directionR); uart1SendChar(( unsigned char) ref_speedR); //printf("I send2 %c %c \r\n", ref_speedR, directionR); wait=0; while(!uart1Signal()){ sRch = 0; //printf(" i'm busy right"); wait++; if (wait>1000) {break; //goto et; } } if(uart1Signal()){ sRch = uart1GetCh(); if (i==0) {//printf("I receive right speed: \r\n"); //printf(" %d \r\n", sRch*2); delayMS(2); } } }
/********************************************************************************************************* ** Function name: uart2SendString ** Descriptions: UART·¢ËÍÒ»¸ö×Ö·û´® ** input parameters: pucBuf:´ý·¢ËÍ×Ö·û´®Ö¸Õë ** output parameters: none ** Returned value: none ** Created by: ** Created date: **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: *********************************************************************************************************/ void uart2SendString (INT8U *pucBuf) { while (*pucBuf != '\0') { uart1SendChar(*pucBuf++); } }
void uart1SendChars(unsigned char *buf, unsigned int size) { while (size--) { uart1SendChar(*buf++); } }
/***************************************************************************** * * Description: * Print a fixed number of bytes (as opposed to NULL-terminated string). * * Params: * [in] pBuff - The character to print (to uart #1) * [in] count - Number of characters to print * ****************************************************************************/ void uart1SendChars(char *pBuff, tU16 count) { while (count--) uart1SendChar(*pBuff++); }