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

📄 i2ceeprom.c

📁 国外一个牛网站!!i2ceeprom avr c得应用程序。
💻 C
字号:
/*! \file i2ceeprom.c \brief Interface for standard I2C EEPROM memories. */
//*****************************************************************************
//
// File Name	: 'i2ceeprom.c'
// Title		: Interface for standard I2C EEPROM memories
// Author		: Pascal Stang - Copyright (C) 2003
// Created		: 2003.04.23
// Revised		: 2003.04.23
// Version		: 0.1
// Target MCU	: Atmel AVR series
// Editor Tabs	: 4
//
// This code is distributed under the GNU Public License
//		which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************

#include <avr/io.h>
#include <avr/interrupt.h>

#include "i2c.h"
#include "i2ceeprom.h"

// Standard I2C bit rates are:
// 100KHz for slow speed
// 400KHz for high speed

// functions
void i2ceepromInit(void)
{
	// although there is no code here
	// don't forget to initialize the I2C interface itself
}

u08 i2ceepromReadByte(u08 i2cAddr, u32 memAddr)
{
	u08 packet[2];
	// prepare address
	packet[0] = (memAddr>>8);
	packet[1] = (memAddr&0x00FF);
	// send memory address we wish to access to the memory chip
	i2cMasterSendNI(i2cAddr, 2, packet);
	// retrieve the data at this memory address
	i2cMasterReceiveNI(i2cAddr, 1, packet);
	// return data
	return packet[0];
}

void i2ceepromWriteByte(u08 i2cAddr, u32 memAddr, u08 data)
{
	u08 packet[3];
	// prepare address + data
	packet[0] = (memAddr>>8);
	packet[1] = (memAddr&0x00FF);
	packet[2] = data;
	// send memory address we wish to access to the memory chip
	// along with the data we wish to write
	i2cMasterSendNI(i2cAddr, 3, packet);
}

⌨️ 快捷键说明

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