打印
[程序源码]

合泰单片机EEPROM编程实例

[复制链接]
1974|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ljq673091|  楼主 | 2017-5-16 10:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
以下为合泰单片机EEPROM编程实例,基本上适用于大部分合泰的MCU

.C文件

/***********************************************************
**   Function : fun_eeprom_Write
**   INPUT    : lu8v_addr;lu8v_data
**   OUTPUT   : none
**   NOTE     : none
***********************************************************/

void fun_eeprom_Write(u8 lu8v_addr, u8 lu8v_data)
{

        _eea = lu8v_addr;
        _eed = lu8v_data;

        #if(mac_eeprom_type == mac_eeprom_Short)

        _bp     = 1;
        _mp1    = 0x40;
        _iar1  |= 0x08;
        _iar1  |= 0x04;
        while(_iar1 & 0x04);
        _iar1        &=        0xf7;                                //disable WREN        
        _bp     = 0;        

        #endif        
//============================================================        
        #if(mac_eeprom_type == mac_eeprom_Long)

        _mp1l = 0x40;
        _mp1h = 1;
        _iar1        |=        0x8;                                //enable WREN
        _iar1        |=        0x4;                                //active write
        while(_iar1 & 0x04);                //wait write end
        _iar1        &=        0xf7;                                //disable WREN        

        #endif
}


/***********************************************************
**   Function : fun_eeprom_Read
**   INPUT    : lu8v_addr
**   OUTPUT   : lu8v_eeprom_byte
**   NOTE     : none
***********************************************************/

u8 fun_eeprom_Read(u8 lu8v_addr)
{
        u8 lu8v_eeprom_byte;
               
        _eea = lu8v_addr;


        #if(mac_eeprom_type == mac_eeprom_Short)

        _bp     = 1;
        _mp1    = 0x40;
        _iar1  |= 0x02;
        _iar1  |= 0x01;
               
        while(_iar1 & 0x01);
        lu8v_eeprom_byte = _eed;               
        _iar1  &= 0xfd;  
        
        #endif
//============================================================        
        #if(mac_eeprom_type == mac_eeprom_Long)

        _mp1l = 0x40;
        _mp1h = 1;
        _iar1 |=0x2;                                //enable RDEN
        _iar1 |=0x1;                                //active READ
        while(_iar1 & 0x01);                //wait read end
        lu8v_eeprom_byte = _eed;
        _iar1 &=        0xfD;                                //disable RDEN        

        #endif

        return lu8v_eeprom_byte;        

}



.h文件

#ifndef _eeprom_h_
#define _eeprom_h_

/********************************************************************
NOTE:無需修改
********************************************************************/
#define        mac_eeprom_Long                1
#define        mac_eeprom_Short        0
#define mac_eeprom_type                mac_Eeprom_Short

/********************************************************************
Function:        
********************************************************************/
void fun_eeprom_Write(u8 lu8v_addr, u8 lu8v_data);
u8 fun_eeprom_Read(u8 lu8v_addr);

#endif

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

9

帖子

0

粉丝