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 using PIC 16f877a

Status
Not open for further replies.

gopintj

Member level 4
Joined
Sep 1, 2010
Messages
77
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
Thirukalukalukundra, Kanchipuram, Tamilnadu, India
Activity points
1,953
Hello friends,..!!!!

I am very new to Microcontrollers. As i am a Final Year Electronics student, I would like to build ADC as my mini project.

I hav searched lots of webpage and i found nothing helpful.

This is my program coding.. Please help me. :(

Code:
#include<pic.h>
#include"delay.c"
#include"lcd_driver.c"
__CONFIG(0x1932);
void adc_init(void);
void adc_channel(void);
unsigned char adc_res(void);
void main()
{	
	
	unsigned char result=0;
	setup_lcd_port();
	lcd_init();
	adc_init();
	adc_channel();
while(1)
	{
		result=0;
		DelayUs(20);
		result=adc_res();
		lcd_goto_pos(1);
		lcd_putn(result);
		DelayUs(20);
		}
}
void adc_init(void)
{
	TRISA=0x01;
	TRISC4=0;
	DelayUs(20);
	ADCON1=0b10000010;
}
void adc_channel(void)
{
	DelayUs(20);
	ADCON0=0b11000001;
}
unsigned char adc_res(void)
{
	ADRESL=0;
	DelayUs(10);
	ADGO=1;
	while(ADGO)
	{
		
		continue;
		
	}
    return ADRESL;
	
}


I am using 16f877a and High Tech C compiler.

Thanks in advance.. :)
 
Last edited by a moderator:

These are the best PIC tutorials I have come across online:

**broken link removed**

**broken link removed**

The cover both the baseline and midrange PICs using both MPASM Assembler and Hi-Tech C.

Your 16F877A is a midrange PIC and tutorial 8 in the second link above covers Analog to Digital Conversion.

You should have no problems find your answers in these tutorials. They are very professionally done in PDF form with downloadable source.

Hope the tutorials help you in your endeavors.
 

Thanks for your valuable reply.. :)

I think, Analog Input in Channel 0 of 16f877a is not suitable for A/D conversions.

I then, tried in channel 1 and i got the output successfully.. :)


The doubt that i hav now is, Which one is the best compiler,.. i mean, I have known about High tech c compiler and i m working on it till now. :)

But, some says that, CCS compiler is better than High Tech C compiler...!!!!!

Could you tell me which of the above is best one to create codes...???

Waiting for your valuable reply. :)
 

The doubt that i hav now is, Which one is the best compiler,.. i mean, I have known about High tech c compiler and i m working on it till now. :)

But, some says that, CCS compiler is better than High Tech C compiler...!!!!!
I'm using Hi-Tech compiler. I like to use Hi-Tech. I also heard about CCS Compiler and Micro C, but I don't give a try yet.

From my view, I see the CCS Compiler and Micro C have many ready made function that user can use, while Hi-Tech don't have many function. I'm using Hi-Tech with all my own function but this is good to get more understanding what's going on.

The Hi-Tech is cheaper but CCS I heard need to pay some yearly, maybe for the function updates.
 

Oh.. :)

Thank you for your valuable reply.. :)

I here after going to use High Tech C compiler to improve my knowledge as like you ppl..:)

Thank u very much once again.. :)

dont use the forum as your mobile and spoil the quality of it...

spend some time to type the complete words when you ask for help...

this is the last warning to you ,
 
Last edited by a moderator:

You have alot of compilers available to use.

Some will need payment thought.

Arduino - easiest (huge number of libraries. They go as far as having libraries for specific IC, like max6674 or max6675.

CCS and Mikro - they have a decent community helping them and they also have a very good number of libraries to compare and create more complex codes

Hi-Tech - (the one i use) has loads of ppl using it but the number of libraries built for it are very small comparing with the others... but when you get something working on it you get double pleased. You need to check datasheets, etc... etc... i think that by working with this compiler you learn more of C than working on the others ;)
 

These tutorials are great! Thanks for the links, I'm new to pics, I've been looking for something like this for a while.
 

I was not able to find out that tutorial for free. Can any one help ?
 

Hi Tahmid

this is great work.
How can it be read with an LCD, to display the value maybe the RMS value like a range of 100V--300V
 

What do you mean by read with LCD. The value you get from adc is converted to string and then passed to lcd display function which displays the adc data on LCD.
 

What I mean is this how do I measure an RMS with range of 100v-300v and above to display it on an LCD. This is my question
 

Vrms = V/sqrt(2)

If you are measuring a scaled down dc value proportional to some AC value then you calculation will be

like this.

If your adc input is 5V DC and your AC for 5V DC is equal to 300 V AC then

5V DC = 1023 raw adc value

1023 * x = 5
x = 5/1023 = 0.0048875855327468

If raw ad c value 765 then 765 * 0.0048875855327468 = 3.73900293255132 V

5V Dc = 300V AC

5 * y = 300

y = 300/5 = 60

So, 3.739 * 60 = 224.34 V AC

Try this method and see if it works. In AC the rms value will be equal to 70% of the peak value

Vrms = V/sqrt(2) = 224.34/1.41421 = 155.5648

Eg: 165 V AC = 115 V AC RMS

If you get 230 V AC RMS then actual AC is 325.266 V
 

Ok I think I got it but I have to try it and see the result. thanks a million Jayanth.devarayanadurga

- - - Updated - - -

Ok I think I got it but I have to try it and see the result. thanks a million Jayanth.
 

hello guys i am doing a ph meter project using pic 16877a, i have no idea about the coding can anyone help me please.......

thank you
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top