#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
void usart_init(void)
{
UCSR0C|=(1<<UCSZ01)|(1<<UCSZ00);
UBRR0H=0X00;
UBRR0L=51;
UCSR0B|=(1<<TXEN0); //波特率9600
UCSR1C|=(1<<UCSZ11)|(1<<UCSZ10);
UBRR1H=0X00;
UBRR1L=51;
UCSR1B|=(1<<TXEN1);
}
/********************************************************************
函 数 名:sent
入口参数:data
出口参数:无
函数作用:发送数据
说 明:
********************************************************************/
void sent(unsigned char data)
{
while(!(UCSR0A&(1<<UDRE0)));
UDR0=data;
}
void sent1(unsigned char data)
{
while(!(UCSR1A&(1<<UDRE1)));
UDR1=data;
}
int main(void)
{
usart_init();
DDRA = 0XFF;
PORTA = 0xfe;
DDRD |= (1<<PD3);
PORTD |= (1<<PD3);
while(1)
{
PORTA = 0xff;
sent(0x33);
_delay_ms(100);
//sent1(0x32);
_delay_ms(500);
PORTA = 0x00;
_delay_ms(500);
}
}
上面是代码,代码执行到sent1(0x32);的时候会卡住,串口0可用,串口1不能使用,大神们知道是什么原因吗? |