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.

ADC configuration code meaning

Status
Not open for further replies.

pp99

Newbie level 3
Newbie level 3
Joined
Jun 16, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,303
ADC configuration code meaning in 16F877A

May I know what's are the meaning for each row code as below:

adcon0=0x00;
adcon1=0x00;

set_bit(adcon0,0);
set_bit(adcon0,2);

if(!(adcon0&4))
{
portb=adresh;
set_bit(adcon0,2);
}

and why need to change LVP_OFF to LVP_ON?

Thanks.
 

adcon0 and adcon1 control the ADC , check page 127-128 of the datasheet https://ww1.microchip.com/downloads/en/devicedoc/39582b.pdf

set_bit(adcon0,0); this sets bit0, it powers up the ADC
set_bit(adcon0,2); this sets bit2, it starts the conversion
if(!(adcon0&4)) checks if bit2 has become 0 which means that the conversion has ended

Alex
 

Then how about the &4 meaning?

Do you know what is the LVP meaning?

Thanks.
 

Then how about the &4 meaning?

Do you know what is the LVP meaning?

Thanks.

Sorry for the late reply, my internet service was down yesterday.
You can read about bitwise operations in this tutorial AVR Freaks :: View topic - [TUT] [C] Bit manipulation (AKA "Programming 101")

adcon0&4 is using masking, it is the same as (adcon0 & 0b00000100) so adcon is ANDed with 0b00000100 which means that every bit except from bit 2 will be forced to give a result of 0 so using that you can actually check if bit2 (only) is 0 or 1.
Any value ANDed with 0 will always give a result of 0, any value ANDed with 1 will keep the value it had so (adcon0 & 0b00000100) can give two results, 0b00000100 when bit2=1 and 0b00000000 when bit2=0.

I don't use PIC so I don't know about the LVP but the datasheet says that it is used for low-voltage ICSP programming, I don't see a relation with the ADC.

Alex
 

ADRESH is the A/D Result High Register
The ADRESH:ADRESL registers contain the 10-bit result of the A/D conversion. When the A/D conversion is complete, the result is loaded into this A/D Result register pair.

You can find it in the datasheet

Alex
 

Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top