我用MEGA128总线外扩了一片FM1808,在其有效的地址范围内(0x1100~0x9100)定义了一些变量.
/*********************************************************************************************************
AVR 外部EEPROM读写范例
EEPROM的简介
EEPROM的写操作
EEPROM的读操作
**--------------文件信息--------------------------------------------------------------------------------
**文 件 名:RdWr_FM1808.c
**创 建 人: lijianliang
**最后修改日期: 2008年4月2日
**描 述: read write FM1808
记录:
*********************************************************************************************************/
/*
在普通模式下,前 4352 个数据地址包含寄存器文件, I/O 存储器,扩展的 I/O 存储器以
及内部数据 SRAM。起始的 32 个地址为寄存器文件,然后是 64 个 I/O 存储器,接着是
160 个扩展的 I/O 存储器,最后是 4096 字节的内部数据 SRAM。
*/
#include <avr/io.h>
//#include <avr/inttypes.h>
#define uchar unsigned char
#define uint unsigned int
void DelayMs(uint t)
{
uint i;
for(i=0;i<t;i++)
{
i++;
i--;
}
}
void main(void)
{
uchar j=0;
uint *ptr;
uint temp;
MCUCR=0x80;//外部SRAM使能
XMCRA=0x2c;
XMCRB=0x00;//使能外部存储器总线保持功能
ptr=0x2100;
*ptr++=0x05;
temp=0x0006;
for(j=0;j<100;j++)
{
//temp=*ptr;
++temp;
DelayMs(10);
*ptr++=temp;
DelayMs(10);
DelayMs(10);
}
while(1)
{
DelayMs(100);
DelayMs(100);
}
}