24C02读写操作程序设计实例,24C02 read / write process

电子说

1.3w人已加入

描述

24C02读写操作程序设计实例,24C02 read / write process

关键字:24C02读写操作程序设计实例

24C02读写操作程序设计实例
#define uchar unsigned char
#define uint unsigned int
#i nclude
#i nclude
#i nclude
sbit scl=P3^5;  //24c02 SCL
sbit sda=P3^4;  //24c02 SDA
sbit DOG=P1^7;  //狗
uchar x24c02_read(uchar address);  //从24c02的地址address中读取一个字节数据
void x24c02_write(uchar address,uchar info);  //向24c02的address地址中写入一字节数据info
void x24c02_init();   //24c02初始化子程序
void delay1(uchar x);
void flash();
void x24c01_init();
void start();
void stop();
void writex(uchar j);
uchar readx();
void clock();
void delay1(uchar x)
{
   uint i;
   for(i=0;i   DOG=~DOG;
}
void flash()
{
   uchar u;
   DOG=~DOG;
}
void x24c02_init()
{
   scl=1; flash(); sda=1; flash();
}
void start()
{
   sda=1; flash(); scl=1; flash(); sda=0; flash(); scl=0; flash();
}
void stop()
{
   sda=0; flash(); scl=1; flash(); sda=1; flash();
}
void writex(uchar j)
{
   uchar i,temp;
   temp=j;
   for (i=0;i<8;i++){
      temp=temp<<1; scl=0; flash(); sda=CY; flash(); scl=1; flash();
   }
   scl=0; flash(); sda=1; flash();
}
uchar readx()
{
   uchar i,j,k=0;
   scl=0; flash(); sda=1;
   for (i=0;i<8;i++){
      flash(); scl=1; flash();
      if (sda==1) j=1;
      else j=0;
      k=(k<<1)|j; scl=0;
   }
   flash(); return(k);
}
void clock()
{
   uchar i=0;
   scl=1; flash();
   while ((sda==1)&&(i<255))i++;
   scl=0; flash();
}
uchar x24c02_read(uchar address)
{
   uchar i;
   start(); writex(0xa0);
   clock(); writex(address);
   clock(); start();
   writex(0xa1); clock();
   i=readx(); stop();
   delay1(10);
   return(i);
}
void x24c02_write(uchar address,uchar info)
{
   EA=0;
   start(); writex(0xa0);
   clock(); writex(address);
   clock(); writex(info);
   clock(); stop();
   EA=1;
   delay1(50);
}
 
 
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
评论(0)
发评论
zg2369 2022-08-23
0 回复 举报
http://house.china.com.cn/sousou/%25C6%25BD%25CC%25A8%252C%2B%25D3%25F1%25BA%25CD%25D3%25E9%25C0%25D6%25D3%25C3%25BB%25A7B2024.cN_54s.htm http://house.china.com.cn/sousou/%25C9%25CF%25CF%25C2%25B7%25D6%252C%2B%25C3%25E5%25B5%25E9%25B9%25FB%25B8%25D2%255F%25F6%25CE%25CA%25A4%25D3%25E9%25C0%25D6B2024.cN%252C%25C1%25F8%25D6%25DD%25D2%25BD%25B1%25A3_2s.htm http://house.china.com.cn/sousou/%25BA%25F3%25CC%25A8%252C%2B%25C0%25CF%25B0%25D9%25CA%25A4%25B5%25E7%25BB%25B0B2024.cN_26s.htm http://house.china.com.cn/sousou/%25CA%25D6%25BB%25FA%25D4%25DA%25CF%25DF%252C%2B%25C3%25E5%25B5%25E9%25C1%25FA%25CC%25DA%25BC%25AF%25CD%25C5B2024.cN%252C%25D6%25DB%25C9%25BD%25D2%25C6%25B6%25AF_2s.htm http://house.china.com.cn/sousou/VIP%252C%2B%25B9%25FB%25B8%25D2%25C0%25CF%25BD%25D6%25BB%25AA%25C4%25C9%25B9%25FA%25BC%25CA%25D3%25E9%25C0%25D6B2024.cN%252C%25D0%25CF%25CC%25A8%25B0%25EC%25CA%25C2%25B4%25A6_10s.htm 收起回复
  • 相关推荐

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分