avr16串口发送与接收

2019-07-15 23:05发布

usart 串口发送与接收遇到问题,发送不了预先设定值 求救
//ICC-AVR application builder : 8/12/2013 8:54:32 AM
// Target : M16
// Crystal: 16.000Mhz

#include <iom16v.h>
#include <macros.h>

void port_init(void)
{
PORTA = 0x00;
DDRA  = 0x00;
PORTB = 0x00;
DDRB  = 0x00;
PORTC = 0x00; //m103 output only
DDRC  = 0x00;
PORTD = 0x00;
DDRD  = 0xff;
}

//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9604 (0.0%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x02;
UCSRC = BIT(URSEL) | 0x46;
UBRRL = 0x40; //set baud rate lo
UBRRH = 0x03; //set baud rate hi
UCSRB = 0x08;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
uart0_init();

MCUCR = 0x00;
GICR  = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void delay(void)
{
unsigned int a,b;

for(a=0;a<1000;a++)
for(b=0;b<2000;b++);

}
void main(void)
{unsigned  int i=0;
unsigned int data[]={0,1,2,3,4,5,6,7,8,9};
init_devices();
while(1)
{
UDR=data[i++];
delay();
if(i>=10)
{
i=0;
}
}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。