PIC16F877A片内EEPROM c程序
扫描二维码
随时随地手机看文章
/*=============================================================================
访问PIC16F877A片内EEPROM,运行程序:
BeginTest->LED0亮,
EEPROMTestOK->LED7亮,
Write&ReadOK->LED0/2/4/6亮。
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
//MPLABIDEV7.11+CCSC3.18
//Access16F877AinternalEEPROM//
///////////////////////////////////////////////////////////////////////////////
#include<16F877A.h>//PIC16F877headerfile
#usedelay(clock=4000000)//for4Mhzcrystal
#fusesXT,NOWDT,NOPROTECT,NOLVP//fordebugmode
#defineEEPROM_SIZE256
//////////////////////////////////////////////////////////////eeprom_test()
//
int8eeprom_test(void)
{
int16i;
//write0x55test
for(i=0;i
write_eeprom(i,0x55);
}
for(i=0;i
if(0x55!=read_eeprom(i))return0;
}
//write0xaatest
for(i=0;i
write_eeprom(i,0xaa);
}
for(i=0;i
if(0xaa!=read_eeprom(i))return0;
}
//write0
for(i=0;i
write_eeprom(i,0x00);
}
return0xff;
}//endeeprom_test()
/*===========================================================================*/
voidmain(void)
{
//begintest
output_high(PIN_C0);
//testinternaleeprom
if(0!=eeprom_test())
{
output_high(PIN_C7);
delay_ms(1000);
}
//write24c02
write_eeprom(0,0x55);
//read24c02
output_c(read_eeprom(0));
}//endmain()