?? at29c010a.c
字號(hào):
#include<reg51.h>
#include<absacc.h>
#define CsOut29Add XBYTE[0X3FFF]
#define CsOutPort XBYTE[0X5FFF]
#define test XBYTE[0XFFFF]
void delay(unsigned int times)
{
unsigned int i;
unsigned char j;
for(i=0;i<times;i++)
for(j=0;j<55;j++)
test=0x00;
}
void BeepLight(void)
{
unsigned int i;
for(i=0;i<5;i++)
{
CsOutPort=0x00;
delay(100);
CsOutPort=0x1c;
delay(100);
}
}
unsigned char ReadMemory(unsigned int sector,unsigned char AddressOfSector)
{
unsigned char AddAddress;
unsigned int xdata *MemoryAddress;
union UnionAddress
{
unsigned int word;
struct StructTwoByte
{
unsigned char byte1;
unsigned char byte2;
}StructTwoByte1;
}UnionAddress1;
MemoryAddress=0x0000;
AddAddress=(unsigned char)sector>>6;
UnionAddress1.StructTwoByte1.byte1=((unsigned char)sector&0x3f);
UnionAddress1.StructTwoByte1.byte2=AddressOfSector<<1;
UnionAddress1.word=UnionAddress1.word>>1;
CsOut29Add=AddAddress;
MemoryAddress=UnionAddress1.word;
return(*MemoryAddress);
}
void WriteMemory(unsigned int sector,unsigned char AddressOfSector,unsigned char value)
{
unsigned char AddAddress;
unsigned int xdata *MemoryAddress;
union UnionAddress
{
unsigned int word;
struct StructTwoByte
{
unsigned char byte1;
unsigned char byte2;
}StructTwoByte1;
}UnionAddress1;
MemoryAddress=0x0000;
AddAddress=(unsigned char)sector>>6;
UnionAddress1.StructTwoByte1.byte1=((unsigned char)sector&0x3f);
UnionAddress1.StructTwoByte1.byte2=AddressOfSector<<1;
UnionAddress1.word=UnionAddress1.word>>1;
CsOut29Add=AddAddress;
MemoryAddress=UnionAddress1.word; UnionAddress1.word;
*MemoryAddress=value;
}
void ReadMemorySequence(unsigned int sector,unsigned char *databuf,unsigned long number)
{
unsigned int i;
unsigned char j;
unsigned char WriteNumber;
unsigned int PageCount;
unsigned char RemainCount;
unsigned char AddAddressOfSector;
unsigned int xdata *MemoryAddress;
unsigned int address;
WriteNumber=0;
PageCount=(unsigned int)(number/0xff);
RemainCount=(unsigned char)(number%0xff);
for(i=0;i<PageCount;i++)
{
sector+=i;
AddAddressOfSector=(unsigned char)(sector>>6);
address=(sector&0x003f)<<0x07;
MemoryAddress=address;
CsOut29Add=AddAddressOfSector;
for(j=0;j<0x8f;j++)
{
databuf[WriteNumber++]=*(MemoryAddress+j);
}
delay(15);
}
sector++;
AddAddressOfSector=(unsigned char)(sector>>6);
address=(sector&0x003f)<<0x07;
MemoryAddress=address;
CsOut29Add=AddAddressOfSector;
for(j=0;j<RemainCount;j++)
{
databuf[WriteNumber++]=*(MemoryAddress+j);
}
}
void WriteMemorySequence(unsigned int sector,unsigned char *databuf,unsigned long number)
{
unsigned int i;
unsigned char j;
unsigned char WriteNumber;
unsigned int PageCount;
unsigned char RemainCount;
unsigned char AddAddressOfSector;
unsigned int xdata *MemoryAddress;
unsigned int address;
WriteNumber=0;
PageCount=(unsigned int)(number/0xff);
RemainCount=(unsigned char)(number%0xff);
for(i=0;i<PageCount;i++)
{
sector+=i;
AddAddressOfSector=(unsigned char)(sector>>6);
address=(sector&0x003f)<<0x07;
MemoryAddress=address;
CsOut29Add=AddAddressOfSector;
for(j=0;j<0x8f;j++)
{
*(MemoryAddress+j)=databuf[WriteNumber++];
}
}
sector++;
AddAddressOfSector=(unsigned char)(sector>>6);
address=(sector&0x003f)<<0x07;
MemoryAddress=address;
CsOut29Add=AddAddressOfSector;
for(j=0;j<RemainCount;j++)
{
*(MemoryAddress+j)=databuf[WriteNumber++];
}
}
void main(void)
{ /*
unsigned char result;
unsigned char i=1;
unsigned char datavalue=0x55;
BeepLight();
WriteMemory(0xff,i,datavalue);
delay(5000);
result=ReadMemory(0xff,i);
if(result==datavalue)
{
BeepLight();
}
delay(5000);
*/
//unsigned char i;
unsigned char code DataBuf[10]={0x13,0x57,0x91,0x24,0x68,0x13,0x57,0x91,0x24,0x68};
unsigned char data ReadBuf[10];
WriteMemorySequence(0xfe,DataBuf,10);
delay(15);
ReadMemorySequence(0xfe,ReadBuf,10);
BeepLight();
while(1);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -