论坛前面有人写了双串口的,参考以下帖子:http://www.51hei.com/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位数据,可变波特率
- AUXR &= 0xFB; //独立波特率发生器时钟为Fosc/12,即12T
-
- BRT = 0xFA; //设定独立波特率发生器重装值
-
- AUXR |= 0x10; //启动独立波特率发生器
- }
- void Uart2_send_byte(unsigned char date)//自己改下名称 不要一样
- {
- S2BUF=date;
- while((S2CON&0X02)==0);
- S2CON&=~0X02; //清除发送标志位
- }
- void Uart2_send_string(unsigned char *p) //串口2发送一个字符串
- {
- while(*p!='\0')
- {
- Uart2_send_byte(*p);
- p++;
- }
- }
复制代码 主程序:
- /*--------------------------------
- *
- 2018年8月29日
- 程序的功能是: 使用STC12C5A60S2 串口2 发送数据
- 硬件:
- 作者:画中仙
- *
- */
- #include <STC12C5A60S2.H>
- #include "UART2.h"
- unsigned char temps[20]={"You are= "};//字符串,可以直接修改内容
- unsigned char code displaytable[] = {"0123456789.C%"}; //显示数字表
- int main()
- {
-
- Uart2Init();//初始化9600
-
- Uart2_send_byte(displaytable[1]); //发送数字1
- Uart2_send_string(temps); //将这个字符串发送
-
-
- while(1)
- {
- }
- }
复制代码
全部资料51hei下载地址:
UART2程序.zip
(21.81 KB, 下载次数: 366)
2018年8月30日
|