基于stm32f103rb的串口通信
單片機源程序如下:
- /******************************************************************************/
- // 任務分類:非周期非連續(隨機任務)、周期非連續(定時任務)、周期連續(循環)
- // 本程序:單個周期連續性任務
- // 通過查詢方式進行USART1數據發送
- // 連線:USART1缺省連線
- /******************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include <stm32f10x.h>
- #include "drv_usart.h"
- #include <stdio.h>
- //uint8_t TxBuffer[] = "USART Hyperterminal Hardware Flow Control Example!\n";
- void Delay1ms(uint32_t nCount);
- // 主程序
- int main(void)
- {
- unsigned char k = 0;
- float ft = 0.0f;
-
- USART2_Config(); // 串口初始化
- while(1) // 死循環
- {
- k++;
- ft = (float)k / 10.0f;
- printf("\r\n this is a printf demo \r\n");
- printf("Integer and float dispaly is %d, \t %f\r\n", k, ft);
- Delay1ms(1000); // 延時1s
- }
- }
- /*----------------------------------------------------------*\
- | Delay1ms 延時 Inserts a delay time.(系統時鐘為8MHz*9) |
- | nCount: 延時時間 specifies the delay time length. |
- \*----------------------------------------------------------*/
- void Delay1ms(uint32_t nCount)
- {
- int k;
-
- for(; nCount != 0; nCount--)
- for(k=0; k<10282; k++)
- __nop();
- }
復制代碼
所有資料51hei提供下載:
串口.rar
(4.16 KB, 下載次數: 13)
2019-6-24 11:35 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|