搜索
bottom↓
回复: 4

一段代码在ICC AVR 编译可以正常运行在GCC 不知道那个地方有错?

[复制链接]

出0入0汤圆

发表于 2008-5-7 17:28:16 | 显示全部楼层 |阅读模式
功能是串口打印字符串函数.用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")
#define  CLI()  cli()
#define  SEI()  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...
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2008-5-7 18:53:45 | 显示全部楼层
putchar??  stdout需要指定吧?参考avr libc 手册stdio.h

出0入0汤圆

 楼主| 发表于 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)

出0入0汤圆

发表于 2008-5-8 11:08:58 | 显示全部楼层
参考avr libc 手册

出0入0汤圆

发表于 2014-6-28 14:17:40 | 显示全部楼层
没有定位串口的发送操作哈,所以需要自己重新编写代码,
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-23 21:32

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表