/********************************************************************** * @name UART2_SendString * * @param None * * @return int * * @description Write character to Serial Port * ***********************************************************************/ void UART2_SendString (unsigned char *s) { while (*s != 0) { UART2_SendByte(*s++); } }
/*---------------------------------------------------------------------------* * Routine: UART2_SendDataBlock *---------------------------------------------------------------------------* * Description: * Send a group of data to the SCI2 transmit buffer. Block until * all data is sent. * Inputs: * uint8_t *aData -- Pointer to bytes to send out * uint32_t aLen -- Number of bytes to send * Outputs: * void *---------------------------------------------------------------------------*/ void UART2_SendDataBlock(const uint8_t *aData, uint32_t aLen) { /* Send each byte one at a time unless out of space */ uint32_t i; for (i = 0; i < aLen; ++i) { while (!UART2_SendByte(aData[i])); } }
/******************************************************************************************* * 函数名:UART2_SendString() * 参数 :uint8_t *s 指向字符串的指针 * 返回值:void * 描述 :UART2发送字符串函数 *********************************************************************************************/ void UART2_SendString(uint8_t *s) { while(*s) //判断是否到字符串末尾 { UART2_SendByte(*s); //发送指针当前所指的字节 s++; //地址加1 } }
/******************************************************************************************* * 函数名:UART2_Handler() * 参数 :void * 返回值:void * 描述 :UART2中断服务函数 *********************************************************************************************/ void UART2_Handler(void) { uint8_t temp; if((UART2->UART_SR& UART_SR_RXRDY)==1) { //接收数据中断 temp= UART2->UART_RHR&0xff; //接收一个字节 UART2_SendByte(temp); //将接收的数据发回 } }
void UART2_SendString(u8* Data) { u16 i=0; //for(; i < len; i++) while(Data[i]!='\0') { UART2_SendByte(Data[i]); /* 循环调用发送一个字符函数 */ i++; } }
/********************************************************************** * @name UART2_SendChar * * @param None * * @return int * * @description Write character to Serial Port * ***********************************************************************/ void UART2_SendChar(char disp) { uint16_t dispbuf[4]; uint8_t i; dispbuf[3] = disp%10 + '0'; dispbuf[2] = disp/10%10 + '0'; dispbuf[1] = disp/10/10%10 + '0'; dispbuf[0] = disp/10/10/10%10 + '0'; for(i=0;i<4;i++) UART2_SendByte(dispbuf[i]); }
/*---------------------------------------------------------------------------* * Routine: UART2_SendData *---------------------------------------------------------------------------* * Description: * Attempts to send a group of data to the SCI2 transmit buffer. * Returns the number of bytes actually sent. * Inputs: * uint8_t *aData -- Pointer to bytes to send out * uint32_t aLen -- Number of bytes to send * Outputs: * void *---------------------------------------------------------------------------*/ uint32_t UART2_SendData(const uint8_t *aData, uint32_t aLen) { uint32_t i; /* Send each byte one at a time unless out of space */ for (i = 0; i < aLen; ++i) { if (!UART2_SendByte(aData[i])) break; } /* Return the number of bytes that did get into the transmit FIFO */ return i; }
void UART2_SendBytes(u8 *bytes,u8 len)//发送指定长度16进制数据 { u8 i=0; for(i=0;i<len;i++) UART2_SendByte(*(bytes+i)); }