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 output not get in my project using pic16f873a

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,m using pic 16f873a and using ccs c compiler.in my project i am using AN0 pin for adc voltage measure.if 1v come means enable RBO,2v come means enable RB1.but i am not get the out put.

Code:
#include<pic.h>
#define led1 RB0
#define led2 RB1
void adc_init();
void adc_read();
void main()
{
TRISA=0xff;
TRISB=0x00;
adc_init();
while(1)
{
adc_read();
if(data>204)
{
RB0=1;
}
if(data>409)
{
RB1=1;
}
}//while
}//main
void adc_init()
{
ADCON0=0X01;
ADCON1=0X2F;
}
void adc_read()
{
GODONE=1;
data=ADRESH;
}

Use CODE tags when posting your code.

is this correct ?pls help me..
 
Last edited by a moderator:

1. first you need to include 16f873a.h
2.data is not on the main scope. or you need to make data global variable.
3.I dont think you are using CCS in CSS your code will be
#include "16F873.h" //MCU header file
#device ADC=10 //Select 10-bit ADC
void main() //Start main block
{
int16 intemp; //Input temp from ADC result
setup_adc(ADC_CLOCK_INTERNAL); //Select internal ADC clock
setup_adc_ports(AN0); //Configure for AN0 input
set_adc_channel(0); //Select AN0
while(1) //Main loop always
{
intemp=read_adc(); //Read analog input
if(temp>204) //Convert to degC
PIN_B0=1;
else if(temp<409)
PIN_B1=0;
else
{}
}
}
 

hi to all i,m using pic 16f873a and using ccs c compiler.in my project i am using AN0 pin for adc voltage measure.if 1v come means enable RBO,2v come means enable RB1.but i am not get the out put.

Isn't this in Hi-Tech C and not CCS?
 

pls help me the program in hi tech c
thanks to u

---------- Post added at 05:55 ---------- Previous post was at 05:37 ----------

1. first you need to include 16f873a.h
2.data is not on the main scope. or you need to make data global variable.
3.I dont think you are using CCS in CSS your code will be
#include "16F873.h" //MCU header file
#device ADC=10 //Select 10-bit ADC
void main() //Start main block
{
int16 intemp; //Input temp from ADC result
setup_adc(ADC_CLOCK_INTERNAL); //Select internal ADC clock
setup_adc_ports(AN0); //Configure for AN0 input
set_adc_channel(0); //Select AN0
while(1) //Main loop always
{
intemp=read_adc(); //Read analog input
if(temp>204) //Convert to degC
PIN_B0=1;
else if(temp<409)
PIN_B1=0;
else
{}
}
}

pls help me the above program to execute in hi tech c compiler
 

If you are using the Hi-Tech Compiler there is no need to include the following header files:

Code:
#include <16F873.h>
or
#include<pic.h>

However, you do need to include the following header file:

Code:
#include <htc.h>

There are several major issues with your code, however rather than discuss each point I have posted the following example for the PIC16F87X series:

main.c
Code:
#include <htc.h>

/* Basic A2D sample code for an PIC16F87x device.
 * This code willl set up the A2D module to return an
 * 8-Bit result. If greater precision is needed, a 10-Bit
 * result can be returned if read_a2d() is modified to
 * return the short ((ADRESH<<8)+(ADRESL)). Note also that
 * ADCON1 should be set to 0x80 in the init_a2d() routine
 * instead of zero.
 *
 * This code will sample an A2D value on analog port RA0, and it's value
 * will be used to move a LED's position across PORTB.
 *
 * This project can be demonstrated on the Microchip PICDEM2 board.
 */

__CONFIG(DEBUGEN & WDTDIS & LVPDIS);	// Setup the configuration word for ise with ICD2

/* Sample code to set up the A2D module */
void init_a2d(void){
	ADCON0=0;	// select Fosc/2
	ADCON1=0;	// select left justify result. A/D port configuration 0
	GODONE=1;		// turn on the A2D conversion module
}

/* Return an 8 bit result */
unsigned char read_a2d(unsigned char channel){
	channel&=0x07;	// truncate channel to 3 bits
	ADCON0&=0xC5;	// clear current channel select
	ADCON0|=(channel<<3);	// apply the new channel select
	GODONE=1;	// initiate conversion on the selected channel
	while(GODONE)continue;
	return(ADRESH);	// return 8 MSB of the result
}

void main(void){
	unsigned char x;

	init_a2d();	// initialise the A2D module
	GIE=0;		// we don't want interrupts
	TRISB=0xF0;	// the lower four bits of POTRB will be used in output mode
	
	for(;;){
		x=read_a2d(1);		// sample the analog value on RA0
		PORTB = (8>>(x>>6));	// Use the 2 MS Bits of the result to select the bit position of the LED on PORTB
	}
}



The studying the following tutorial may also be of help:






Study the above lesson and if you have any further questions post them here and I will gladly assist you further.


You may also find the following Microchip Guides of some help:

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

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


BigDog
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top