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

📄 at24c64.c

📁 Keil C51完整的128X64LCD显示的电子打铃仪代码,内含DS1302X5045等操作代码
💻 C
字号:

#include "Config.h"

sbit ISDA=P2^6;
sbit ISCL=P2^7;

uint8 c;
bit ack;

bit EEPROMByteWrite0(uint16 addr,uint8 value);
uint8 EEPROMByteRead0(uint16 addr1);

void I2cSentByte();
void I2cStart(void);
void I2cStop(void);
extern void    _nop_ (void);

bit EEPROMByteWrite0(uint16 addr,uint8 value)
{
	I2cStart();
	c=0xa0;
	I2cSentByte();
	if (ack==0)
		return(0);
	c=addr>>8;	
	I2cSentByte();
	if (ack==0)
		return(0);
	c=addr;	
	I2cSentByte();
	if (ack==0)
		return(0);
	c=value;	
	I2cSentByte();
	if (ack==0)
		return(0);
	I2cStop();
	Delay1(50);
	return(1);
}

uint8 EEPROMByteRead0(uint16 addr1)
{
	uint8 bytedata,j;
	I2cStart();
	c=0xa0;
	I2cSentByte();
	if (ack==0)
		return(0);
	c=addr1>>8;	
	I2cSentByte();
	if (ack==0)
		return(0);
	c=addr1;	
	I2cSentByte();
	if (ack==0)
		return(0);
	I2cStart();
	c=0xa1;
	I2cSentByte();
	if (ack==0)
		return(0);
	ISDA=1;
	for (j=0;j<8;j++)
	{	
		_nop_();
		ISCL=0;
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		ISCL=1;
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		bytedata<<=1;
		if (ISDA) 
			bytedata|=0x01;
		_nop_();
		_nop_();
		
	}
	ISCL=0;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	ISCL=1;
	I2cStop();
	return (bytedata);
}

void I2cStart(void)
{
	ISDA=1;
	ISCL=1;
	_nop_();
	_nop_();
	_nop_();
	ISDA=0;
	_nop_();
	_nop_();
	_nop_();
	ISCL=0;
	_nop_();
	_nop_();
}

void I2cStop(void)
{
	ISDA=0;
	ISCL=1;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	ISDA=1;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	ISCL=0;
}

void I2cSentByte()
{
	data uint8 temp1,temp2;
	for(temp1=0;temp1<8;temp1++)
	{
		temp2=c &0x80;
		if(temp2==0x80) 
			ISDA=1;
		else 
			ISDA=0;
		c<<=1;
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		ISCL=1;
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		ISCL=0;
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		
	}
	_nop_();
	_nop_();
	ISDA=1;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	ISCL=1;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	if(ISDA==1)
		ack=0;
	else
		ack=1;
	ISCL=0;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	
}

⌨️ 快捷键说明

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