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.

need help with adc in pic 18f452

Status
Not open for further replies.

linkstatic

Junior Member level 1
Joined
Apr 14, 2012
Messages
15
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,375
Code:
#pragma config OSC=HS,OSCS=OFF
#pragma config  BOR=ON,BORV=45,PWRT=ON
#include<P18F452.h>
#include<delays.h>

void main()

{

TRISC=0;
TRISD=0;
TRISAbits.TRISA0=1;
ADCON0=0x81;
ADCON1=0xCE;
while(1)
{
Delay10TCYx(1);
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);
PORTC=ADRESL;
PORTD=ADRESH;

}

}

i just wanted to know do i have to connect the (vref +) to +5v and (vref-) to ground? and is the code right or not?
 

Code:
#pragma config OSC=HS,OSCS=OFF
#pragma config  BOR=ON,BORV=45,PWRT=ON
#include<P18F452.h>
#include<delays.h>

void main()

{

TRISC=0;
TRISD=0;
TRISAbits.TRISA0=1;
ADCON0=0x81;
ADCON1=0xCE;
while(1)
{
Delay10TCYx(1);
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);
PORTC=ADRESL;
PORTD=ADRESH;

}

}

i just wanted to know do i have to connect the (vref +) to +5v and (vref-) to ground? and is the code right or not?

with ADCON1=0xCE;
PCFG3:pCFG0: A/D Port Configuration Control bits=1110
AN0 is analog input pin and Vref+ to Vdd and Vref- to Vss
See page 184 of datasheet

You have not mentioned what you want to do with the ADC output, if anything is connected (and how) to output port(s) etc.

It appears that you want to show the result to PORTC and PORTD. Low byte appears on PORTC and high byte on portD.

Code C - [expand]
1
2
3
4
5
6
7
8
9
while(1)
{
Delay10TCYx(1);
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);
PORTC=ADRESL;
PORTD=ADRESH;
//<---------------------------------------------Put some delay 200ms to 250 ms
}

 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top