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.

[SOLVED] ADC problem using PIC16F876A

Status
Not open for further replies.

papunblg

Advanced Member level 3
Advanced Member level 3
Joined
Oct 22, 2010
Messages
716
Helped
172
Reputation
344
Reaction score
165
Trophy points
1,343
Location
Kolkata India
Activity points
6,421
The following code (to measure voltage using inbuilt ADC) is not working as expected. It appears that AN0 is not accepting input. Am I missing something? (for the time being I am using ADC0804 with 16f876A!!!!!!!!!as I am pretty comfortable with it)

void main(void)
{
ADCON0=0b10000000;
ADCON1=0b11000000;
ADCON0.ADON=1; // turn on the A2D conversion module
Delay_ms(300);
LCD_init();
while(1){
Delay_ms(300);
read_adc();
-----
-------
}

void read_adc(void)
{
unsigned short result;
ADCON0.GO = 1; //ADC start
while(ADCON0.GO==1);
result=ADRESH;
result=result<<8; //shift to left for 8 bit
result=result|ADRESL; //10 bit result from ADC
}
 

Code:
unsigned short result;
Short is 1 byte long. You need at least int size (2B).

Code:
result=result<<8; //shift to left for 8 bit
After this, result = 0

Also the scope of the result is inside the block. You should use "return result;", or a global variable.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top