epr.c

来自「STM32F10xx的LCD驱动源码」· C语言 代码 · 共 79 行

C
79
字号
#include "stm32f10x_lib.h" 
#include "I2C.h"

#define EEPROM_READ_ADDRESS    0xA1
#define EEPROM_WRITE_ADDRESS   0xA0


void EEPR_Write_Commend(u8 Terminal_Address,u8* Buffer,u8 Total_Bytes); 
void EEPR_Read_Commend(u8 DATA_Address,u8* Buffer_Address,u8 Total_Bytes);
u32 EEPR_ByteRead_Commend(u8 DATA_Address);
extern void Delay_XMs(u8 Dly);
/**********************************************************************************
Function name:
      Funtion:
        input:
       output:
         note:
*********************************************************************************/
void EEPR_Write_Commend(u8 Terminal_Address,u8* Buffer,u8 Total_Bytes)
{
  u8 y=0;
    I2C_Start();   
    Address_Sending(Transmitter,0,EEPROM_WRITE_ADDRESS, Addring_Mode_7);  
    //send address byte to be write to
    I2C_SendByte(Terminal_Address); 
    while(y<Total_Bytes)
    {
     I2C_SendByte(*(Buffer++)); 
     y++;
      Delay_XMs(30);
    }
     I2C_Stop_Write();
  
}
/**********************************************************************************
Function name:EEPR_Read_Commend
      Funtion:read data from the  EEProm`s appointed address.
        input:   DATA_Address: Target address you may read from
              *Buffer_Address:buffer for the read data 
                  Total_Bytes:How many bytes you want to read from the eeprom.
       output:none
         note:
*********************************************************************************/
void EEPR_Read_Commend(u8 DATA_Address,u8* Buffer_Address,u8 Total_Bytes)
{ 
    u8 x=0;
  /****************Send wanted data`s address first *************************/  
    I2C_Start();

    Address_Sending(Transmitter,0,EEPROM_WRITE_ADDRESS, Addring_Mode_7);
    I2C_SendByte(DATA_Address)   ;
 /***************read the wanted data*****************************************/   
    I2C_Start(); 
    Address_Sending(Reciver,0,EEPROM_READ_ADDRESS, Addring_Mode_7);
    while (x<Total_Bytes)
     {
      *(Buffer_Address++)= I2C_ReciveByte( ); 
      x++;
      Delay_XMs(30);
    }
    I2C_Stop_Read();
}


u32 EEPR_ByteRead_Commend(u8 DATA_Address)
{
    u32 x=0;
  /****************Send wanted data`s address first *************************/  
    I2C_Start();   
    Address_Sending(Transmitter,0,EEPROM_WRITE_ADDRESS, Addring_Mode_7);
    I2C_SendByte(DATA_Address)   ;
 /***************read the wanted data*****************************************/   
    I2C_Start(); 
    Address_Sending(Reciver,0,EEPROM_READ_ADDRESS, Addring_Mode_7);
      x= (u32) I2C_ReciveByte( );
      Delay_XMs(30);
   
    I2C_Stop_Read();
}

⌨️ 快捷键说明

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