本帖最后由 uuuren 于 2010-11-25 17:35 编辑
/*** Initialization of Serial Port(Ex.Baud Rate setting) ***/
void InitSerial(void)
{SCON = 0x50; // SERIAL MODE 1, SM00 = 0, SM01 =1, REN=1
TMOD |= 0x20; // Timer1 MODE 2
PCON |= 0x80; // SMOD0 = 1
TL1 = 0xFC; // Baud Rate Setting to 115200bps
TH1 = 0xFC; // Baud Rate Setting to 115200bps
TR1 = 1; // Timer1 START
txbufrflag = 1;
RI = 0;
TI = 0;
txdptro = 0;
txdptri = 0;
rxdptro = 0;
rxdptri = 0;
ES = 1; // 1}
void PU_INT4(void) interrupt 4 //中断
{ EA = 0;
if (RI)
{ RI = 0;
uartrxd[rxdptri++] = SBUF; }
if (TI)
{ TI = 0;
if (txdptro == txdptri)
txbufrflag = 1;
else
SBUF = uarttxd[txdptro++];
}
EA = 1;
}
char putchar(char accum) // 串行口输出
{ while (((txdptri+1) & 0x0f) == txdptro);
uarttxd[txdptri++]=accum;
if (txbufrflag)
{txbufrflag = 0;
TI = 1;}
return accum;}
unsigned char GetcomLn(unsigned char *temp)
{unsigned char byData,count;
count = 0;
while(rxdptro != rxdptri)
{temp[count++] = uartrxd[rxdptro++];
for(byData = 0; byData < 30; byData++)
{if (rxdptri == rxdptro) wait_1us(5);
else break;}
}
temp[count] = 0; //字符串最后加一空格
return count;
}
请教问题:putchar(char accum)中 while (((txdptri+1) & 0x0f) == txdptro);有什么作用?
以及GetcomLn中那个for循环有什么用? |