X24C44一款老的EEPROM

来源:本站
导读:目前正在解读《X24C44一款老的EEPROM》的相关信息,《X24C44一款老的EEPROM》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《X24C44一款老的EEPROM》的详细说明。
简介:本文主要介绍了X24C44一款老的EEPROM。

*/

#include "reg51.h"

#include "intrins.h"

#define X24C44_WRDS 0x80 //RESET WRITE ENABLE LATCH

#define X24C44_STO 0x81 //TRANSFERS FROM RAM TO EEPROM

#define X24C44_WRITE 0x83 //RAM WRITE

#define X24C44_WREN 0x84 //SET WRITE ENABLE LATCH

#define X24C44_RCL 0x85 //TRANSFERS FROM EEPROM TO RAM, RESETS WRITE ENABLE LATCH

#define X24C44_READ 0x86 //RAM READ</P><P>

//#define NOP() { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); }

//对从芯片而言

sbit SPI24C44_CS =P1^1;

sbit SPI24C44_SK =P1^0;

sbit SPI24C44_DI =P1^2;

sbit SPI24C44_DO =P1^3;

lag(unsigned int Time){while(Time--);}

void delayms(){ unsigned char i=255; while(i--);}

//写一字节// SPI_SK上升沿数据有效 _/-

void SPI24C44_WriteByte(unsigned char dat)

{ unsigned char count;

for(count=0;count<8;count++)

{

dat<<=1;

SPI24C44_DI=CY; NOP();

SPI24C44_SK=1; ///上升

SPI24C44_SK=0; //开始上升 NOP();

}

}

//读一字// SPI_SK上升沿数据有效 _/—

unsigned int SPI24C44_ReadWord()

{ unsigned char count;

unsigned int dat=0;

for(count=0;count<16;count++)

{

dat<<=1;

if(SPI24C44_DO) dat++; //为"0"读出一个字

SPI24C44_SK=1;

SPI24C44_SK=0;

NOP();

} return(dat);

}

//从24C44(EEPROM)里面读取一字

//address: 0-15

unsigned int SPI24C44_Read(unsigned char address)

{

unsigned char temp;

unsigned int dat;

SPI24C44_SK=0;

NOP();

SPI24C44_CS=0;

NOP();

SPI24C44_DI=0;

NOP();

SPI24C44_DO=0;

NOP();

SPI24C44_CS=1;

SPI24C44_WriteByte(X24C44_RCL);

//PERFORM A RECALL TO SET THE RECALL LATCH

SPI24C44_CS=0;

SPI24C44_CS=1;

SPI24C44_WriteByte(X24C44_WREN);

//PERFORM A RECALL TO SET THE RECALL LATCH

SPI24C44_CS=0;

address=address<<3;

temp= X24C44_READ | address;

SPI24C44_CS=1;

SPI24C44_WriteByte(temp); //Read Data from RAM Address

dat=SPI24C44_ReadWord();

SPI24C44_CS=0;

return(dat);}//向24C44里(EEPROM)写一字

SPI24C44_Write(unsigned char address,unsigned int dat)

{ unsigned char temp;

unsigned int moon;

SPI24C44_SK=0;

NOP();

SPI24C44_CS=0;

NOP();

SPI24C44_DI=0;

NOP();

SPI24C44_DO=0;

NOP();

SPI24C44_CS=1;

SPI24C44_WriteByte(X24C44_RCL); //PERFORM A RECALL TO SET THE RECALL LATCH

SPI24C44_CS=0;

SPI24C44_CS=1;

SPI24C44_WriteByte(X24C44_WREN); //PERFORM A RECALL TO SET THE RECALL LATCH

SPI24C44_CS=0;

address=address<<3;

temp=X24C44_WRITE | address;

SPI24C44_CS=1;

SPI24C44_WriteByte(temp); //WRITE(1AAAA011): Write Data into RAM Address AAAA

SPI24C44_WriteByte( (unsigned char)(dat>>8) );

//send data

SPI24C44_WriteByte( (unsigned char)dat );

//send data

SPI24C44_CS=0;

SPI24C44_CS=1;

SPI24C44_WriteByte(X24C44_STO );

//STO(1XXXX001):Store RAM Data in E2PROM

SPI24C44_CS=0;

SPI24C44_CS=1;

SPI24C44_WriteByte(X24C44_WRDS );

//STO(1XXXX001):Store RAM Data in E2PROM

SPI24C44_CS=0;

lag(500);

moon=SPI24C44_Read(address>>3);

if(moon==dat) SystemError=0;

else SystemError=1;}//非标准SPI口驱动,比较难调注意芯片与CPU接口

提醒:《X24C44一款老的EEPROM》最后刷新时间 2024-03-14 01:02:55,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《X24C44一款老的EEPROM》该内容的真实性请自行鉴别。