lh012278 发表于 2006-9-15 17:41:55

如何正确读写外部ram?求助于马老师

我用的是meg162的板子,外扩32K的ram,只写了一个测试读写功能的小程序,却始终运行不正常。

程序如下:

// Target : M162

// Crystal: 11.0592Mhz



#include <iom162v.h>

#include <macros.h>



#defineRUN_LIGHTPORTD|=0x10//PC0 RUN LED light

#defineRUN_BLACKPORTD&=0xEF//PC0 RUN LED black



unsigned int i;



extern unsigned char data;



//define mappings

void mapping_init(void)

{

asm(

".area memory(abs)
"

".org 0x2000
"

" _data:: .blkb 2000
"

".text
"

);

}



void port_init(void)

{

   PORTA = 0xff;//PA output

   DDRA= 0xFF;

   PORTB = 0xFF;//PB0-PB2input, others output

   DDRB= 0xb8;

   PORTC = 0xf3;//PC output

   DDRC= 0xFF;

   PORTD = 0XeF;

   DDRD= 0x72;

   PORTE = 0x07;

   DDRE= 0x00;

}



void InitSys()

{   

   //stop errant interrupts until set up

   CLI(); //disable all interrupts

   port_init();

   

   

   MCUCR= 0x80;

   EMCUCR = 0x00;

   

   TIMSK= 0x00; //timer interrupt sources

   ETIMSK=0x00;

   GICR= 0x00;

   PCMSK0=0x00;

   PCMSK1=0x00;

   SEI(); //re-enable interrupts

   //all peripherals are now initialised

}



void main(void){



    unsigned int j;

    InitSys();   



    for (j=0;j<2000;j++){

      data=0xf0;   

    }

    if (data==0xf0) {RUN_LIGHT;}   //读取数组某一位的值,如果与写入的一致,测试灯亮

}



程序运行的结果应该是测试灯直接变亮才对,可是它根本没反应

测试灯没有问题,已经检查过了

我翻过论坛上以前的帖子,数组的定义和操作没看出什么不同

实在想不出来是哪里的问题

我用的iccavr,马老师可以指点一下吗?

先行谢过。

machao 发表于 2006-9-15 18:28:15

请参考《M128》书中关于外部扩展RAM的硬件和注意事项。
页: [1]
查看完整版本: 如何正确读写外部ram?求助于马老师