Electronic Safe: Code Snippet

void StoreKey(char *str)

{

ee_up = 0x00;

ee_low = ee_up + 5;

while (*str)

{

bit = *str++;

EEPROM_Write();

ee_up =ee_up+10; //test

ee_low = ee_up+5;

}

lastaddress = ee_up;

}



void GetKey(void)

{

ee_up = 0x00;

ee_low = ee_up +5;

while (ee_up != lastaddress)

{

EEPROM_Read();

UART_Put();

ee_up = ee_up +10;

ee_low = ee_up +5;

}

}

The code above is used to store a variable length PIN in EEPROM and retrieve it when needed. It starts at address 0x00 and increments by 10 for every successful digit. Once the PIN is stored it saves the last used address into a variable so the GetKey() function knows when to stop.