//EEPROM4.C
//EEPROM Interrupt Demo
//PIC16F628 EEPROM size 128 00-7Fh
//PIC16F648A EEPROM size 256 00-FFh
//#include <16F628.h>
#include <16F648A.h>
#use delay(clock=4000000)
#fuses XT,PUT,BROWNOUT,MCLR,NOWDT,NOPROTECT,NOLVP
#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1)
int EEPROMflag;
#INT_EEPROM
void EEPROM_done(void)
{
EEPROMflag=1;
}
void DumpEEPROM(void)
{
int vol,i,j,k;
k=0;
for(i=0; i<8; ++i)
{
printf("%4X: ",k); //EEPROM in hex
for(j=0;j<=15;++j)
{
printf( "%2X ",read_eeprom(i*16+j));
if(j==7)
printf("- ");
}
printf("\r\n");
k+=16;
}
printf("\r\n");
}
//*** MAIN ***
main()
{
int i,Err;
long Cn;
delay_ms(200); //Delay for Hardware ready
printf("*** EEPROM DEMO4***\r\n");
enable_interrupts(GLOBAL);
enable_interrupts(INT_EEPROM);
for(i=0;i<128;i++)
{
Cn=0;
Err=0;
EEPROMflag=0;
write_eeprom(i,i);
while(EEPROMflag==0)
{
Cn++;
if(Cn==3)
{
Err=1;
break;
}
}
if(Err==1)
{
printf("write EEPROM Error address %2X\r\n",i);
break;
}
}
DumpEEPROM();
while(1); //Loop here
}