#include<pic.h>
#include <htc.h>
__CONFIG(0x3B04);
//__EEPROM_DATA(0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F);
__EEPROM_DATA(0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0xFF);
//__EEPROM_DATA(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF);
#define uchar unsigned char
#define uint unsigned int
#define bitset(var,bitno)((var)|=1<<(bitno))
#define bitclr(var,bitno)((var)&=~(1<<(bitno)))
/*
static volatile unsigned char acc @ 0x20;
static volatile bit acc0 @ (unsigned)&acc*8+0;
static volatile bit acc7 @ (unsigned)&acc*8+7
*/
#define key0 RA0
#define key1 RA1
#define key2 RA2
void Dlms(uint z){
uint i,a;
for(a=z;a>0;a--)
for(i=110;i>0;i--);
}
void Port_init(){
ANSEL=0x00; //0 = Digital I/O. Pin is assigned to port or special function.
CMCON=0x07; //CM2:CM0 = 111 Comparator Off (Lowest power)
TRISA=0x00;
PORTA=0xff;
TRISC=0x00;
PORTC=0xff;
}
uchar Eeprom_read(uchar add){
EEADR=add; //地址赋初值
RD=1; //启动一次读操作
return EEDAT;
}
void Eeprom_write(uchar add,uchar dat){
EEADR=add;
EEDAT=dat;
WREN=1; //允许进行写操作
GIE=0; //禁止中断
EECON2=0x55;
EECON2=0xAA; //校验
WR=1; //启动一次写操作
while(EEIF==0);
EEIF=0;
WREN=0; //关闭写操作
GIE=1;
}
void main(){
uchar i;
OSCCAL = _READ_OSCCAL_DATA();
Port_init();
while(1) {
for(i=0;i<=0x07;i++){
PORTC=Eeprom_read(i);
Dlms(300);
Eeprom_write(1,0x55);
PORTC=Eeprom_read(1);
while(1);
}
}
}