EEPROM读、擦、写。
文章图片
unsigned int eeprom_read(unsigned int address)
{
//GIE=0;
unsigned int data = https://www.it610.com/article/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;
}
【PIC 1508 EEPROM】
推荐阅读
- pic
- PIC定时器中断
- PIC 1508 TIM2的定时器使用
- 浅析PIC单片机定时器
- PIC 1508 TIM1的定时器门控的理解
- PIC 1508 WDT使用
- PIC 1508 TIM0的定时器使用
- PIC 1508 DAC使用
- PIC 1508 TIM1的定时器中断使用