liuzhijun 发表于 2008-5-7 17:28:16

一段代码在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...
}

felixch 发表于 2008-5-7 18:53:45

putchar??stdout需要指定吧?参考avr libc 手册stdio.h

liuzhijun 发表于 2008-5-8 09:40:49

【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)

felixch 发表于 2008-5-8 11:08:58

参考avr libc 手册

zqy517 发表于 2014-6-28 14:17:40

没有定位串口的发送操作哈,所以需要自己重新编写代码,
页: [1]
查看完整版本: 一段代码在ICC AVR 编译可以正常运行在GCC 不知道那个地方有错?