24C02 EEPROM存储器的C语言操作.doc_第1页
24C02 EEPROM存储器的C语言操作.doc_第2页
24C02 EEPROM存储器的C语言操作.doc_第3页
24C02 EEPROM存储器的C语言操作.doc_第4页
24C02 EEPROM存储器的C语言操作.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include #ifndef false #define false 0#endif#ifndef true #define true 1#endif#define WriteDeviceAddress 0xa0#define ReadDviceAddress 0xa1 sbit SDA = P3 5; /根据实际连接的管脚定义sbit SCL = P3 4;sbit led = P10;sbit led2 = P11;unsigned char code Num21=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80, 0x90,0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00, 0x10,0x89; unsigned char code Disdigit4 = 0x7F,0xBF,0xDF,0xEF;unsigned char Disbuf4;unsigned char code write_data5 = 5,2,5,1,8 ;unsigned char read_data5;/-void Delayus(unsigned int number) for(;number!=0;number-)/-void DelayMs(unsigned int number) unsigned char temp;for(;number!=0;number-) for(temp=112;temp!=0;temp-) /-void Start() SDA=1;Delayus(4);SCL=1;Delayus(4);SDA=0;Delayus(4);SCL=0;Delayus(4);/-void Stop() SCL=0;Delayus(4);SDA=0;Delayus(4);SCL=1;Delayus(4);SDA=1;Delayus(4);/-void Ack() SDA=0;Delayus(4);SCL=1;Delayus(4);SCL=0;Delayus(4);SDA=1;Delayus(4);/-void NoAck() SDA=1;Delayus(4);SCL=1;Delayus(4);SCL=0;Delayus(4);SDA=0; /-bit TestAck() bit ErrorBit;SDA=1;Delayus(4);SCL=1;Delayus(4);ErrorBit=SDA;Delayus(4);SCL=0;return(ErrorBit);/-void Write8Bit(unsigned char input) unsigned char temp;for(temp=8;temp!=0;temp-) SDA=(bit)(input&0x80); Delayus(4); SCL=1; Delayus(4); SCL=0; Delayus(4); input=input1;/-unsigned char Read8Bit() unsigned char temp,rbyte=0;for(temp=8;temp!=0;temp-) SCL=1; Delayus(4); rbyte=rbyte1; rbyte=rbyte|(unsigned char)(SDA); SCL=0;return(rbyte);void Write24c02(unsigned char *Wdata,unsigned char RomAddress,unsigned char number)Start();Write8Bit(WriteDeviceAddress);TestAck();Write8Bit(RomAddress);TestAck();for(;number!=0;number-) Write8Bit(*Wdata); TestAck(); Wdata+;Stop();DelayMs(10);void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes)Start();Write8Bit(WriteDeviceAddress);TestAck();Write8Bit(RomAddress);TestAck();Start();Write8Bit(ReadDviceAddress);TestAck();while(bytes!=1) *RamAddress=Read8Bit(); Ack(); RamAddress+; bytes-;*RamAddress=Read8Bit();NoAck();Stop();void Display(void) /显示unsigned int i = 0;unsigned int temp,count; temp = Disdigitcount; P2 =temp;temp = Disbufcount;temp = Numtemp; P0 =temp; count+; if (count=4) count=0; void time1() interrupt 3 using 2 Display(); TH1 = (65535 - 2000)/256; TL1 = (65535 - 2000)%256;void main()TMOD = 0x15;TR1 = 1;EA = 1;ET1 = 1;Write24c02(write_data,0x00,3);DelayMs(200); R

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论