|
一個(gè)復(fù)雜的項(xiàng)目往往會(huì)用到多個(gè)串口
一般的串口1、2、3都有例程可用
這里主要分享串口4、5的調(diào)用
單片機(jī)源程序如下:
- #include "sys.h"
- #include "usart.h"
- #include "delay.h"
- #include "led.h"
- #include "usart2.h"
- #include "usart3.h"
- #include "UART4.h"
- #include "UART5.h"
- void u1_Tx(void)
- {
- USART1->DR=0x44; delay_ms(1);
- USART1->DR=0x53; delay_ms(1);
- USART1->DR=0x54; delay_ms(1);
- USART1->DR=0x31; delay_ms(1);
-
- USART1->DR=0x0d; delay_ms(1);
- USART1->DR=0x0a; delay_ms(1);
- }
- void u2_Tx(void)
- {
- USART2->DR=0x44; delay_ms(1);
- USART2->DR=0x53; delay_ms(1);
- USART2->DR=0x54; delay_ms(1);
- USART2->DR=0x32; delay_ms(1);
-
- USART2->DR=0x0d; delay_ms(1);
- USART2->DR=0x0a; delay_ms(1);
- }
- void u3_Tx(void)
- {
- USART3->DR=0x44; delay_ms(1);
- USART3->DR=0x53; delay_ms(1);
- USART3->DR=0x54; delay_ms(1);
- USART3->DR=0x33; delay_ms(1);
-
- USART3->DR=0x0d; delay_ms(1);
- USART3->DR=0x0a; delay_ms(1);
- }
- void u4_Tx(void)
- {
- UART4->DR=0x44; delay_ms(1);
- UART4->DR=0x53; delay_ms(1);
- UART4->DR=0x54; delay_ms(1);
- UART4->DR=0x34; delay_ms(1);
-
- UART4->DR=0x0d; delay_ms(1);
- UART4->DR=0x0a; delay_ms(1);
- }
-
- void u5_Tx(void)
- {
- UART5->DR=0x44; delay_ms(1);
- UART5->DR=0x53; delay_ms(1);
- UART5->DR=0x54; delay_ms(1);
- UART5->DR=0x35; delay_ms(1);
-
- UART5->DR=0x0d; delay_ms(1);
- UART5->DR=0x0a; delay_ms(1);
- }
- int main(void)
- {
-
- Stm32_Clock_Init(9);//系統(tǒng)時(shí)鐘設(shè)置
- delay_init(72); //延時(shí)初始化
-
- uart_init(72,9600); //串口1初始化
- usart2_Init(36,9600); //串口2 初始化為 波特率:9600
- usart3_init(36,9600); //串口3 初始化為 初始化為9600
- uart4_init(36,9600);
- uart5_init(36,9600);
- // PD2 串口5-RX 與LED1 沖突
- // LED_Init();
-
- while(1)
- {
- delay_ms(3000);
- u1_Tx();
- u2_Tx();
- u3_Tx();
- u4_Tx();
- u5_Tx();
- }
-
-
- }
復(fù)制代碼
所有程序51hei提供下載:
串口1 串口2 串口3 串口4 串口5 初始化程序(寄存器版).7z
(472.38 KB, 下載次數(shù): 12)
2021-6-29 15:59 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|