How ADC value stores inside ADRESH and ADRESL register for pic16f877a .. #2

Thread Starter

PIC_love

Joined Jan 25, 2023
1
ADRES is not a valid resister.

adval has been declared as an unsigned integer, i.e. 16 bits.

ADRESH is an 8-bit register, containing the upper bits of the ADC result.

Setting
adval = ADRESH;

first guarantees that the 8-bit result gets stored into a 16-bit variable.
Then
adval = (adval << 8);
will shift the result to the left by 8 (the same as multiplying by 256).

Now you can add (or OR) the lower 8-bit value ADRESL.
adval = adval | ADRESL;
//_____________________________________________________________________
Hi .
Can you explain the following command to me completely ?
How it run step by step ?
16_bit_variable = ((ADRESH << 8 ) +ADRESL);
 

Papabravo

Joined Feb 24, 2006
21,225
//_____________________________________________________________________
Hi .
Can you explain the following command to me completely ?
How it run step by step ?
16_bit_variable = ((ADRESH << 8 ) +ADRESL);
Sure! The operation is to take the 8 bit quantity ADRESH and shift it to the left by 8 bits with 0's filling the low order bits and the result is a 16-bit quantity with 8 low order 0's.. Then you add the 8-bit quantity ADRESL to the 16-bit quantity with the 8 low order zeros and there is no carry into the higher 8 bits. The result is 16-bit quantity that is composed of two 8-bit values. And all is right with the world.
 
Top