Continue to Site

# PIC16F877A ADC register Value problem

Status
Not open for further replies.

#### imtisal

##### Junior Member level 1
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.
I got some command while searching over internet as follow: -

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.

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:
imtisal

### imtisal

Points: 2
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.
I got some command while searching over internet as follow: -

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.

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.

imtisal

### imtisal

Points: 2
Totally got it,
Thanks T3STY and Tahmid.

Once again thanks for such a nice favor.

Stay Blessed.

Imtisal

Status
Not open for further replies.