ATMEGA128串口问题
时间:10-02
整理:3721RD
点击:
void USART0_Init()
{
UCSR0B=0X00;
UCSR0A=0X00;
UCSR0C=(3<<UCSZ0);
// UCSR0C =(1<<UCSZ01)|(1<<UCSZ0);
UBRR0H=(11059200/16/(Baund+1))/256;
UBRR0L=(11059200/16/(Baund+1))%256;
UCSR0B|=(1<<TXEN0)|(1<<RXEN0);
}
void USART0_Send(uchar usart_data)
{
while(!(UCSR0A&(1<<UDRE0)));
UDR0=usart_data;
}
uchar USART0_Receive()
{
while(!(UCSR0A&(1<<RXC0)));
return UDR0;
while(RXC0)
UCSR0B&=~(1<<RXEN0);
}
void main()
{
uchar menory;
PORT_Init();
USART0_Init();
USART0_Send('1');
while(1)
{
// PORTB=USART0_Receive();
menory=USART0_Receive();
// PORTB=menory;
delay(500);
USART0_Send(menory);
}
}
发送正常,接收0x01为什么一位一位的接收?
{
UCSR0B=0X00;
UCSR0A=0X00;
UCSR0C=(3<<UCSZ0);
// UCSR0C =(1<<UCSZ01)|(1<<UCSZ0);
UBRR0H=(11059200/16/(Baund+1))/256;
UBRR0L=(11059200/16/(Baund+1))%256;
UCSR0B|=(1<<TXEN0)|(1<<RXEN0);
}
void USART0_Send(uchar usart_data)
{
while(!(UCSR0A&(1<<UDRE0)));
UDR0=usart_data;
}
uchar USART0_Receive()
{
while(!(UCSR0A&(1<<RXC0)));
return UDR0;
while(RXC0)
UCSR0B&=~(1<<RXEN0);
}
void main()
{
uchar menory;
PORT_Init();
USART0_Init();
USART0_Send('1');
while(1)
{
// PORTB=USART0_Receive();
menory=USART0_Receive();
// PORTB=menory;
delay(500);
USART0_Send(menory);
}
}
发送正常,接收0x01为什么一位一位的接收?