sumole 发表于 2007-11-19 15:07:56

GCC中断函数中的指针

程序如下
SIGNAL(SIG_INTERRUPT5)
{uint buff;
uchar *p=0x7018;
........
}
编译后提示 error: invalid conversion from `int' to `unsigned char*'
但在别的函数中这样写没问题,急

shark 发表于 2007-11-19 18:02:29

SIGNAL(SIG_INTERRUPT5)
{uint buff;
uchar *p=(uchar*)0x7018;
........
}

mljda 发表于 2007-11-19 19:52:06

楼上正解~
结果-》p 指向 0x0718字节型 地址空间;

sumole 发表于 2007-11-19 23:18:32

谢谢一楼的解答
但这和c语言的指针初始化不一样哦


我用指针访问一个接口芯片的缓存区
#defineaddress *(uchar *)0x7018
   address=12;//编译通过
   buff=address;//编译不通过
怎么回事?

shark 发表于 2007-11-20 00:33:38

我编译通过winavr20070525
#include <avr/io.h>
#include <avr/interrupt.h>

typedef unsigned char uchar;
typedef unsigned intuint;

SIGNAL(SIG_OVERFLOW0)
{
uint buff;
uchar *p=(uchar*)0x7018;
#defineaddress *(uchar *)0x7018
   address=12;//编译通过
   buff=address;//编译通过   
}   
int main()
{
   return 0;
}

sumole 发表于 2007-11-20 10:10:16

谢谢 shark

sumole 发表于 2007-11-20 10:49:52

还想问一下gcc中如何实现类似c中
uchar *p=address;
*p=0;
*(p+1)=1;
的地址加一的操作

shark 发表于 2007-11-20 12:10:55

gcc不也是c嘛,一样操作。

sumole 发表于 2007-11-20 12:20:12

获取一个数组的首地址
uchar *p
p=&a;
编译时warning: assignment discards qualifiers from pointer target type
请问如何解决

shark 发表于 2007-11-20 12:23:03

你的信息不完整,猜不出来,a是什么类型?是如何定义的?

sumole 发表于 2007-11-20 12:45:20

就是一个普通数组    uchar a={......略.......}保证没越界

shark 发表于 2007-11-20 13:14:46

我编译没有任何warning和errors,WINAVR20070525

#include <avr/io.h>
#include <avr/interrupt.h>

typedef unsigned char uchar;
typedef unsigned intuint;

uchar a={1,2,3,4,5};
int main()
{
   uchar *p ;
   p = &a;
   PORTB = *p;
   return 0;
}

你如果还有问题,贴一下可重现故障的最小程序。

sumole 发表于 2007-11-20 13:40:44

const prog_uchar EPDescr_Out_HS=
   {           0x07,                           
        0x05,                                                               
        0x01,                                                          
        0x03,                                                                                0x00,                              
        0x02,                                                        
        0x02
   };

int main()
{uchar *p;
uchar buff;
p=&EPDescr_Out_HS;
buff=*p;
.............
}

shark 发表于 2007-11-20 15:49:49

prog_uchar 是存储在flash中的,不能用*p访问的,要用pgm_read_byte函数

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>

typedef unsigned char uchar;
typedef unsigned intuint;

prog_uchar EPDescr_Out_HS=
   {         0x07,                           
      0x05,                                                               
      0x01,                                                            
      0x03,                                                                              0x00,                              
      0x02,                                                         
      0x02
   };

int main()
{
   uchar buff;
   buff = pgm_read_byte(& EPDescr_Out_HS);
}

sumole 发表于 2007-11-20 15:55:42

一语惊醒梦中人,shark真高手也
有没有这方面的书,推荐一下,论坛上的书讲的不够详细,有的部分都没有

shark 发表于 2007-11-20 16:01:10

用GCC,务必要先看艺芯的《AVR单片机GCC程序设计》。

sumole 发表于 2007-11-20 16:41:36

这就看
页: [1]
查看完整版本: GCC中断函数中的指针