#include "config.h"
#define uint unsigned int
#define uchar unsigned char
//#define SRAM_ADDR (uint16 *)0x80000000 //SRAM的起始地址分配在BANK0
#define SRAM_ADDR 0x80000000
//由于BS62LV16008001的A0与LPC2214的A1相连,所以addr要左移一位
//#define GetAddr(addr) (volatile uint16 *)(SRAM_ADDR|(addr<<1))
#define LED 0x000f0000
uint16 a=0;
void delay_ms(uint z)
{
uint x,y;
for(x=3000;x>0;x--)
for(y=z;y>0;y--);
}
void sram_init()
{
PINSEL2=0x0e002020; //拉低WE OE CS0
// BCFG0=0x0000104f; //存储器组配置寄存器
PINSEL2=PINSEL2&0xfffffff7; //将P1.16-P1.25设置为GPIO口
IO1DIR=LED; //将P1.16-1.19设置为输出端
IO1SET=LED;
}
void write_data(uint32 Addr, uint8 data)
{
volatile uint16 *ip;
// PINSEL2=0x0e002020; //拉低WE OE CS1
ip=(volatile uint16 *)(SRAM_ADDR|Addr);
*ip=data;
// delay_ms(10);
// PINSEL2=0x0e002030; //拉高WE OE CS0送数据
}
/*uchar read_data(uint32 Addr)
{
uchar k;
volatile uint16 *ip;
ip=(volatile uint16 *)(SRAM_ADDR+0);
k=*ip;
return(k);
}*/
int main()
{
volatile uint16 *addr;
sram_init();
while(1)
{
write_data(0x0,0x01);
// delay_ms(20);
// PINSEL2=0x0e002020; //拉低WE OE CS0
addr=(volatile uint16 *)SRAM_ADDR+0;
// delay_ms(20);
a=(*addr);
if(a==0x01)
{
IO1CLR=LED;
}
else
{
IO1SET=LED;
}
}
// while(1);
return(0);
}
现在可以读,但地址改变后就回出错。。我的寄存器BCFG配置有点问题。。。有高手可以说说这方面的资料吗 |