converting data

General discussion on mikroC.
Post Reply
Author
Message
marco
Posts: 57
Joined: 03 Jan 2008 20:34

converting data

#1 Post by marco » 01 Sep 2010 12:29

Hello again my friends!
I´m working with 16f877A and i have a basic question for you!

I have 2 memories (Eeprom) with adress 0x32(1byte) and 0x33(1byte) with data on it.
I have a variable V (unsigned (int), 2 bytes).
Eeprom 0x32 is MSB and Eeprom 0x33 is LSB.
How can i send 2 eeprom data into V variable

EX:
Eeprom_(0x32);---0x3;(MSB)----3 Decimal
Eeprom_(0x33);--- FF;(LSB)----255 Decimal

Variable V=03FF------1023 Decimal

thank you all, my friends.

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: converting data

#2 Post by braus » 01 Sep 2010 19:41

Hello marco. As with many problems in programming this has a lot of solutions which I'm going to provide you perhaps is not the best but I'm sure it works;

1. You need a single byte variable to temporarily store v value, i.e. unsigned short temp.
2. As you will first access to 0x32 memory allocation (MSB) then you have to charge it's value first, i.e. temp=V>>8; 0x32=temp;
3. Finally you charge 0x33 memory allocation value, i.e. temp=V; 0x33=temp;
Best Regards
Omar Galicia
Mexico City

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

Re: converting data

#3 Post by Sobrietytest » 05 Sep 2010 09:07

In case you got confused by braus' reply, it goes like this...

Code: Select all

short temp;
int V;

V = Eeprom_Read(0x32);       //temp = 0x0003
V = V << 8;                  //V = 0x0300, i.e. the value gets bitshifted 8 binary places to the left
temp = Eeprom_Read(0x33);    //temp = 0x00FF
V = V + temp;                //V = 0x03FF



marco
Posts: 57
Joined: 03 Jan 2008 20:34

Re: converting data

#4 Post by marco » 08 Sep 2010 12:16

Hello
I haven´t try yet but it seems very logic!
Ihave compile the programme but i havent test it on hardware!
As soon as i test it ,i will comment!

Thank you my friends for the help and for que quick response.

marco
Posts: 57
Joined: 03 Jan 2008 20:34

Re: converting data

#5 Post by marco » 22 Sep 2010 09:49

Sory about the delay!!
It is working fine.
Probleme 100% solved.

Once again tank you guys.

Post Reply

Return to “mikroC General”