?? 24lc256.c
字號(hào):
#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;
}
//寫(xiě)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;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -