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 problem using pic16f877a

Status
Not open for further replies.

glenndingding

Newbie level 5
Joined
Feb 15, 2012
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Philippines
Activity points
1,403
HI

can anyone help me?
I am new using micro c pro. i am using pic16f877a, how to configure ADC? please can anyone lend me a code for configuration?


i have a current sensor which will convert current to a certain voltage. and this voltage is serves as an input to pic16f877a.
i want to use PORT A only ,disregarding PORT E. because I only have 3 sensors which means I only use 3 ANALOG INPUTS to pic.

i do not know how to configure adc for this...

here is some of my codes.

TRISA = 0x07; //3 inputs RA0/AN0, RA1/AN1, RA2/AN2
ANSEL = 1; // 3 pins are configured analog inputs
PORTC = 0; //port c configures as output
TRISC = 0x88; //only 6 pins output

PORTD = 0; //portd are configures output
TRISD = 0x8F // only 3 pins output


what else to do.....where is the configuration for adc can any one help me to revise my codes
:sad::cry:
 

i think u need to configure the ADCON1 register. see datasheet to be more specific.
 

Code:
unsigned int AdcRead(unsigned char channel)
  {
  unsigned int result;
  unsigned char sample_time = 5U;

  ADCON1 = 0x80U;  /* 10 bit Right justified result, Vdd as ref */
  ADCON0 = 0x81U;  /* Conversion clock Fosc/32 */
	
  ADCON0 |= (unsigned char)(channel << 2U);  /* Select channel 	*/ 
	
  while(sample_time--){
    ;
    }	
	
  GODONE = 1U;  /* Start conversion  */
	
  while(GODONE){
    ;
    }
	
  result = ADRESH;
  result <<= 8U;
  result |= ADRESL;
  return result;
  }
 
I would strongly recommend you study the following tutorial:





The Gooligum Tutorials are some of the best available, very comprehensive and best of all free.

The entire series of tutorials cover most of the topics concerning Baseline and Midrange PICs using both Assembly and C languages with the Hi-Tech C Compiler.

Also the following are excellent reference materials concerning ADC in the Midrange PIC series, of which the PIC16F877A is a device of that series:

10-bit A/D Converter (Mid-Range) PICs

8-Bit A/D Converter - PICmicro Mid-Range MCU Family

Study the Gooligum Tutorial and you will soon be a master of the PIC Analog to Digital Conversion module.


BigDog
 

hi please help me configure the adc of PIC16F877A microcontroller. please.....

i want to use PORT A as 3 inputs......RA0/AN1 (PIN 2), RA1/AN1(PIN 3) , RA2/AN2/Vref-/CVref(PIN 4)
there is Vref at PIN 5 which is RA3/AN3/Vref+....

can some one lend me a code for this please.
 

Code:
#define channel_1  0  /* AN0 */
#define channel_2  1  /* AN1 */
#define channel_3  2  /* AN2 */



unsigned int AdcRead(unsigned char channel)
  {
  unsigned int result;
  unsigned char sample_time = 5U;

  ADCON1 = 0x81U;  /* 10 bit Right justified result, RA3 as +ref, Vss -ref */
  ADCON0 = 0x81U;  /* Conversion clock Fosc/32 */
	
  ADCON0 |= (unsigned char)(channel << 2U);  /* Select channel 	*/ 
	
  while(sample_time--){
    ;
    }	
	
  GODONE = 1U;  /* Start conversion  */
	
  while(GODONE){
    ;
    }
	
  result = ADRESH;
  result <<= 8U;
  result |= ADRESL;
  return result;
  }

/* A to d Function */
 

Sir is this code is a micro c code?

---------- Post added at 00:56 ---------- Previous post was at 00:53 ----------

hi please help me configure the adc of PIC16F877A microcontroller. please.....I AM USING MICRO C

i want to use PORT A as 3 inputs......RA0/AN1 (PIN 2), RA1/AN1(PIN 3) , RA2/AN2/Vref-/CVref(PIN 4)
there is Vref at PIN 5 which is RA3/AN3/Vref+....

can some one lend me a code for this please.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top