本帖最后由 itelectron 于 2010-8-16 10:26 编辑
/*----------------------------
Initial UART
----------------------------*/
void InitUart()
{
EA=1;ES=1;//ET1=1;
SCON = 0x50; /* 0x52;//SCON */
TMOD |= 0x21; /*0x20;// TMOD */
TCON = 0x60; /*0x60;// TCON */
PCON=PCON&0x7f;
//TL1=0xD0;TH1=0XD0;//1200
//TL1=0xE8;TH1=0XE8;//2400
//TL1=0xF4;TH1=0XF4;//4800
//TL1=0xfA;TH1=0XfA;//9600
//PCON=PCON|0x80;TL1=0xfA;TH1=0XfA;//19200
//PCON=PCON|0x80;TL1=0xfd;TH1=0Xfd;//38400
PCON=PCON|0x80;TL1=0xff;TH1=0Xff;//115200
}
/*----------------------------
Send one byte data to PC
Input: dat (UART data)
Output:-
----------------------------*/
void SendData(unsigned char dat)
{ SBUF = dat; //Send current data
while (!TI);TI = 0; //Wait for the previous data is sent
//if (!TI);TI = 0;
//Clear TI flag
} |