|
#include "reg52.h"
sfr AUXR =0x8E; //此文件中定義了單片機(jī)的一些特殊功能寄存器
typedef unsigned int u16; //對數(shù)據(jù)類型進(jìn)行聲明定義
typedef unsigned char u8;
void UartInit(void) //4800bps@12.000MHz
{
SCON = 0x50; //8位數(shù)據(jù),可變波特率
AUXR |= 0x40; //定時(shí)器1時(shí)鐘為Fosc,即1T
AUXR &= 0xFE; //串口1選擇定時(shí)器1為波特率發(fā)生器
TMOD &= 0x0F; //設(shè)定定時(shí)器1為16位自動重裝方式
TL1 = 0x8F; //設(shè)定定時(shí)初值
TH1 = 0xFD; //設(shè)定定時(shí)初值
ET1 = 0; //禁止定時(shí)器1中斷
TR1 = 1; //啟動定時(shí)器1
}
void main()
{
UartInit(); // 串口初始化
while(1);
}
void Usart() interrupt 4
{
u8 receiveData;
receiveData=SBUF;//接收到的數(shù)據(jù)
RI=0;
SBUF=receiveData;
while(!TI);
TI=0;
}
還是不行,試了11.0592MHz和12Mhz的,串口輸入之后,沒有返回值 |
|