AT24C02存储器

一、原理图

在这里插入图片描述

二、器件地址和写字节

器件地址
AT24C02为2k的,对应下面的地址(A0~2均接地为0),读这个存储器最低位为1,写为0(读地址0xa1,写地址0xa0
在这里插入图片描述
写字节
流程:开始函数-》发送器件地址-》等待应答-》发送将数据地址(即要将数据写入在哪)-》等待应答-》发送要写入的数据-》等待应答-》停止函数
在这里插入图片描述
随机读
流程:开始-》发送器件地址(写0xa0)-》等待应答-》字节地址(指定要读哪里的数据)-》等待应答-》开始-》发送器件地址(0xa1)-》等待应答-》读数据-》停止
在这里插入图片描述

三、注意事项

补充蓝桥杯官网提供的驱动代码
在这里插入图片描述
写入时间需要时间,要延时
在这里插入图片描述

四、具体代码

练习内容:往AT24C02写入数据,读取并用数码管显示数据

#include "reg52.h"
#include "iic.h"
#include "smg.h"

unsigned char dat;
code unsigned char Seg_Table[] = { 
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,  
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; 

void Delayxms(unsigned int t)	//@12.000MHz
{
	while(t--)
	{
		unsigned char data i, j;
		i = 12;
		j = 169;
		do
		{
			while (--j);
		} while (--i);
	}
}

void initsystem()
{
	hc573(4);
	P0=0xff;
	hc573(5);
	P0=0x00;
	AT24C02_write(0x01,222);
	Delayxms(10);
}

void smgshow()
{
	smgshow_bit(0,0xff);
	Delayxms(2);
	smgshow_bit(1,0xff);
	Delayxms(2);
	smgshow_bit(2,0xff);
	Delayxms(2);
	smgshow_bit(3,0xff);
	Delayxms(2);
	smgshow_bit(4,0xff);
	Delayxms(2);
	smgshow_bit(5,Seg_Table[dat/100]);
	Delayxms(2);
	smgshow_bit(6,Seg_Table[dat/10%10]);
	Delayxms(2);
	smgshow_bit(7,Seg_Table[dat%10]);
	Delayxms(2);
	smgshow_all(0xff);
}
void main()
{
	initsystem();
	while(1)
	{
		dat=AT24C02_read(0x01);
		smgshow();
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值