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.

how to use multiple adc chaneels in pic 16f873a

Status
Not open for further replies.

suvaraj

Member level 2
Joined
Dec 24, 2010
Messages
50
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
erode
Activity points
1,580
hi to all,
i am using pic16f873a,hitech c compiler.in my project i need to use more than 2 adc channels.any one pls help me the program in hitech c.

thanks in advance,
 

you have 5 channels built-in your 16f873a if u need extra then why not to use 16f877a which have built-in 8 * 10bit ADC channels.
 

hi i know u r asked.my question is how to use two different adc inputs in program
 
  • Like
Reactions: uks

    uks

    Points: 2
    Helpful Answer Positive Rating
just select required ADC channel using "CHS0;CHS1;CHS2" bits in "ADCON0" register and also read ADC section on datasheet.
one thing more that also configure "ADCON1" register to enable required ADC.
 
Last edited:

pls give me one example program for using RA0&RA1 in one program in hi tech c.(using pic 16f873a)
thank u
 
  • Like
Reactions: uks

    uks

    Points: 2
    Helpful Answer Positive Rating
Code:
#define channel_1  0  /* AN0 */
#define channel_2  1  /* AN1 */
#define channel_3  2  /* AN2 */

/*
Example:

result = AdcRead(channel_1);

*/

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

  ADCON1 = 0x80U;  /* 10 bit Right justified result, Vdd 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 */
 

Hello.btbass
How we can see result of these 3 analog input channels at different output ports of 16F873A.
best regards,
 

See this example ADC code in Hi-Tech.
If want read 3 ADC, just store in 3 variable.

Code:
value1=read_a2d(0);
value2=read_a2d(1);
value3=read_a2d(2);
 
Last edited by a moderator:

engshahrul Salamat Datang ,
Web page, you offered for ADC example is tuk tuk (close).
 

#include "LibraryHD44780.h"
#include "LibraryADC.h"
Error [141] ; 10.27 can't open include file "LibraryHD44780.h": No such file or directory
--------------------------------------------------------------------------------------
If we remove these 2 include headers from code,then also failed in compiling.
We receive this error.
----------------------------------------------------------------
Error [500] ; 0. undefined symbols:
_lcd_init
-----------------------------------------------
Do you have any example with leds?
 

hello,engshahrul
i attached a code,in this code we can control leds on RC4 and RC5.
With RA0.
But if we wish to control led at RC0.
Which second adc pin we should select,to control RC0.
And what changes should be in code?
 

Attachments

  • adc_on_leds_16F676.txt
    627 bytes · Views: 81
  • 52_1329078546.gif
    66.7 KB · Views: 83

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top