How to store large integer value greater than 255 at particular location in eeprom(Solved))

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

How to store large integer value greater than 255 at particular location in eeprom(Solved))

#1 Post by kumar123 » 07 Feb 2024 12:05

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
Last edited by kumar123 on 08 Feb 2024 13:11, edited 1 time in total.

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: How to store large integer value greater than 255 at particular location in eeprom

#2 Post by kumar123 » 08 Feb 2024 13:10

Hi,

Problem has been solved.

Regards,
Kumar

mia02
Posts: 3
Joined: 14 Feb 2024 12:25

Re: How to store large integer value greater than 255 at particular location in eeprom(Solved))

#3 Post by mia02 » 05 Mar 2024 11:11

Could you please share the solution.
Thanks

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: How to store large integer value greater than 255 at particular location in eeprom(Solved))

#4 Post by kumar123 » 06 Mar 2024 05:21

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

paulfjujo
Posts: 1544
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: How to store large integer value greater than 255 at particular location in eeprom(Solved))

#5 Post by paulfjujo » 13 Mar 2024 10:14

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));

Post Reply

Return to “mikroC PRO for PIC General”