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

📄 24c02程序设计.txt

📁 24C02EEPROM存储
💻 TXT
字号:
#include<at89x51.h>
#include<intrins.h>
#include<absacc.h>
#include<string.h>
#define unchar unsigned char
#define uint unsigned int
sbit SCL=P1_6;
sbit SDA=P1_7;
sbit K0=P1_3;
unchar E24_State;
uchar COM XBYTE[0xe100]8155命令口地址
void sdelay()
{
uint x=200;
while(--x);
}
void sdelay1()
{
uint x=1;
while(--x);
}
void time10ms(char num)
{
uint lp;
uchar i;
for(i=0;i<=num;i++)
{lp=200;while(--lp);
}}
void start()开始条件函数
{
SCL=0;SDA=1;SCL=1;sdelay1();SDA=0;sdelay1();SCL=0;}
void endd()//结束条件函数
{
SCL=0;SDA=0;SCL=1;sdelay1();SDA=1;sdelay1();SCL=0;}
char rbyte(char ask_flag)//读8BIT函数
{
uchar x,lp;
x=0;
for(lp=0;lp<8;lp++)
{
SCL=0;
SDA=1;//输入前先将SDA置“1”
sdelay1();
SCL=1;
x=(x<<1)|SDA;
}
SCL=0;
if(ask_flag)SDA=0;
else SDA=1;
SCL=1;
return(x);
}
void wbyte(char p)//写8bit函数
{
uchar i;
for(i=0;i<8;i++)
{
SCL=0;
SDA=p&0x80;
p<<=1;
SCL=1;
}
SCL=0;
SDA=1;
SCL=1;
i=255;
while(SDA&&--i)//等待从机应答
if(!i)
E24_State|=0x1;
SCL=0;
}
char read_byte(char adr)//读一个字节函数
{
uchar x;
start();
wbyte(0xa0);
wbyte(adr);
start();
wbyte(0xa1);
x=rbyte(0);
endd();
return(x);
}
void write_byte(char adr,char num)//写1个字节函数
{
start();
wbyte(0xa0);
wbyte(adr);
wbyte(num);
endd();
time10ms(0);
}
void disp()//显示函数省略
main()//主函数
{
uchar i;
SP=0x60;
PSW=0;
COM=0x03;//定义8155命令字,PA,PA输出,PC口输入
while(1)
{
if(K0)//K0开关为高,写
{
write_byte(0x10,0x41);//向0x10,0x11,0x12单元分别写入0x41,0x21,0x86
write_byte(0x11,0x21);
write_byte(0x12,0x86);
memset(buf,0,6);//设置显示“000000”
}
else
{
i=read_byte(0x10);//K0开关为低,读出0x10,0x11,0x12,三个单元内容
buf[0]=(i&0xf0)>>4;
buf[1]=i&0xf;
i=read_byte(0x11);
buf[2]=(i&0xf0)>>4;
buf[3]=i&f;
i=read_byte(0x12);
buf[4]=(i&0xf0)>>4;
buf[5]=i&0xf;}
for(i=0;i<20;i++)
disp(0;//显示
}
}
{
start();
}

⌨️ 快捷键说明

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