PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 20, 2004 3:48 pm |
|
|
I'm sure you want something much more complicated than what I'm
going to tell you, but here goes:
A 24LC256 eeprom has 32768 bytes. If you want to partition it
into at least 50 blocks of user data, then divide 32KB by 50:
Code: |
32768
------- = 655.36
50 |
So you could allocate 655 bytes per user. But, it's more convenient
to use a binary number for the record size, so let's round it down to 512
bytes per user.
This program will convert a user number from 0 to 49 into a EEPROM
address. You could actually have user numbers from 0 to 63.
Code: | #include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define get_record_address(x) (x << 9)
void main()
{
int8 i;
int16 record_address;
// Display the eeprom address for user numbers from 0 to 49.
for(i = 0; i < 50; i++)
{
record_address = get_record_address((int16)i);
printf("User: %u record address: %lx \n\r", i, record_address);
}
while(1);
} |
|
|