PIC 1508 EEPROM

EEPROM读、擦、写。

unsigned int eeprom_read(unsigned int address)
{
//    GIE  =0;
    unsigned int data = 0;
    PMCON1bits.CFGS = 0;//访问闪存程序存储器    
    PMADRH = address / 256;
    PMADRL = address % 256;//写入地址
    PMCON1bits.RD = 1;//启动读操作
    _nop();
    _nop();  
    data = PMDATH;
    data = data << 8;
    data+ = PMDATL;
//  GIE = 1;
    return data;
}

 

 

void eeprom_erase(unsigned int address)
{
//    GIE=0;
    PMCON1bits.CFGS = 0;//访问闪存程序存储器
    PMADRH = address / 256;
    PMADRL = address % 256;//擦除地址 
    PMCON1bits.FREE = 1;//选择擦除操作
    PMCON1bits.WREN = 1;//写使能
    PMCON2 = 0x55;
    PMCON2 = 0xAA;//解码
    PMCON1bits.WR = 1;//开始擦除
    _nop();
    _nop();
    while(PMCON1bits.WR);//等待擦除完成,硬件自动清零
    PMCON1bits.WREN = 0;
//    GIE = 1;
}

void eeprom_write(unsigned int address,unsigned int data)
{
//    GIE = 0;
    PMCON1bits.CFGS = 0;//访问闪存程序存储器
    PMADRH = address / 256;
    PMADRL = address % 256;//写入地址
    PMCON1bits.FREE = 0;//选择写操作
    PMCON1bits.LWLO = 1;//仅装入写锁存器
    PMCON1bits.WREN = 1;//使能写操作
    PMDATH = data / 256;
    PMDATL = data % 256;//装入数据0X308
    PMCON1bits.LWLO = 0;//将锁存器内容写入闪存
    PMCON2 = 0x55;
    PMCON2 = 0xAA;//解码
    PMCON1bits.WR = 1;
    _nop();
    _nop();
    while(PMCON1bits.WR);//等待擦除完成,硬件自动清零
    PMCON1bits.WREN = 0;
//    GIE = 1;    
}

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值