如题,亲测成功!
单片机源程序如下:
- #include "stm32f10x.h"
- #include "delay.h"
- #include "HX711.h"
- #include "usart.h"
- #include "usart2.h"
- #include "usart3.h"
- #include "usart4.h"
- #include "usart5.h"
- int main(void)
- {
- u8 i;
- u8 len1;
- u8 len2;
- u8 len3;
- u8 len4;
- u8 len5;
- u16 times=0;
- delay_init();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- uart1_init(115200);
- uart2_init(115200);
- uart3_init(115200);
- uart4_init(115200);
- uart5_init(115200);
- while(1)
- {
- if(USART1_RX_STA&0x8000)
- {
- len1=USART1_RX_STA&0x3fff;
- for(i=0;i<len1;i++)
- {
- USART_SendData(USART1, USART1_RX_BUF[i]);
- while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
- }
- USART1_RX_STA=0;
- }else
- {
- if(times%200==0)
- {
- u1_printf("This is u1\n");
- }
- }
- if(USART2_RX_STA&0x8000)
- {
- len2=USART2_RX_STA&0x3fff;
- for(i=0;i<len2;i++)
- {
- USART_SendData(USART2, USART2_RX_BUF[i]);
- while(USART_GetFlagStatus(USART2,USART_FLAG_TC)!=SET);
- }
- USART2_RX_STA=0;
- }else
- {
- if(times%200==0)
- {
- u2_printf("This is u2\n");
- }
- }
- if(USART3_RX_STA&0x8000)
- {
- len3 = USART3_RX_STA&0x3fff;
- for(i = 0;i < len3;i++)
- {
- USART_SendData(USART3, USART3_RX_BUF[i]);
- while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
- }
- USART3_RX_STA=0;
- }else
- {
- if(times%200==0)
- {
- u3_printf("This is u3\n");
- }
- }
- if(USART4_RX_STA&0x8000)
- {
- len4 = USART4_RX_STA&0x3fff;
- for(i = 0;i < len4;i++)
- {
- USART_SendData(UART4, USART4_RX_BUF[i]);
- while(USART_GetFlagStatus(UART4,USART_FLAG_TC)!=SET);
- }
- USART4_RX_STA=0;
- }else
- {
- if(times%200==0)
- {
- u4_printf("This is u4\n");
- }
- }
- if(USART5_RX_STA&0x8000)
- {
- len5 = USART5_RX_STA&0x3fff;
- for(i = 0;i < len5;i++)
- {
- USART_SendData(UART5, USART5_RX_BUF[i]);
- while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);
- }
- USART5_RX_STA=0;
- }else
- {
- if(times%200==0)
- {
- u5_printf("This is u5\n");
- }
- }
- times++;
- delay_ms(10);
- }
- }
复制代码
所有资料51hei提供下载:
5个串口同时工作.rar
(309.69 KB, 下载次数: 190)
|