Board logo

标题: [求助]对SRAM的读写操作问题(附程序) [打印本页]

作者: 1725572214    时间: 2007-8-29 19:10     标题: [求助]对SRAM的读写操作问题(附程序)

请教对SRAM的读写操作问题(附程序)

#include <stdio.h>
#include "system.h"
#include "alt_types.h"

int main()
{
    alt_u32 i;
    int j;
    int *p1;
    int a[2048];
    int b[2048];
  
   
   
    for(i=0;i<2048;i++)
    {
        a=i+1;
    }
  
    for(i=0;i<0x800;i++)
    {
       IOWR_8DIRECT(0x00400000, 0, a);       
    }
   
    printf("Hello from NIOS II!\n");
   
    p1=(int*)0x00401000;
   
    for(j=0;j<0x800;j++)
    {
        IORD_8DIRECT(0x00401000, 0);
        b[j]=(*p1)&0xff;
        printf("%d\n",b[j]);
    }
   
    printf("Hello from Host!\n");
   

  return 0;
}

报错为:

**** Build of configuration Debug for project hello_world_0 ****

make -s all
Compiling hello_world.c...
../hello_world.c: In function `main':
../hello_world.c:22: warning: implicit declaration of function `IOWR_8DIRECT'
../hello_world.c:31: warning: implicit declaration of function `IORD_8DIRECT'
../hello_world.c:40:2: warning: no newline at end of file
Linking hello_world_0.elf...
obj/hello_world.o(.text+0x7c): In function `main':
../hello_world.c:22: undefined reference to `IOWR_8DIRECT'
obj/hello_world.o(.text+0xc4):../hello_world.c:31: undefined reference to `IORD_8DIRECT'
collect2: ld returned 1 exit status
make: *** [hello_world_0.elf] Error 1
Build completed in 11.344 seconds

[此贴子已经被作者于2007-8-29 19:19:25编辑过]


作者: 1725572214    时间: 2007-8-29 19:11

报错位置为:

IOWR_8DIRECT(0x00400000, 0, a);  

IORD_8DIRECT(0x00401000, 0);     


作者: caopengly    时间: 2007-8-30 20:20

“hello_world.c:31: undefined reference to `IORD_8DIRECT'
”你要包含头文件

# include <io.h>


作者: 1725572214    时间: 2007-8-30 20:24

噢  这样啊 谢谢斑竹caopengly!


作者: 1725572214    时间: 2007-8-31 10:49

再请教一下版主:我要把0x00401000处的数据存到B[I]数组中,是不是

 for(j=0;j<0x800;j++)
    {
        IORD_8DIRECT(0x00401000, 0);
        b[j]=(*p1)&0xff;
        printf("%d\n",b[j]);
    }
这样就可以呢?






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0