//从RS232接收一个字节
int uart_getchar(void)
{
uchar status,res;
// CLR_0(PORTC,PC1);
// _delay_us(20);
if(!(UCSR0A & 0x80))
return -1; //no data to be received
status = UCSR0A;
res = UDR0;
if (status & 0x1c)
return -1; // If error, return -1
return res;
}
//等待从RS232接收一个有效的字节
uchar uart_waitchar(void)
{
int c;
while((c=uart_getchar())==-1);
return (uchar)c;
}