#define EEPMASS2 0x56 //密码钥匙2
#define EEPADDR 0x4000 //eep地址起始
void eeprom_read(U16 u16Addr, U8 *pdatas, U8 len)
{
U8 *eep=(U8 *)u16Addr
U8 j
for(j=0j<lenj++)
{
pdatas[j]=eep[j]
}
}
void eep_word_write(U16 u16Addr, U8 *pdatas, U8 len)
{
U8 *eep=(U8*)u16Addr
U8 j
FLASH_DUKR=EEPMASS1 //锁1密钥
FLASH_DUKR=EEPMASS2 //锁2密钥
while(!(FLASH_IAPSR&0x08))//等待解密就绪
DISABLE_MAC_INTERRUPTS()
FLASH_CR2 |= 0x40//
FLASH_NCR2 &= ~0x40 //设置字编程
for(j=0j<lenj++)
{
eep[j] = pdatas[j]
}
while(!(FLASH_IAPSR&0x04))
FLASH_IAPSR &=0xf7 // off the eeprom program
ENABLE_MAC_INTERRUPTS()
}
void EEPROM_erasure(UINT16 number) //清除 *** 作函数{
UINT16 *erase
//erase = (unsigned char*)(0x400+number)
erase = (UINT16*)(number)
*erase = 0xff
DisableInterrupts
while(!(ECLKDIV & 0x80))
{}
while(!(ESTAT & 0x80))
{}
while(!(EPROT & 0x80))
{}
ECMD = 0x40
ESTAT |= 0x80
while(!(ESTAT & 0x40))
{}
EnableInterrupts
}
void EEPROM_write(UINT16 code,UINT16 number) //写 *** 作
{
UINT16 *eeaddr //对EEPROM进行写 *** 作时的地址
/*
allow_calibration = 0
calibration = 1
*/
DisableInterrupts
eeaddr = (UINT16*)(number)
while(!(ECLKDIV & 0x80)) //判断ECLKDIV是否被写入,是向下进行,否原地等待?
{}
while(!(ESTAT & 0x80)) //判断缓冲区是否准备好,准备好则向下进行,没有准备好则原地等待?
{}
while(!(EPROT & 0x80)) //判断EEPROM是否允许被写入,允许向下进行,不允许则原地等待?
{}
*eeaddr= code
ECMD = 0x20
ESTAT |= 0x80
while(!(ESTAT & 0x40)) //判断EEPROM是否被写入,是向下进行,否原地等待;
{}
EnableInterrupts
return
}
*/
UINT16 EEPROM_read(UINT16 add) //读 *** 作
{
UINT16 *erase
UINT16 m
calibration = 0
DisableInterrupts
erase = (UINT16*)(add)
m = *erase
EnableInterrupts
return m
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)