__no_init uchar read_datum@0x10;
//擦除EEPROM不能进中断,擦除flash时,CPU至少停止4ms
void EraseFlash(uint address)
{
FMUSR=0xa5;
//asm("LD FMSECH,R14");
//asm("CLR FMSECL");
FMSECH=address>>8;
FMSECL=0;
FMCON=0XA1;
// while(FMCON&0X01); //等待擦除完成
FMUSR=0X00;
}
//start_address工作寄存器为R14,R15;datum工作寄存器的R12,R13;
//number的工作寄存器为R11。
void FlashWritBytes(uint start_address,uchar *datum,uchar number)
{
asm("PUSH R9");
asm("LD FMUSR,#0A5H");
FMCON=0X50;
//asm("LD FMSECH,R14");
//asm("CLR FMSECL");
FMSECH=start_address>>8;
FMSECL=0;
for(;number>0;number--)
{
asm("LD R9,@R13");
asm("LDC @RR14,R9");
asm("INC R15");
asm("INC R13");
}
asm("LD FMUSR,#00H");
asm("POP R9");
}
uchar FlashReadByte(uint address)
{
asm("PUSH R9");
asm("LDC R9,@RR14");
asm("LD 0X10,R9");
asm("POP R9");
return(read_datum);
}转载
|