|
/*=============================================================================
访问PIC16F877A片内EEPROM,运行程序:
Begin Test -> LED0亮,
EEPROM Test OK-> LED7亮,
Write&Read OK -> LED0/2/4/6亮。
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
// MPLAB IDE V7.11 + CCS C3.18
// Access 16F877A internal EEPROM for MCD2-demo
//
// by LW7807@163.com
// 2005/06/22
///////////////////////////////////////////////////////////////////////////////
#include <16F877A.h> // PIC16F877 header file
#use delay(clock=4000000) // for 4Mhz crystal
#fuses XT, NOWDT, NOPROTECT, NOLVP // for debug mode
#define EEPROM_SIZE 256
////////////////////////////////////////////////////////////// eeprom_test()
//
int8 eeprom_test(void)
{
int16 i;
// write 0x55 test
for(i=0; i<EEPROM_SIZE; ++i)
{
write_eeprom(i, 0x55);
}
for(i=0; i<EEPROM_SIZE; ++i)
{
if(0x55 != read_eeprom(i)) return 0;
}
// write 0xaa test
for(i=0; i<EEPROM_SIZE; ++i)
{
write_eeprom(i, 0xaa);
}
for(i=0; i<EEPROM_SIZE; ++i)
{
if(0xaa != read_eeprom(i)) return 0;
}
// write 0
for(i=0; i<EEPROM_SIZE; ++i)
{
write_eeprom(i, 0x00);
}
return 0xff;
}//end eeprom_test()
/*===========================================================================*/
void main(void)
{
// begin test
output_high(PIN_C0);
// test internal eeprom
if(0 != eeprom_test())
{
output_high(PIN_C7);
delay_ms(1000);
}
// write 24c02
write_eeprom(0, 0x55);
// read 24c02
output_c(read_eeprom(0));
}//end main()
|
|