unsigned char WriteEEPROM(unsigned char *pData, unsigned char whichbutton) { unsigned char keys = 0; unsigned char bytes = 0; unsigned char counter = 0; unsigned char returnvalue = 0; for(keys = 0; keys < 32; keys++) { for(bytes = 0; bytes < 8; bytes++) { if(eeprom_read((keys * 8) + bytes) == 0xFF) counter++; } if(counter == 8) break; else counter = 0; } for(bytes = 0; bytes < 8; bytes++) { if(bytes == 7) { pData[bytes] &= 0xF0; // clear the last 4 bits of the last byte if(whichbutton == BUTTON_INPUT) pData[bytes] |= 0x0A; // set the last 4 bits to 1010 else if(whichbutton == BUTTON_NEW) pData[bytes] |= 0x05; // set the last 4 bits to 0101 } eeprom_write(((keys * 8) + bytes), pData[bytes]); } if(counter == 8) returnvalue = 1; else returnvalue = 0; return returnvalue; } unsigned char CheckEEPROM(unsigned char *pData) { unsigned char keys = 0; unsigned char bytes = 0; unsigned char counter = 0; unsigned char returnvalue = 0; unsigned char keytype = 0; for(keys = 0; keys < 32; keys++) { for(bytes = 0; bytes < 8; bytes++) { if(eeprom_read((keys << 3) + bytes) == pData[bytes]) { counter++; keytype = 0x0F & eprom_read((keys << 3) + bytes); // store the value that was read } } if(counter == 8) break; else counter = 0; } if((counter == CORRECT) && (keytype == 0x05)) returnvalue = 1; if((counter == CORRECT) && (keytype == 0x0A)) returnvalue = 2; else returnvalue = 0; return returnvalue; }