|
論壇前面有人寫了雙串口的,參考以下帖子:http://www.zg4o1577.cn/bbs/dpj-49898-1.html
這個程序也是寫的很不錯的。
而我這個是串口2,采用多.c的模塊編程,可以直接加入工程中,很方便~~
程序可以附件下載
- /*--------------------------------
- 串口2范例程序
- *
- RXD--P1.2
- TXD--P1.3
- */
- #include <STC12C5A60S2.H>
- #include "UART2.h"
- void Uart2Init(void) //9600bps@11.0592MHz
- {
- AUXR |= 0x08; //使能波特率倍速位S2SMOD:(波特率加倍)
- S2CON = 0x50; //8位數(shù)據(jù),可變波特率
- AUXR &= 0xFB; //獨立波特率發(fā)生器時鐘為Fosc/12,即12T
-
- BRT = 0xFA; //設(shè)定獨立波特率發(fā)生器重裝值
-
- AUXR |= 0x10; //啟動獨立波特率發(fā)生器
- }
- void Uart2_send_byte(unsigned char date)//自己改下名稱 不要一樣
- {
- S2BUF=date;
- while((S2CON&0X02)==0);
- S2CON&=~0X02; //清除發(fā)送標(biāo)志位
- }
- void Uart2_send_string(unsigned char *p) //串口2發(fā)送一個字符串
- {
- while(*p!='\0')
- {
- Uart2_send_byte(*p);
- p++;
- }
- }
復(fù)制代碼 主程序:
- /*--------------------------------
- *
- 2018年8月29日
- 程序的功能是: 使用STC12C5A60S2 串口2 發(fā)送數(shù)據(jù)
- 硬件:
- 作者:畫中仙
- *
- */
- #include <STC12C5A60S2.H>
- #include "UART2.h"
- unsigned char temps[20]={"You are= "};//字符串,可以直接修改內(nèi)容
- unsigned char code displaytable[] = {"0123456789.C%"}; //顯示數(shù)字表
- int main()
- {
-
- Uart2Init();//初始化9600
-
- Uart2_send_byte(displaytable[1]); //發(fā)送數(shù)字1
- Uart2_send_string(temps); //將這個字符串發(fā)送
-
-
- while(1)
- {
- }
- }
復(fù)制代碼
全部資料51hei下載地址:
UART2程序.zip
(21.81 KB, 下載次數(shù): 366)
2018-8-30 21:57 上傳
點擊文件名下載附件
2018年8月30日
|
|