|
简单的串口发送程序,下载到实验板上后,将开发板和电脑之间用串口线连上,但是串口助手接不到数据。串口助手设置为9600,无校验位,8数据位,1停止位。
帮忙看下,问题在哪,刚接触AVR~~
代码如下:
//ICC-AVR application builder : 2012-8-30 16:33:51
// Target : M128
// Crystal: 7.3728Mhz
#include
#include
#define fosc 7372800
#define baud 9600
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9600 (0.0%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06; //char size 8
UBRR0L = (fosc/16/(baud+1))%256; //set baud rate lo
UBRR0H = (fosc/16/(baud+1))/256; //set baud rate hi
UCSR0B = (1<
}
void putchar0(unsigned char c)
{
while(!(UCSR0A&(1<
UDR0=c;
}
void puts0(char *s)
{
while(*s)
{
putchar0(*s);
s++;
}
putchar0(0x0a);
putchar0(0x0d);
}
void main()
{
unsigned char i;
uart0_init();
puts0("hello!");
while(1)
{
puts0("test OK!");
}
}
|
|