/**
******************************************************************************
* @file EEPROM_24LC64.c
* @author NuMicro MCU Software Team
* @version V1.01
* @date 7. Dec 2011
* @brief Õâ¸öµµ°¸Ìṩ¶Áд24LC64 EEPROMËùÐèÈÍÌ幦ÄÜ.
******************************************************************************
* @copyright
*
* Copyright (c) 2011 ÐÂÌƿƼ¼
*/
#include <stdio.h>
#include "MINI51.h"
#include "DrvGPIO.h"
#include "DrvSYS.h"
#include "DrvI2C.h"
/**
* @brief д³öÒ»¸öλԪ×é×ÊÁϵ½Ö¸¶¨µÄλַ
* @param address ҪдµÄλַ
* @param data ҪдÈëµÄ×ÊÁÏ
* @return -
*/
void Write_24LC64(uint32_t address, uint8_t data)
{
uint32_t i;
// SystemCoreClock = DrvSYS_GetHCLKFreq();
/* ´ò¿ªI2CÇÒÉ趨ʱÖÓËÙ¶ÈΪ100Kbsp */
DrvI2C_Open(100000);
/* ´«ËÍI2C START ѶºÅ */
DrvI2C_Ctrl(1, 0, 0, 0);
while ( DrvI2C_GetIntFlag ( ) == 0);//while (I2C->CON_BITS.SI == 0);
/* ËͳöwriteÃüÁî */
DrvI2C_WriteData (0xA0);//I2C->DATA = 0xA0;
DrvI2C_Ctrl(0, 0, 1, 0);
while ( DrvI2C_GetIntFlag ( ) == 0);//while (I2C->CON_BITS.SI == 0);
/* Ëͳö¸ßλԪλַ */
I2C->DATA = (address >> 8) & 0XFF;
DrvI2C_Ctrl(0, 0, 1, 1);
while (I2C->CON_BITS.SI == 0);
/* ËͳöµÍλԪλַ */
I2C->DATA = address & 0XFF;
DrvI2C_Ctrl(0, 0, 1, 1);
while (I2C->CON_BITS.SI == 0);
/* ´«ËÍ×ÊÁÏ */
I2C->DATA = data;
DrvI2C_Ctrl(0, 0, 1, 1);
while (I2C->CON_BITS.SI == 0);
/* ´«ËÍI2C STOPѶºÅ */
DrvI2C_Ctrl(0, 1, 1, 0);
while (I2C->CON_BITS.STOP== 1);
/* ¹Ø±ÕI2C */
DrvI2C_Close();
for (i = 0;i < 120000;i++);
}
/**
* @brief ´ÓÖ¸¶¨µÄλַ¶ÁÈ¡Ò»¸öλԪ×é×ÊÁÏ
* @param address Òª¶ÁµÄλַ
* @return »Ø´«¶Áµ½µÄ×ÊÁÏ
*/
uint8_t Read_24LC64(uint32_t address)
{
uint8_t TEMP;
//SystemCoreClock = DrvSYS_GetHCLKFreq();
/* ´ò¿ªI2CÇÒÉ趨ʱÖÓËÙ¶ÈΪ100Kbsp */
DrvI2C_Open(100000);
/* ´«ËÍI2C START ѶºÅ */
DrvI2C_Ctrl(1, 0, 1, 0);
while (I2C->CON_BITS.SI == 0);
/* ËͳöwriteÃüÁî */
I2C->DATA = 0XA0;
DrvI2C_Ctrl(0, 0, 1, 0);
while (I2C->CON_BITS.SI == 0);
/* Ëͳö¸ßλԪλַ */
I2C->DATA = (address >> 8) & 0XFF;
DrvI2C_Ctrl(0, 0, 1, 1);
while (I2C->CON_BITS.SI == 0);
/* ËͳöµÍλԪλַ */
I2C->DATA = address & 0XFF;
DrvI2C_Ctrl(0, 0, 1, 0);
while (I2C->CON_BITS.SI == 0);
/* ´«ËÍI2C STOPѶºÅ */
DrvI2C_Ctrl(0, 1, 1, 0);
while (I2C->CON_BITS.STOP == 1);
/* ´«ËÍI2C RESTART ѶºÅ */
DrvI2C_Ctrl(1, 0, 1, 0);
while (I2C->CON_BITS.SI == 0);
/* ËͳöreadÃüÁî */
I2C->DATA = 0XA1;
DrvI2C_Ctrl(0, 0, 1, 1);
while (I2C->CON_BITS.SI == 0);
/* ¶ÁÈ¡×ÊÁÏ */
I2C->DATA = 0XFF;
DrvI2C_Ctrl(0, 0, 1, 0);
while (I2C->CON_BITS.SI == 0);
TEMP = I2C->DATA;
/* ´«ËÍI2C STOPѶºÅ */
DrvI2C_Ctrl(0, 1, 1, 0);
while (I2C->CON_BITS.STOP == 1);
/* ¹Ø±ÕI2C */
DrvI2C_Close();
return TEMP;
}