|
|
基于stm32f103rb的串口通信
單片機(jī)源程序如下:
- /******************************************************************************/
- // 任務(wù)分類:非周期非連續(xù)(隨機(jī)任務(wù))、周期非連續(xù)(定時任務(wù))、周期連續(xù)(循環(huán))
- // 本程序:單個周期連續(xù)性任務(wù)
- // 通過查詢方式進(jìn)行USART1數(shù)據(jù)發(fā)送
- // 連線: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) // 死循環(huán)
- {
- 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.(系統(tǒng)時鐘為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();
- }
復(fù)制代碼
所有資料51hei提供下載:
串口.rar
(4.16 KB, 下載次數(shù): 13)
2019-6-24 11:35 上傳
點擊文件名下載附件
|
|