⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 24lc256.c

📁 24LC256的C51驱动程序, 采用8052系列单片机
💻 C
字号:
#include <reg52.h>
#include <stdio.h>
#include <intrins.h>
#include "24lc256.h"

sbit sda=P1^0; //SDA--P1.0   SCL--P1.1   A0-GND  A1-GND  A2-GND  EP-GND 
sbit scl=P1^1;

void outs(unsigned char datouts)
{ unsigned  char  datouts_copy_rlc=datouts;
  int i;
  sda=1;
  scl=1;
  _nop_();  
  sda=0;
  _nop_();
  scl=0;  //起始条件
  for( i=0;i<8;i++)  
 {if ((datouts_copy_rlc&0x80)==0) sda=0;
  else sda=1;
  _nop_();
  scl=1;
  _nop_();
  scl=0;
  datouts_copy_rlc<<=1;}
  sda=1;
  _nop_();
  scl=1;
  _nop_();
  scl=0;
 }    
 
void out(unsigned char datout)
{ unsigned  char  datout_copy_rlc=datout;
  int j;
  for(j=0;j<8;j++)  
 {if ((datout_copy_rlc&0x80)==0x00) sda=0;
  else sda=1;
  _nop_();
  scl=1;
  _nop_();
  scl=0;
  datout_copy_rlc<<=1;}
  sda=1;
  _nop_();
  scl=1;
  _nop_();
  scl=0;
}

unsigned char in()
{unsigned char datin=0x00;
 int i;
 sda=1;
 for(i=0;i<8;i++)
 { scl=0;
   _nop_();
   scl=1;   
   datin<<=1;   
   datin^=sda;
  }
  scl=0;
 return datin;
 }
 
 void stop()
{ sda=0;
  _nop_();
  _nop_();
  scl=1;
  _nop_();   
  _nop_();   
  sda=1;
}    
//写EEPROM
void byte_write(unsigned char w_control,unsigned char addr_high,unsigned char addr_low,unsigned char d_write)
{ outs(w_control);
  out(addr_high);
  out(addr_low);
  out(d_write);
  stop();}
//读EEPROM
unsigned char byte_read(unsigned char w_control,unsigned char r_control,unsigned char addr_high,unsigned char addr_low)
{unsigned char data_show;
  outs(w_control);
  out(addr_high);
  out(addr_low);    
  outs(r_control);
  data_show=in();
  stop();
  return data_show;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -