本帖最后由 anchoret 于 2013-5-21 21:03 编辑
我采用查询方式接收字符串,可每次只能接收到第一个字符,帮我看看怎么回事,谢谢!
unsigned int USART0_Rec( unsigned char *buf )
{
unsigned int i;
unsigned long int time;
i = 0;
time = 0;
/* Wait for the first data to be received*/
while(!( UCSR0A & (1<<RXC0)))
;
buf i= UDR0;
while(!( UCSR0A & (1<<UDRE0))) //等待读空,去掉也不行
;
i++;
do
{
while(!( UCSR0A & (1<<RXC0)))
{
buf i= UDR0;
while(!( UCSR0A & (1<<UDRE0))) //等待读空,去掉也不行
;
i++;
}
time++;
} while (time <= 5000000);
return i;
} |