📄 24lcxx.c
字号:
#include<reg51.h>
#include<math.h>
#define uint unsigned int
#define uchar unsigned char
/*****************24LC65******************************/
sbit SISO2465=P0^1;
sbit CLOCK2465=P0^0;
/*************24lc65读写程序*********************/
void dlms5000(uint i) //382=5ms; 75=1ms
{ uint i1;
for(i1=0;i1<i;i1++){}
}
void dlms(void)
{ uchar i1;
for(i1=1;i1<200;i1++){}
}
/***************************************
NAME:INITIALIZING 24LC65
AIM: STARTING AND STOPPING 24LC65
****************************************/
void st24LC65(void)
{
SISO2465=1;
CLOCK2465=1;
dlms();
SISO2465=0;
CLOCK2465=0;
}
void stop24LC65(void)
{
CLOCK2465=0;
SISO2465=0;
dlms();
CLOCK2465=1;
SISO2465=1;
}
/***************************************
NAME:WRITING 24LC65
AIM :WRITING PARAMETERS THAT NEED SAVE
FOREVER.
****************************************/
void wshuju(uchar a)
{
uchar i;uint b,f;
f=0;
b=a;
for(i=0;i<8;i++)
{
b=b*2;
f=b&0x0100;
f=f/0x0100;
CLOCK2465=0;
SISO2465=f;
dlms();
dlms();
CLOCK2465=1;
}
CLOCK2465=0;
dlms();
CLOCK2465=1;
CLOCK2465=0;
}
uchar rshuju()
{
uint a, e;uchar i;
a=0; e=0;
for(i=0;i<8;i++)
{
CLOCK2465 =1;
e=SISO2465;
CLOCK2465=0;
a=(a<<1)+e;
e=0;
}
dlms();
CLOCK2465 =1;
CLOCK2465=0;
i=(uchar)a;
return(i);
}
void w24lc65sj(uint addr,uchar a,uchar chipselect) //chipselect=0xa0;
{ uchar idata taddl,taddh;
taddl=addr%256;
taddh=addr>>8;
st24LC65();
wshuju(chipselect);
wshuju(taddh);
wshuju(taddl);
wshuju(a);
stop24LC65();
dlms5000(600);
}
uchar r24lc65sj(uint addr,uchar chipselect)
{ uchar a;
uchar idata taddl,taddh;
EA=1;
taddl=addr%256;
taddh=addr>>8;
st24LC65();
wshuju(chipselect);
wshuju(taddh);
wshuju(taddl);
stop24LC65();
st24LC65();
wshuju(chipselect+1);
a=rshuju();
stop24LC65();
EA=1;
return(a);
}main()
{char i,j;
w24lc65sj(0x00,0x55,0xa0);
i=r24lc65sj(0x00,0xa0);
j=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -