Page 1 of 1
How to store large integer value greater than 255 at particular location in eeprom(Solved))
Posted: 07 Feb 2024 12:05
by kumar123
Hi,
I want to store large number at these two below location in eeprom
0x0000, 0x0001
Code: Select all
data_size++; (it could be around 65535 bytes)
EEPROM_Write(0x0000, data_size & 0xFFFF);
EEPROM_Write( 0x0001, (data_size >> 8) & 0xffff);
Is the above code is right?
If wrong please let me know the correct way.
Regards,
Kumar
Re: How to store large integer value greater than 255 at particular location in eeprom
Posted: 08 Feb 2024 13:10
by kumar123
Hi,
Problem has been solved.
Regards,
Kumar
Re: How to store large integer value greater than 255 at particular location in eeprom(Solved))
Posted: 05 Mar 2024 11:11
by mia02
Could you please share the solution.
Re: How to store large integer value greater than 255 at particular location in eeprom(Solved))
Posted: 06 Mar 2024 05:21
by kumar123
Hi,
This is the piece of code which i took it from the internet:
Code: Select all
unsigned char hi,lo;
//data_size any value greater than 255 it will store at these two below locations
hi = (unsigned char)(data_size >> 8); // store location at 1
lo = (unsigned char)data_size; // store location at 1
EEPROM_Write(0x0000, hi);
EEPROM_Write(0x0001, lo);
I hope this will help you!
Regards
Kumar
Re: How to store large integer value greater than 255 at particular location in eeprom(Solved))
Posted: 13 Mar 2024 10:14
by paulfjujo
hello,
more simple solution
The mikroC PRO for PIC compiler provides a set of useful built-in utility functions.
The Lo, Hi, Higher, Highest routines are implemented as macros. If you want to use these functions
you must include built_in.h header file (located in the include folder of the compiler) into your project.
example
Code: Select all
// to load TMR1 value 0x0BDB ( 3035 decimal)
TMR1H= Hi (3035);
TMR1L= Lo (3035);
or for eeprom:
to store the value 32769 into Eeprom adresse 0 and 1
Code: Select all
unsigned int My_DAta; //integer 16 bits data
My_Data = 32769 ;
EEPROM_Write(0x0000, HI(My_Data);
EEPROM_Write(0x0001, Lo(My_Data);
another way : use pointer .
Code: Select all
unsigne int My_Data;
unsigned char *p1;
p1= &My_Data;
My_Data=32769;
EEPROM_Write(0x0000, *(p1));
EEPROM_Write(0x0001, *(p1+1));