一段代码在ICC AVR 编译可以正常运行在GCC 不知道那个地方有错?
功能是串口打印字符串函数.用ICC编译可以正常运行,用GCC编译却不能运行.(代码为ICC工具自动生成,在GCC下编译只改了头文件和宏定义)#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <stdio.h>
/*------宏定义------*/
#define uchar unsigned char
#define uint unsigned int
#define BIT(x) (1<<(x))
#define NOP() asm("nop")
#define WDR() asm("wdr")
#defineCLI()cli()
#defineSEI()sei()
void port_init(void)
{
PORTA = 0x00;
DDRA= 0x00;
PORTB = 0xff;
DDRB= 0x00;
PORTC = 0x00; //m103 output only
DDRC= 0x00;
PORTD = 0x00;
DDRD= 0xff;
PORTE = 0x00;
DDRE= 0x00;
PORTF = 0x00;
DDRF= 0x00;
PORTG = 0x00;
DDRG= 0x00;
}
void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x2F; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x18;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV= 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
uart0_init();
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void Puts( unsigned char *s) // \arg pointer to a string ending by \0
{
while (*s)
{
putchar(*s);
s++;
}
}
//
int main(void)
{
init_devices();
while(1)
{
puts("HELLO AVR");
}
//insert your functional code here...
} putchar??stdout需要指定吧?参考avr libc 手册stdio.h 【1楼】 felixch不是太明白可以说清楚点吗!
//================================================
下面是GCC STDIO。H里面的已经有putchar();但不知道怎样指定。
#if !defined(DOXYGEN)
extern int putc(int __c, FILE *__stream);
extern int putchar(int __c);
#endif /* not DOXYGEN */
#define putc(__c, __stream) fputc(__c, __stream)
#define putchar(__c) fputc(__c, stdout) 参考avr libc 手册 没有定位串口的发送操作哈,所以需要自己重新编写代码,
页:
[1]