芯片是STC15W4K56S4,在加入eeprom相关程序后,期望存储数据,但实际情况是,外部修改的数据在
电路板掉电后,再次接
电源时,修改的数据并没有保存,不确定是函数的问题,还是数据根本没有写进去,请求解答,有涉及到EEPROM的部分程序如下:
- #include
- #include "STC15Fxxxx.H"
- #define MAIN_Fosc 24000000UL
- #define LcmXPixel 128
- #define LcmYPixel 64
- #define MIN(A,B) ((A)<(B)?(A):(B))
- #define Uchar unsigned char
- #define Uint unsigned int
- #definetimer0_Reload (MAIN_Fosc / 1000)
- #define CMD_IDLE 0
- #define CMD_READ 1
- #define CMD_PROGRAM 2
- #define CMD_ERASE 3
- #define MileageAddr 64
- #define BLaddr 1024
- u16 Buf[12][3]={{5,1,1},{5,3,1},{10,3,2},{5,6,2},{10,6,3},{15,4,3}};
- Uchar IAPreadbyte(Uint addr);
- void IAPprogrambyte(Uint addr , Uchar dat);
- void IAPerasesector(Uint addr);
- void IAPidle();
- void writeDatas(Uint addr , Uchar *pdat , Uchar n);
- void writeDatas(Uint addr , Uchar *pdat , Uchar n)
- {
- Uchar i;
- IAPerasesector(addr);
- for(i=0;i
- {
- IAPprogrambyte(addr+i,pdat[i]);
- }
- }
- void main( void )
- {
- Uchar contrast=30;
- DelayMS(10);
- RES = 0;
- DelayMS(200);
- RES = 1;
- DelayMS(50);
- LcmInit();
- ds1302_init();
- ds1302_write_time();
- P0M1 = 0; P0M0 = 0;
- P1M1 = 0; P1M0 = 0;
- P2M1 = 0; P2M0 = 0;
- P3M1 = 0; P3M0 = 0;
- P4M1 = 0; P4M0 = 0;
- P5M1 = 0; P5M0 = 0;
- P6M1 = 0; P6M0 = 0;
- P7M1 = 0; P7M0 = 0;
- INT_CLKO |= 0x20;
- display_index = 0;
- AUXR |= 0x80;
- TMOD &= 0xF0;
- TL0 = 0x00;// TH0 = (u8)(Timer0_Reload / 256);
- TH0 = 0xDC;// TL0 = (u8)(Timer0_Reload % 256);
- ET0 = 1; //Timer0 interrupt enable
- TR0 = 1; //Timer0 run
- EA = 1;
- TF0 = 0;
- Buf[select_2-2][0]=IAPreadbyte(0x0000);
- while(1)
- {
- if(pagenum==21)
- {
- LcmPutStr(0,0,"________________");
- LcmPutNum(7,4,Buf[select_2-2][1]);//LcmPutStr(100,4,"h");
- LcmPutNum(43,4,Buf[select_2-2][0]);//LcmPutStr(50,4,"ml");
- LcmPutNum(84,4,Buf[select_2-2][2]);//LcmPutStr(50,4,"d");
- if(select_21==1){LcmPutStr(10,0,">");LcmPutStr(10,4," "); LcmPutStr(45,4," ");LcmPutStr(87,4," ");LcmPutStr(30,6," ");}
- if(select_21==2){LcmPutStr(10,4,">");LcmPutStr(10,0," ");LcmPutStr(45,4," "); LcmPutStr(87,4," ");LcmPutStr(30,6," ");} //
- if(select_21==3){LcmPutStr(45,4,">");LcmPutStr(10,0," ");LcmPutStr(10,4," "); LcmPutStr(87,4," ");LcmPutStr(30,6," ");} //
- if(select_21==4){LcmPutStr(87,4,">");LcmPutStr(10,0," ");LcmPutStr(10,4," "); LcmPutStr(45,4," ");LcmPutStr(30,6," ");} //
- if(B2PressOnce==1)
- {
- B2PressOnce=0;
- if(select_21==2){if(Buf[select_2-2][1]<24){Buf[select_2-2][1]++; }else{Buf[select_2-2][1]=0;}}
- if(select_21==3){if(Buf[select_2-2][0]<15){Buf[select_2-2][0]++; }else{Buf[select_2-2][0]=0;}}
- if(select_21==4){if(Buf[select_2-2][2]<10){Buf[select_2-2][2]++; }else{Buf[select_2-2][2]=0;}}
- }
- if(B3PressOnce==1)
- {
- B3PressOnce=0;
- if(select_21==1) {select_21=2;}
- else if(select_21==2){select_21=3;}
- else if(select_21==3){select_21=4;}
- else if(select_21==4){select_21=1;}
- }
- if(B4PressOnce==1)
- {
- B4PressOnce=0;
- if(select_21==1){pagenum=2;LcmClear(0x00);}
- else {pagenum=3;LcmClear(0x00);}
- }
- writeDatas(0x0000,&Buf[select_2-2][0],4);
- }
- }
- }
- void IAPidle(void)
- {
- IAP_CONTR = 0;
- IAP_CMD = 0;
- IAP_TRIG = 0;
- IAP_ADDRH = 0x80;
- IAP_ADDRL = 0;
- }
- Uchar IAPreadbyte(Uint addr)
- {
- Uchar dat;
- IAP_CONTR = 0x83;
- IAP_CMD = CMD_READ;
- IAP_ADDRL = addr;
- IAP_ADDRH = addr>>8;
- IAP_TRIG = 0x5A;
- IAP_TRIG = 0xA5;
- _nop_();
- dat = IAP_DATA;
- IAPidle();
- return dat;
- }
- void IAPerasesector(Uint addr)
- {
- IAP_CONTR = 0x83;
- IAP_CMD = CMD_ERASE;
- IAP_ADDRL = addr;
- IAP_ADDRH = addr>>8;
- IAP_TRIG = 0x5A;
- IAP_TRIG = 0xA5;
- _nop_();
- IAPidle();
- }
- void IAPprogrambyte(Uint addr , Uchar dat)
- {
- IAP_CONTR = 0x83;
- IAP_CMD = CMD_PROGRAM;
- IAP_ADDRL = addr;
- IAP_ADDRH = addr>>8;
- IAP_DATA = dat;
- IAP_TRIG = 0x5A;
- IAP_TRIG = 0xA5;
- _nop_();
- IAPidle();
- }
复制代码
1
|