Wednesday, April 24, 2013

PIC16F877A ADC example

Given below is a sample program for testing the ADC of PIC16F877A. This program will read the analog input at channel 0 (AN0) of PIC16F877A. If the read value is greater than 512 (~2.5 volts), LED connected to the RD7 will be switched on. You can vary the analog input by varying the POT.

The program is written for XC8 compiler. A sample circuit is also given for testing the program.

Download related MPLAB X IDE project and KiCad files.


Note:
You are free to point out the mistakes and ask doubts.
Disclaimer:
Technoburst will not be responsible for any damages both physically or financially occurred due to the use of this circuit/program.

6 comments:

Marcos Prieto said...

Very good and simple example. Thanks.

Anonymous said...

Could not understand the meaning of line -
ADCResult = (ADRESH<<8) + ADRESL ; //Merging the MSB and LSB

As per my understanding , (ADRESH<<8) will make ADRESH as 00000000.

Any help is appreciated.

Ambadipudi Manikanta said...

Yes... Do not shift the ADRESH by 8, its an 8-bit regsiter and the contents become 0... Instead copy that value into a local variable(16 - bit variable) and << 8 times and then OR that with the ADRESL.

Timmusicify said...

Thank you so much! Took me an entire day to figure this out and it could have gone on way longer without your help!

Anonymous said...

This code works for me, but when I'm testing it in proteus, this warning appears: "[PIC16 ADC] PC=0x07EE. ADC conversion clock period (5e-07) is less than min TAd=1.6us and is possibly invalid for device clock frequency. [U1]"

Does it matter? If it does, What should I do?

Aasim zia said...

Can you please tell how to convert this ADCresult into string value for printing on lcd.

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes