/* EEPROM.c: Writes a value to the EEPROM and shows it on the monitor. Compiler: BC++ 3.1, Turbo C++ 1.01 (3.01) MSVC 1.52 Compile mode: Large Project: EEPROM.c ..\..\Lib\upac5000.lib Hardware: uPAC-5000 Description The uPAC-5000 module contains 16K bytes of EEPROM which includes space reserved for the system. The EEPROM is designed to store data that is not changed frequently. The erase /write cycle of the EEPROM is limited to 1,000,000 erase/write cycles, so it should not be changed frequently when testing. The first 4K bytes (Block 0 ~ 15) reserved for the system, so user can use the other blocks whose total size of 12K bytes. [Dec 28, 2011] by Liam */ #include #include "..\..\lib\upac5000.h" void main(void) { int iBlock, iAddress, iRet, iValue, iByte; float fValue; InitLib(); /* InitLib() must be called before other functions in the library may be used */ // ===== For integer ===== Print("Write 3 integers (1234, 7188, 8000) to block 16.\r\n"); EE_WriteEnable(); iValue=1234; iRet=EE_MultiWrite(16, 0, 2, (char*)&iValue); // block 16, address 0, 2 bytes iValue=7188; iRet=EE_MultiWrite(16, 2, 2, (char*)&iValue); // block 16, address 2, 2 bytes iValue=8000; iRet=EE_MultiWrite(16, 4, 2, (char*)&iValue); // block 16, address 4, 2 bytes EE_WriteProtect(); Print("Read 3 integers from block 16.\r\n"); EE_MultiRead(16, 0, 2, (char*)&iValue); // block 16, address 0, 2 bytes Print(" Block 16, Address 0 = %d\r\n", iValue); EE_MultiRead(16, 2, 2, (char*)&iValue); // block 16, address 2, 2 bytes Print(" Block 16, Address 2 = %d\n\r", iValue); EE_MultiRead(16, 4, 2, (char*)&iValue); // block 16, address 4, 2 bytes Print(" Block 16, Address 4 = %d\n\r", iValue); Print("Clear the 3 integers.\r\n"); EE_WriteEnable(); iValue=0; iRet=EE_MultiWrite(16, 0, 2, (char*)&iValue); // block 16, address 0, 2 bytes if(iRet!=NoError) Print("Clear block 16, address 0 ===> error !\r\n"); iRet=EE_MultiWrite(16, 2, 2, (char*)&iValue); // block 16, address 2, 2 bytes if(iRet!=NoError) Print("Clear block 16, address 2 ===> error !\r\n"); iRet=EE_MultiWrite(16, 4, 2, (char*)&iValue); // block 16, address 4, 2 bytes if(iRet!=NoError) Print("Clear block 16, address 4 ===> error !\r\n"); EE_WriteProtect(); Print("Press any key to continue.\r\n\r\n"); Getch(); // ===== for float values ===== Print("Write 3 float values (1234.123, 7188.123, 8000.123) to block 16.\r\n"); EE_WriteEnable(); fValue=1234.123; iRet=EE_MultiWrite(16, 0x10, 4, (char*)&fValue); // block 16, address 0x10 fValue=7188.123; iRet=EE_MultiWrite(16, 0x14, 4, (char*)&fValue); // block 16, address 0x14 fValue=8000.123; iRet=EE_MultiWrite(16, 0x18, 4, (char*)&fValue); // block 16, address 0x18 EE_WriteProtect(); Print("Read 3 float values from block 16.\r\n"); EE_MultiRead(16, 0x10, 4, (char*)&fValue); // block 16, address 0x10, 4 bytes Print(" Block 16, Address 10(hex) = %7.3f\r\n", fValue); EE_MultiRead(16, 0x14, 4, (char*)&fValue); // block 16, address 0x14, 4 bytes Print(" Block 16, Address 14(hex) = %7.3f\r\n", fValue); EE_MultiRead(16, 0x18, 4, (char*)&fValue); // block 16, address 0x18, 4 bytes Print(" Block 16, Address 18(hex) = %7.3f\r\n", fValue); Print("Clear the 3 float values.\r\n"); EE_WriteEnable(); fValue=0.0; iRet=EE_MultiWrite(16, 0x10, 4, (char*)&fValue); // block 16, address 0x10 if(iRet!=NoError) Print("Clear block 16, address 10(hex) ===> error !\r\n"); iRet=EE_MultiWrite(16, 0x14, 4, (char*)&fValue); // block 16, address 0x14 if(iRet!=NoError) Print("Clear block 16, address 14(hex) ===> error !\r\n"); iRet=EE_MultiWrite(16, 0x18, 4, (char*)&fValue); // block 16, address 0x18 if(iRet!=NoError) Print("Clear block 16, address 18(hex) ===> error !\r\n"); EE_WriteProtect(); Print("Press any key to continue.\r\n\r\n"); Getch(); // ===== for bytes ===== Print("Write 3 bytes ('A', 'B', 'C') to block 16.\r\n"); EE_WriteEnable(); EE_RandomWrite(16, 0x20, 'A'); // block16, address 0x20, byte='A' EE_RandomWrite(16, 0x21, 'B'); // block16, address 0x21, byte='B' EE_RandomWrite(16, 0x22, 'C'); // block16, address 0x22, byte='C' EE_WriteProtect(); Print("Read 3 bytes from block 16.\r\n"); iByte=EE_RandomRead(16, 0x20); Print(" Block 16, Address 20(hex) = %c\r\n", iByte); iByte=EE_RandomRead(16, 0x21); Print(" Block 16, Address 21(hex) = %c\r\n", iByte); iByte=EE_RandomRead(16, 0x22); Print(" Block 16, Address 22(hex) = %c\r\n", iByte); Print("Clear the 3 bytes.\r\n"); EE_WriteEnable(); EE_RandomWrite(16, 0x20, '_'); if(iRet!=NoError) Print("Clear block 16, address 20(hex) ===> error !\r\n"); EE_RandomWrite(16, 0x21, '_'); if(iRet!=NoError) Print("Clear block 16, address 21(hex) ===> error !\r\n"); EE_RandomWrite(16, 0x22, '_'); if(iRet!=NoError) Print("Clear block 16, address 22(hex) ===> error !\r\n"); EE_WriteProtect(); }