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 interface adc with pic16f877a

Status
Not open for further replies.

summerof69.kunal

Newbie level 6
Joined
Apr 25, 2010
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
sikkim
Activity points
1,457
hi..
i m working with pic16f877a and lcd to display the variation of sensor voltage on lcd..
i m able to dsplay anything on lcd..but unable to interface the sensor with adc..can anybody send me the ccs coding and circuit diagram..here is my program to display an lcd..
#device adc=10

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected

#use delay(clock=20000000)




cmdwr()

{

output_low(PIN_d6); // Selecting command reg
output_low(PIN_d5); // LCD write
output_high(PIN_d4);
delay_ms(500);
output_low(PIN_d4);

}




datawr()
{
output_high(PIN_d6); // Selecting command reg
output_low(PIN_d5); // LCD write
output_high(PIN_d4);
delay_ms(500);
output_low(PIN_d4);



}


main()
{


while(1)
{
output_b(56); //initialisation 2 lines 5X7 matrix
cmdwr();
delay_ms(500);
output_b(56); //initialisation 2 lines 5X7 matrix
cmdwr();
delay_ms(500);
output_b(56); //initialisation 2 lines 5X7 matrix
cmdwr();
delay_ms(500);
output_b(56); //initialisation 2 lines 5X7 matrix
cmdwr();
output_b(15);//display on cursor on
cmdwr();
delay_ms(500);
output_b(1);// clear LCD
cmdwr();
delay_ms(500);
output_b(6);// shift cursor right
cmdwr();
delay_ms(500);
output_b(128);
cmdwr();
delay_ms(500);
output_b('S');// line 1 position 1
datawr();
delay_ms(500);
output_b('1');// line 1 position 2
datawr();
delay_ms(500);
output_b('=');// line 1 position 3
datawr();
delay_ms(500);





}

}

plz tell me how to interface the adc..i want to send the voltage of sensor to display the variatiom on lcd..
 

Which sensor you are using?
There is no adc part in your given coding.
 

m using tgs813 and tgs2600...
i don't know the coding of adc..actually my project is to interface the sensor with pic16f877a and show the corresponding variation of ppm in lcd..i knw how to display an lcd but dont know how to interface it with adc
 

i am using hi tech c compiler, if u have no problem i will tell

step1; initialize the adc port
step2: select adc channel
step3: then select 8 bit adc resolution or 10 bit resolution
step4: store adc value in one register then display the lcd
 

This is an example program how u can read adc and display it over serial port.

Code:
void main()
{
   float value1,value2;
   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   while(1)
  {
   set_adc_channel(0);
   delay_ms(10);
   value1=read_adc();
   value2=(value1*5)/1023;
   printf("voltage=%f\r\n",value2);
   delay_ms(500);
  }
}

Its on you how much accuracy you want.you can use 8 bit or 10 bit adc.
 

thanx 4 u help sir..
i want to use external reference voltage..my sensor voltage is varying upto 8-10 volts..
i need a ccs coding like if my analog voltage is between two ranges,i will display some message in lcd....1st i hv to convert my analog voltage to digital and then should apply the loop..plz send me the ccs coding

Added after 1 hours 27 minutes:

hi,
i m doing project on smart sensors (tgs 813 or tgs2600).and it has output as voltage ranging from 0 to 8 volt..we are trying to display the output in ppm in the lcd so in the program we need to code our analog voltage into digital so that we can convert it into a corresponding ppm range using IF statement in the program..like 'o to 1v' will give 200ppm on lcd..we r able to interface pic16f877a to lcd,but we r not able to generate ADC and get the corresponding value..here is our sample program in progress but it is not working:-
#include<16F877A.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected

#use delay(clock=20000000)




cmdwr()

{

output_low(PIN_d6); // Selecting command reg
output_low(PIN_d5); // LCD write
output_high(PIN_d4);
delay_ms(500);
output_low(PIN_d4);

}




datawr()
{
output_high(PIN_d6); // Selecting command reg
output_low(PIN_d5); // LCD write
output_high(PIN_d4);
delay_ms(500);
output_low(PIN_d4);



}


main()
{
int x;//start of adc


while(1)
{
output_b(56); //initialisation 2 lines 5X7 matrix
cmdwr();
delay_ms(500);
output_b(56); //initialisation 2 lines 5X7 matrix
cmdwr();
delay_ms(500);
output_b(56); //initialisation 2 lines 5X7 matrix
cmdwr();
delay_ms(500);
output_b(56); //initialisation 2 lines 5X7 matrix
cmdwr();
output_b(15);//display on cursor on
cmdwr();
delay_ms(500);
output_b(1);// clear LCD
cmdwr();
delay_ms(500);
output_b(6);// shift cursor right
cmdwr();
delay_ms(500);
output_b(128);
cmdwr();
delay_ms(500);
output_b('S');// line 1 position 1
datawr();
delay_ms(500);
output_b('1');// line 1 position 2
datawr();
delay_ms(500);
output_b('=');// line 1 position 3
datawr();
delay_ms(500);

setup_adc(adc_clock_internal);
setup_adc_ports(ALL_ANALOG);
set_adc_channel(1);
delay_ms(1000);
x=read_adc();


if((x>=0)&&(x<=51))
{
output_b('2');
datawr();
delay_ms(500);
}
if((x>=52)&&(x<=102))
{
output_b('3');
datawr();
delay_ms(500);
}
if((x>=103)&&(x<=255))
{
output_b('4');
datawr();
delay_ms(500);
}




}

}




but
 

What supply you are giving to your sensor.
At what voltage you are running your microcontroller and other circuit.you cannot exceed above 5v as far as microcontroller is concerned.Try to operate your sensor at 5v in this way it will vary between 0-5v and you can give this voltage to microcontroller.
By searching i found an project which also uses TGS813 sensor.Check out this, may this will give you an idea how to connect sensor with microcontroller.
 
i m giving +5v to both,sensor and pic16f877a..can u tell me on which pin of pic16f877a i have to connect reference voltage and analog voltage??
 

Why you need a reference voltage?
You dont need a reference voltage.
 

i meant the output voltage that i got from sensors needs to be connected to to which pin no. of pic16f877A in real time so that i can get the corresponding converted ppm value in the lcd...
 

Yoyu have to connect it on one of the analog pin and read the value then do what you want
 

can u upload that FULLTEXT01.pdf one more time..i m unable to download that..

Added after 31 minutes:

can u help me finding any errors or mistake in my above program plz
 

it is an advanced system
interface with PC
iam looking for lm35 with pic16f877a and and three 7-segment to display and the schematic
if anybody have plz post it as quick as u can
 

HI Dahroug..

Can directly connect LM35 OUTPUT to the any analog pin (PORTA0-A5) and using ADC channel u can convert into digital...


hope now u can do it...........
 

it is an advanced system
interface with PC
No it is not an advance system,it is very common system.
By this you can see your temprature on PC(using hyperterminal).

I think CCS have an example file how to interface 7 segment with microcontroller.Look the example file it should clear your confusion.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top