uart發送數據單片機源程序如下:
- #include <reg51.h>
- typedef unsigned char uint8;
- typedef unsigned int uint16;
- uint8 Buf[]="hello world!\n";
- /*
- * 延時
- */
- void delay(uint16 n)
- {
- while (n--);
- }
- /*
- * UART初始化
- * 波特率:9600
- */
- void UART_init(void)
- {
- SCON = 0x50; // 10位uart,允許串行接受
- TMOD = 0x20; // 定時器1工作在方式2(自動重裝)
- TH1 = 0xFD;
- TL1 = 0xFD;
- TR1 = 1;
- }
- /*
- * UART 發送一字節
- */
- void UART_send_byte(uint8 dat)
- {
- SBUF = dat;
- while (TI == 0);
- TI = 0;
- }
- /*
- * UART 發送字符串
- */
- void UART_send_string(uint8 *buf)
- {
- while (*buf != '\0')
- {
- UART_send_byte(*buf++);
- }
- }
- main()
- {
- UART_init();
-
- while (1)
- {
- UART_send_string(Buf);
- delay(20000);
- }
- }
復制代碼
所有資料51hei提供下載:
uart_send_string.rar
(10.09 KB, 下載次數: 18)
2018-5-17 23:35 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|