#include <reg51.H>
#define uint unsigned int
#define uchar unsigned char
uchar dat0[3];
void UartInit(void) //9600bps@11.0592MHz
{
SCON = 0x50; //8位數據,可變波特率
TMOD= 0x20; //設置定時器模式
TL1 = 0xFD; //設置定時初始值
TH1 = 0xFD; //設置定時重載值
ET1 = 0; //禁止定時器中斷
TR1 = 1; //定時器1開始計時
}
//串口發送函數
void PutString(unsigned char *TXStr)
{
while(*TXStr!=0)
{
SBUF=*TXStr;
while(TI==0);
TI=0;
TXStr++;
}
}
void Delay(uint t)
{
uint i,j;
for(i=t;i>0;i--)
for(j=110;j>0;j--);
}
void main()
{
UartInit();
while(1)
{
dat0[0]=P0;
dat0[1]=P1;
dat0[2]=P2;
PutString(dat0);
Delay(1000);
}
}
|