打印
[AVR单片机]

请教关于在gccavr当中嵌入汇编的问题.

[复制链接]
1369|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
pengkewei|  楼主 | 2007-5-28 23:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请教关于在gccavr当中嵌入汇编的问题.
我看了芯艺和另外一本书,参照书中的例句编译不成功.如:芯艺的书当中说,如果
从IO口读取一个数据送内部寄存器当中应当使用下列语句:
asm("in %0,%1 " : "=r " (value) : "I" (_SFR_IO_ADDR(PORTD)));

我基本上全抄袭他的内容写出源文件如下:
#include <avr/io.h>
#include <avr/boot.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <avr/interrupt.h>

int main (void)
{
    asm("in %0,%1 " : "=r " (value) : "I" (_SFR_IO_ADDR(PORTD)));
}

编译环境为pn2.0.6.1 出错提示如下:
> "make.exe" all

-------- begin --------
avr-gcc (GCC) 3.4.6
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling C: test0003.c
avr-gcc -c -mmcu=atmega8 -I. -gdwarf-2 -DF_CPU=7372800UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wundef -Wa,-adhlns=obj/test0003.lst  -std=gnu99 -Wundef -MD -MP -MF .dep/test0003.o.d test0003.c -o obj/test0003.o 
test0003.c: In function `main':
test0003.c:10: error: `value' undeclared (first use in this function)
test0003.c:10: error: (Each undeclared identifier is reported only once
test0003.c:10: error: for each function it appears in.)
make.exe: *** [obj/test0003.o] Error 1

> Process Exit Code: 2

其中我修改了很多地方,编译都出错.请问这个语句我应该怎样写? 

相关帖子

沙发
John_Lee| | 2007-5-29 11:02 | 只看该作者

value未定义

int main (void)
{
    uint8_t value;
    asm("in %0,%1 " : "=r " (value) : "I" (_SFR_IO_ADDR(PORTD)));
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

12

主题

46

帖子

1

粉丝