PIC18Fxx單片機內(nèi)部EEPROM存取程序
#include #include } eebf();
#include
#pragma config OSC=HS
#pragma config WDT = OFF
void eebf_d( void);
void eebf( void);
unsigned char out_bz[8];
unsigned char *buf_d ,*buf ;
int j=0 ;
//創(chuàng)建接受數(shù)組
#pragma idata bigsata
unsigned char out[20] ;
#pragma idata
void eebf( void) //將數(shù)據(jù)存EEPROMggon
{
if(j==1)
{
char adr=0x00;
unsigned char i;
EECON1bits.EEPGD=0; //選EEPROMggon
EECON1bits.CFGS=0; //選存取
INTCONbits.GIE=0;
EECON1bits.WREN=1; //執(zhí)行寫周ggon
buf=&out[0];
for(i=0;i<8;i++,buf++)
{
EECON1bits.RD=1;
EEADR=adr;
EEDATA=*buf;
EECON2=0X55;
EECON2=0XAA;
EECON1bits.WR=1;
while(EECON1bits.WR); //*wait for write complete*/
adr++;
}
INTCONbits.GIE=1;
EECON1bits.WREN=0;
}
void eebf_d( void) //讀EEPROMggon
{
char adr=0x00;
unsigned char i;
EECON1bits.CFGS=0;
EECON1bits.EEPGD=0;
INTCONbits.GIE=0;
for(i=0;i<8;i++,buf_d++)
{
EEADR=adr;
EECON1bits.RD=1;
while(EECON1bits.RD);
*buf_d=EEDATA;
EECON1bits.RD=0;
out_bz[adr]=*buf_d;
adr++;
}
INTCONbits.GIE=1;
}
void main(void)
{
TRISF=0X00;
PORTF=0X01;
while (1)
{
}
}