/* 1. Compiler: TC 2.0 2. Mode: Large 3. Project: Demo6.prj Demo6.c ..\lib\8000l.lib ..\lib\tcpipl.lib 4. Explain: (1). Writing initial data to all 2048(8*256) bytes EEPROM (2). Reading & showing the EEPROM data for check (3). The EEPROM can be erase/write in about 100,000 times (4). The EEPROM can be read in any number of time (5). The EEPROM can be used to store the 8831's module address & configuration 5. Hordware:8831 It's compiled by Tony ------------------------------------------------------------------------------------------- */ #include #include #include #include #include #include"..\lib\8000.h" #include"..\lib\vxcomm.h" /* ------------------------------------------------------------------- */ void main() { int i,j,t,k; char c; int ret; int type; int ver; type=Is8000(); /*detect the current operation system*/ if(type) { ver=GetLibVersion(); Print("Hello 8831! (Flash memory is %d K)\n\r",type); Print("Library version is %d.%02d",ver>>8,ver&0xff); } else { Print("Hello PC!, this program is not run under I-8831."); return; } Init5DigitLed(); /* 5-digit LED initial */ EnableEEP(); /* enable for write operation */ Puts("\n\rWrite EEPROM : "); for (j=0; j<8; j++){ /* write initial value to all 1K bytes data */ Print("\n\rwriting block=%x\n\r",j); Show5DigitLed(1,j); Show5DigitLed(2,17); for (i=0; i<256; i++) { Show5DigitLed(5,i%10); Show5DigitLed(4,(i/10)%10); Show5DigitLed(3,i/100); ret=WriteEEP(j,i,(i+j)&0xff); Print("\raddr=%2X,data=%2X ret=%d",i,(i+j)&0xff,ret); } } Print("\n\r"); ProtectEEP(); /* protect data in EEPROM */ for (k=0;k<256;k++) { i++; i=i&0x01; if (i==0) LedRunOn(); else LedRunOff(); Print("\n\rRead EEPROM : address=%d(%X) data in block 0-7=",k,k); for (j=0; j<8; j++) { t=ReadEEP(j,k); /* read back EEPROM for check */ Print("%02X ",t); } DelayMs(300); /* delay about 0.3 sec */ while (Kbhit()) { c=Getch(); if ((c=='q')|| (c=='Q')) break; Print("(%c)",c); } } }