串口发送指令补充
- //发送一个字节
- void sendByte(USART_TypeDef* USARTx,u8 date)
- {
- USART_SendData(USARTx, date);
- while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE)==RESET);
- }
- //发送两个字节
- void sendTwoByte(USART_TypeDef* USARTx,u16 date)
- {
- u8 temp_h,temp_l;
- temp_h =(date&0xff00)>>8;
- temp_l=(date&0xff);
- sendByte(USARTx,temp_h);
- sendByte(USARTx,temp_l);
-
-
- }
- //发送四个字节
- void sendFourByte(USART_TypeDef* USARTx,u32 date)
- {
- u8 temp1,temp2,temp3,temp4;
- temp1 =(date&0xff000000)>>24;
- temp2=(date&0xff0000)>>16;
- temp3=(date&0xff00)>>8;
- temp4=(date&0xff);
- sendByte(USARTx,temp1);
- sendByte(USARTx,temp2);
- sendByte(USARTx,temp3);
- sendByte(USARTx,temp4);
-
-
- }
- //发送8位数组
- void sendArry(USART_TypeDef* USARTx,u8 *arry,u8 num)
- {
- u8 i;
- for(i=0;i<num;i++)
- {
- sendByte(USARTx,arry[i]);
- }
- while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
- }
- //发送字符串
- void Usart_Sendstr(USART_TypeDef* USARTx,char*str)
- {
- u8 i=0;
- do
- {
- sendByte(USARTx,str[i]);
- i++;
- }
- while(*(str+i)!='\n');
- while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
-
- }
|