Codevisionavr EEPROM>>>>>>>>>>

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi guys i have a problem with writing/reading eeprom on atmega32a. i need to add some pin numbers to eeprom and read them. this is a password lock sysytem.

the problem is how can i add new pin number like a second one or a third one??????

without deleting the existing pins

pin1=1234
pin2=1567
.
.
.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

4 (decimal) digit PINs range from 0 through 9999, easily stored in a 16 bit word.

There is therefore room for 512 PINs in the '32s EEPROM.

Reading an erased EEPROM word will return the value 0xffff (65535), which is not a valid PIN.

To STORE a new PIN, scan the EEPROM address space for a word value 0xffff, and store the new PIN there.

To VERIFY a PIN, scan the EEPROM address space... if you don't find a word with that value, refuse access to the user.

To DELETE a PIN, locate it and write 0xffff to that location.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whenever you find yourself using variable names like pin1, pin2 the chances are you want to use an array pin[] and hence pin[1], pin[2] and so on.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I believe the OP was talking about Personal Identification Numbers. I don't use CodeVision, but IIRC you can do something like...

eeprom unsigned int PIN[10];

to reserve storage for 10 PINs.

Then, to store a new PIN in the next available (erased) slot

bool store_pin(unsigned int pin)
{
    int i;
    for( i = 0; i < 10; i++){
        if( PIN[i] == 0xffff){
            PIN[i] = pin;
            return true;
        }
    }
    return false;
 }
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mikericetga wrote:
4 (decimal) digit PINs range from 0 through 9999, easily stored in a 16 bit word.

There is therefore room for 512 PINs in the '32s EEPROM.

Reading an erased EEPROM word will return the value 0xffff (65535), which is not a valid PIN.

To STORE a new PIN, scan the EEPROM address space for a word value 0xffff, and store the new PIN there.

To VERIFY a PIN, scan the EEPROM address space... if you don't find a word with that value, refuse access to the user.

To DELETE a PIN, locate it and write 0xffff to that location.

thanks for that
but i have another question i think codevision avr wraps eeprom but i could not find the codes to access the eeprom. and the codes to scan and store.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could always give in and read the CodeVision manual ;-)

That will tell you that it has an "eeprom" modifier for variable declaration and the read/write access is implicit.