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

📄 eeprom.c

📁 ST7 Mcu eeprom setting and program sample for learning
💻 C
字号:
/******************************************************************************
COPYRIGHT 2003 STMicroelectronics
Source File Name : EEPROM.c 
Group            : IPSW,CMG-IPDF
Author           : MCD Application Team
Date First Issued: 11/03/2002
********************************Documentation**********************************
General Purpose - Contains source code for all the functions of EEPROM

********************************Revision History*******************************
_______________________________________________________________________________
Date :11/03/2002       Release:1.0 
Date :23/09/2003       Release:2.0         	   	   	      	       		        
                       1. Included necessary comments .
                       2. Changed the magic numbers to constant definitions 
                          present in EEPROM_hr.h.
                       3. Removed the functions which are changed to Macros.
Date :28/04/04         MISRA changes
******************************************************************************/

#include "ST7lib_config.h"                            /* Selection of device */
#include "EEPROM_hr.h"             /* Declaration of constants for magic nos */
#include "EEPROM.h"     /* Prototype definitions of EEPROM library functions */
/*-----------------------------------------------------------------------------
ROUTINE NAME : EEPROM_Read
INPUT        : *PtrToUsrBuffer- User address, where data has to be stored.
               NbOfBytes- Number of bytes user want to read from EEPROM memory.
               *PtrToE2Buffer- EEPROM memory address, from where data has to be 
               read.               
OUTPUT       : None.	       
DESCRIPTION  : Reads data from EEPROM memory and stores it in the user buffer. 
COMMENTS     : None
-----------------------------------------------------------------------------*/
#ifdef _COSMIC_        	       			    /* for COSMIC compiler   */
void EEPROM_Read (unsigned char * PtrToUsrBuffer, unsigned char NbOfBytes, 
                  @near unsigned char * PtrToE2Buffer)
{                  
    unsigned char Temp ; 
     
    EECSR &= EEPROM_DEFAULT;                       /* Read operation enabled */
    for (Temp = 0; Temp < NbOfBytes; Temp ++)
    {                 /* Data bytes from EEPROM memory stored in user buffer */
        (*(PtrToUsrBuffer+ Temp )) = (*(PtrToE2Buffer+ Temp ));
    }              
} 
#endif /* COSMIC */

#ifdef _HIWARE_			     		    /* for HIWARE Compiler   */
void EEPROM_Read (unsigned char * PtrToUsrBuffer, unsigned char NbOfBytes, 
                  unsigned char * far PtrToE2Buffer)
{                  
    unsigned char Temp ; 
    
    EECSR &= EEPROM_DEFAULT;                       /* Read operation enabled */
    for (Temp = 0; Temp < NbOfBytes; Temp ++)
    {                 /* Data bytes from EEPROM memory stored in user buffer */
        (*(PtrToUsrBuffer+ Temp )) = (*(PtrToE2Buffer+ Temp ));
    }              
} 
#endif /* HIWARE */
/*-----------------------------------------------------------------------------
ROUTINE NAME : EEPROM_Write
INPUT        : *PtrToUsrBuffer- User address where data exists.
               NbOfBytes- Number of bytes user wants to write in EEPROM memory. 
               User can write upto 32 bytes.
               *PtrToE2Buffer- EEPROM memory address, where data will be 
               written. 
OUTPUT       : None.	       
DESCRIPTION  : Writes data bytes from user buffer to EEPROM memory. 
COMMENTS     : None.
-----------------------------------------------------------------------------*/
#ifdef _COSMIC_					      /* for COSMIC compiler */
void EEPROM_Write (unsigned char * PtrToUsrBuffer, unsigned char NbOfBytes, 
                   @near unsigned char * PtrToE2Buffer)
{                   
    unsigned char Temp ;     
    
    EECSR |=WRITE_ENABLE;                              /* Write mode enabled */
    EECSR &=PROG_ENABLE;              /* Programming status flag initialised */     
    for (Temp = 0; Temp < NbOfBytes; Temp ++)
    {               /* Data bytes written from user buffer into EEPROM latch */                    
        (*(PtrToE2Buffer + Temp)) =  (*(PtrToUsrBuffer+ Temp));             
    } 
}
#endif /* COSMIC */

#ifdef _HIWARE_					  /* For HIWARE Compiler   */
void EEPROM_Write (unsigned char * PtrToUsrBuffer, unsigned char NbOfBytes, 
                   unsigned char * far PtrToE2Buffer)
{                   
    unsigned char Temp ;               
    
    EECSR |=WRITE_ENABLE;                              /* Write mode enabled */
    EECSR &=PROG_ENABLE;     
    for (Temp = 0; Temp < NbOfBytes; Temp ++)
    {               /* Data bytes written from user buffer into EEPROM latch */
        (*(PtrToE2Buffer + Temp)) = (*(PtrToUsrBuffer+ Temp));                  
    } 
}
#endif  /* HIWARE */
/*-----------------------------------------------------------------------------
ROUTINE NAME : EEPROM_Programming
INPUT        : None.
OUTPUT       : PROG_COMPLETE- If programming is complete.
               PROG_PROGRESS- If programming is not complete. 	       
DESCRIPTION  : Starts writing data bytes from latches to EEPROM cells and 
               returns the programming status to user. 
COMMENTS     : This function can be looped, until the programming cycle is 
               complete.
-----------------------------------------------------------------------------*/
Prog_Status EEPROM_Programming (void)
{
    if ((EECSR & WRITE_ENABLE) )
    {           /* Programming status bit enabled, when write mode selected */
        if(!(EECSR & PROG_PROGRESS))
	     {
             EECSR |= PROG_PROGRESS;
	     }
        return (EEPROM_PROG_PROGRESS) ;     
    } 
    else          
    {                            /* Programming finished or not yet started */
        return (EEPROM_PROG_COMPLETE) ;
    }
        
}
 
/*** (c) 2003  ST Microelectronics ****************** END OF FILE ************/

⌨️ 快捷键说明

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