电路设计,软件开发,专业项目团队承接电子产品开发!


ISPRO下载型编程器
火爆销售中

RS232/TTL转换器
全IC串口窃电

RS232/TTL转换线
全IC串口窃电

ByteBlasterMV Cable
CPLD/FPGA并口下载线

ByteBlaster II Cable ISPRO下载型编程器
支持S51/AVR/PIC
超级51开发板套件
前卫实用超值

PC/MCU/CPLD
三合一学习套件

全新万年历方案
AVR单片机开发板
 

Min51单片机仿真机
迷你型

ARM7开发板
仅售260元!
 

RS-232/RS-485双向接口电平转换器  

51单片机升级STM32
火爆销售中
MPLAB-ICD2
火爆销售中
LED51开发板
玩具又名图文显示棒

面板模块/开发板
经济危机明智决择

       

GSM MODEM GSM猫

SMS短信模块 工业级/全自动
火爆销售中

大功率数传电台

高速数传电台

您当前位置:电子技术资料 -> 外围驱动 -> EEPROM ->

祝您阅读愉快!

ISPRO下载型编程器

RS232 TO TTL转换器
↑↑本文相关产品介绍↑↑

X24C44一款EEPROM(C语言)


类别:技术文章
来源:未知
作者:未知
关键字:X24C44
加入日期:2010-8-3

X24C44一款老的EEPROM,调试很久才成功的!!呵呵(C语言)
//中国电子网www.EC66.com
#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接口!!呵呵

您可能还会关注的相关技术资料:
暂无

中国电子网
www.EC66.com
QQ:34740080 EMAIL:iloveaoe@163.com
最佳浏览:1024*768
Copyright (C) 2001-2010 EC66.COM All Rights Reserved
Aoe/帝国 制作维护
粤ICP备18061901号