Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to combine two 8 bit registers into a 16 bit variable

Status
Not open for further replies.

bpramod

Member level 1
Joined
Sep 21, 2011
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,534
hi friends....
i m using TH0 and TL0 in my program..at the end i need to combine the values of TH0 and TL0 in 16 bit variable...plz tell me wat is logic
 

Here is the basic technique:

Code:
unsigned int tvalue = 0x00;

tvalue = TH0;  // Insert the TH0 byte into the lower byte of tvalue
tvalue <<= 8;  // Left shift the lower byte into the higher byte of tvalue
tvalue += TL0; // Insert the TL0 byte into the lower byte of tvalue

You can combine a few of these steps together, however this should give the general idea of how to accomplish the task.

BigDog
 
16bit_var= (TH0<<8) | TL0;

Alex

---------- Post added at 09:31 ---------- Previous post was at 09:26 ----------

I think the above works five but just in case you may want to add typecasting too

16bit_var= ((unsigned int)TH0<<8) | TL0;

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top