PIC18Fxx单片机内部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 ;
//创建接受数组
#pragma idata bigsata
unsigned char out[20] ;
#pragma idata
void eebf( void) //将数据存EEPROMggon
{
if(j==1)
{
char adr=0x00;
unsigned char i;
EECON1bits.EEPGD=0; //选EEPROMggon
EECON1bits.CFGS=0; //选存取
INTCONbits.GIE=0;
EECON1bits.WREN=1; //执行写周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)
{
}
}