//
設計題目
:
基於51單片機的串口通信
//
功能
:
//
說明
:
晶振用12m,
///////////////////////////////////////////////////////////
#include
//
12m
晶振
#define
uchar
unsigned
char
#define
uint
unsigned
int
///////////////////////////////////////////////////////////
//
name
:
串口發送函數
//
in
:
//
out
:
//
function
:
//
explain
:
///////////////////////////////////////////////////////////
void
send(uchar
x)
{
sbuf=x;
//
將數據放到緩沖區,發送
while(!ti);
//
等待發送完成
ti=0;
//
清標誌位
}
///////////////////////////////////////////////////////////
//
name
:
初始化函數
//
in
:
//
out
:
//
function
:
//
explain
:
///////////////////////////////////////////////////////////
void
init(void)
{
tmod=0x20;
//
t1工作在方式2,自動重載
th1=0xe6;
tl1=0xe6;
//
設置波特率為1200
sm0=0;
sm1=1;
//
串口方式1
tr1=1;
//
打開定時器1
}
///////////////////////////////////////////////////////////
//
name
:
主函數
//
in
:
//
out
:
//
function
:
//
explain
:
///////////////////////////////////////////////////////////
void
main(void)
{
uchar
i;
init();
//
初始化
while(1)
{
for(i=0;
i<10;
i++)
{
send(i);
}
}
}