Storing a Keycode

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

Hi,
I am new to AVR's so sorry if this is trivial, but can i store a array e.g. int code[6] = {1,2,3,4,5,6}; in to perment memory.

I need to be able to change the value as it is a electronic lock which can be re - programed with a new code, but when I change the batteries the last code neeeds to be kept.

I hope you can understand what i mean.

thanks

James

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

Use the EEPROM. It's easily programmable/reprogrammable from software, and will retain value on power loss.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

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

As you posted in the GCC forum is it a fair assumption that you are using GCC? If so then look to for the support routines that will make your life 100% less complicated.

Cliff

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

Thanks for the pointers ill take a look now

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

Is this the correct way to write to the EEPROM and read it back out.

code[0] = 1;
code[1] = 2;
code[2] = 3;
code[3] = 4;
code[4] = 5;
code[5] = 6;
code[5] = 6;
eeprom_write_block((void*)&code, (const void*)12, 6);

uint8_t code1[6];
eeprom_read_block((void*)&code1, (const void*)12, 6);
code[0] = code1[0];
code[1] = code1[1];
code[2] = code1[2];
code[3] = code1[3];
code[4] = code1[4];
code[5] = code1[5];
code[5] = code1[5];

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

You don't need the first (void *) cast, and you don't need the
"const" in the second cast, but otherwise, yes, that's it.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

Thanks, It seems to work in AVR Studio but have no programmer or debugger at the moment to check it. Replacements are on there way.