小弟我自学AVR了一段时间用GCC编了个串口调试程序,但总是调试不成功。。串口调试助手界面里显示接收不了发送的数据,在程序的中断处理函数里做了个亮灯的标志也没反应,请好心人帮我看看程序有没有什么错误,指点指点程序如下:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#define F_CPU 16000000UL
#include"util/delay.h"
#define fosc 16000000 //时钟频率
#define baud 14400 //串口波特率
#define uint unsigned int
#define uchar unsigned char
uint i=0,j=0;
uchar data;
void uart0_init(void) //串口初始化
{
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C =_BV(UCSZ11)|_BV(UCSZ10); //无校验
UBRR1L=(fosc/16/baud-1)%256;
UBRR1H=(fosc/16/baud-1)/256; //波特率设置
UCSR1B=_BV(RXEN1)|_BV(TXEN1)|_BV(RXCIE1);
}
void putchar0(uchar c)
{
while (!(UCSR1A&(1<<UDRE1)));
UDR1=c;
}
//SIGNAL(SIG_USART1_RECV)
SIGNAL(SIG_USART1_RECV)
{
uchar buf;
buf=UDR1;
PORTA=_BV(PORTA1);
data=buf;
i=1;
_delay_us(1);
}
int main(void)
{
PORTA=_BV(PORTA0);
uart0_init();
sei();
while(1)
{
if(i==1)
{
PORTA=_BV(PORTA2);
for(j=0;j<3;j++)
{
putchar0(data);
}
}
i=0;
}
} |