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

📄 eeprom.c

📁 单片机键值测定程序
💻 C
字号:
//-------------------------------------------------------------------------
// 5.1 Channel Volume Control
// COPYRIGHT (C) 2002, Enbia Technology Inc.
// Target: 89c2051
// AUTHOR: STEVEN LUO
//
// Revision History:
// 2002/7/26 - Original Version
//
//-------------------------------------------------------------------------
#include "define.h"
#include "global.h"
#include <regX52.H>
#include <intrins.h>

#define READ		0x01
#define	WRITE		0xfe
#define EEPROM 		0xa0
//#define uint  unsigned int
//#define uchar unsigned char

char Addr,Val;
//uchar Val,Addr;

extern bit Write_I2C_Byte(uchar); 
uchar Read_I2C_Byte(void); 
extern void Send_I2C_Start(void);
extern void Send_I2C_Stop(void);
extern void SendAcknowledge(bit ack);
    uchar add=0;
//-------------------------------------------------------------------------
// Write_EEPROM
//-------------------------------------------------------------------------
    void Write_EEPROM(uchar Addr, uchar Val){

  	Send_I2C_Start();     			// Start I2C communication
ddg:
  	if (Write_I2C_Byte(add & WRITE))

    {add+=1;if(add==0xff)return;goto ddg;}

/*
   		Send_I2C_Stop();	ttt=10;		// Second NACK -- send STOP condition and return CDB_ERROR
		return;						// ErrorVal  
  	}

	// Write the MAP Address Vale //
	if (Write_I2C_Byte(Addr))

   {
		Send_I2C_Stop();ttt=11;			// Second NACK -- send STOP condition and return CDB_ERROR
		return;						// ErrorVal
	}

	// Write the Val Vale 
	if (Write_I2C_Byte(Val))
	
	{
		Send_I2C_Stop();ttt=12;			// Second NACK -- send STOP condition and return CDB_ERROR
		return;						// ErrorVal
    }*/

	Send_I2C_Stop();				// Stop and return

	
}

//-------------------------------------------------------------------------
//   Read_EEPROM
//-------------------------------------------------------------------------
char Read_EEPROM(uchar Addr){
char temp;
  	
  	Send_I2C_Start();                // Start I2C communication
TVB4:
  	if (Write_I2C_Byte(EEPROM & WRITE)) goto TVB4;
/*	
	{
   		Send_I2C_Stop();			// Second NACK -- send STOP condition and return CDB_ERROR
		return 0xff;				// ErrorVal
  	}
*/  
	// Write the MAP Address Vale //
TVB5:
	if (Write_I2C_Byte(Addr)) goto TVB5;
/*	
	{
		Send_I2C_Stop();			// Second NACK -- send STOP condition and return CDB_ERROR
		return 0xff;				// ErrorVal
    }
*/
	Send_I2C_Stop();

  	Send_I2C_Start();                // Start I2C communication
TVB6:
  	if (Write_I2C_Byte(EEPROM | READ)) goto TVB6;
/*	
	{
   		Send_I2C_Stop();			// Second NACK -- send STOP condition and return CDB_ERROR
		return 0xff;				// ErrorVal
  	}
*/
	temp=Read_I2C_Byte();			// Read the E2 Val Vale 
	SendAcknowledge(1);
	Send_I2C_Stop();				// Stop and return

	return temp;
} 



⌨️ 快捷键说明

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