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.

PIC16F877A ADC register Value problem

Status
Not open for further replies.

imtisal

Junior Member level 1
Junior Member level 1
Joined
Nov 12, 2012
Messages
18
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,418
Helllo all,

Kindly anyone tell me how to load ADRESH and ADRESL values into one register i.e. 16 bit register. I am using ADFM = 1 [Left Justified Format]
I am using MickroC.
In addition to this,
I got some command while searching over internet as follow: -

value=((ADRESL)|(ADRESH<<8));

where value is a 16 bit integer. But I am confused in ADRESH<<8 , whatever the result is in ADRESH, it should become zero after shifting 8 times. Isn't it?
kindly help me to understand this basic idea.

Thanks in advance.


Imtisal
 

Shifting a value may temporary extend the value length (may not reduce it though) but the final real value is dictated by the variable used to store the value. A 16 bit value will get truncated into a 8 bit variable while a 8 bit value into a 16 bit variable will have leading zeros extending the value length up to 16.
This being said (I hope you got it), what you found on the web is correct. What the code does is making a OR between two variables where one of them is shifted by 8 bits to the left. As the "value" variable is 16 bit long the operation has to be considered under this maximum length, which gives the next result:
Code:
ADRESL      +   [00][00][00][00][00][00][00][00][09][10][11][12][13][14][15][16] + (zeros at the beginning are the result of value length extension up to 16 bits)
ADRESH << 8     [01][02][03][04][05][06][07][08][00][00][00][00][00][00][00][00]   (zeros at the end are the result of left shifting by 8 bits)
-------------  -----------------
value           [01][02][03][04][05][06][07][08][09][10][11][12][13][14][15][16]
Now in value you stored the ADRESL value at the lower 8 bits and the ADRESH value at the higher 8 bits.
 
Last edited:
Helllo all,

Kindly anyone tell me how to load ADRESH and ADRESL values into one register i.e. 16 bit register. I am using ADFM = 1 [Left Justified Format]
I am using MickroC.
In addition to this,
I got some command while searching over internet as follow: -

value=((ADRESL)|(ADRESH<<8));

where value is a 16 bit integer. But I am confused in ADRESH<<8 , whatever the result is in ADRESH, it should become zero after shifting 8 times. Isn't it?
kindly help me to understand this basic idea.

Thanks in advance.


Imtisal

Make sure value is a 16-bit variable. In that case, the value obtained from ADRESH will not be zero but will be shifted to the upper byte (bits 8-15) of "value". If value is an 8-bit register, then, yes, <<8 will make it zero.

Hope this helps.
Tahmid.
 
Totally got it,
Thanks T3STY and Tahmid.

Once again thanks for such a nice favor.

Stay Blessed.

Imtisal
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top