佔ROM資源超少的PIC内部 EEPROM讀寫程序
void eeprom_byte_wr(BYTE addr,BYTE data){
EEIF=0;
EEADR=addr;
EEDATA=data;
WREN=1; //Enable write
GIE=0;
EECON2=0x55;
EECON2=0xaa;
WR=1;//Start the write
while(!EEIF)CLRWDT();
EEIF=0;
WREN=0;
GIE=1;
}
BYTE eeprom_byte_rd(BYTE addr)
{
BYTE data;
EEADR=addr;
RD=1;//EE Read
data=EEDATA;
return(data);
} /*****************************************************************************/
void ee_write (unsigned charaddress,unsigned char eedata)
{ if ((EECR&(1<<EEWE))==0)
{ EEAR=address;
EEDR=eedata;
CLI();
EECR|=(1<<EEMWE);
EECR|=(1<<EEWE);
SEI();
}
}
/******************************************************************************/
unsigned charee_read(unsignedcharaddress)
{if ((EECR&(1<<EEWE))==0)
{EEAR=address;
EECR|=(1<<EERE);
return (EEDR);
}
}
页:
[1]