Working with Analog Pins in PIC16F877 (C language)

Thread Starter


Joined Jan 4, 2008
Hello. I am very new to PIC programming. I am using MikroC compiler for PIC. The problem I have is:
I have a distance sensor, which will give me a range of voltages from 0 to 3 Volts. I need to get this value as a float variable in the program, so that I can use it in my C program. How do I work with Analog inputs? I think I should connect sensor to the RA0, for example. Then I set TRISA.F0=1 (declare as input). What should I do next? How to read the sensor data into variable of float type? I know that I should somehow tell the PIC that it is analog input, not digital.
Any advise would be appreciated.
Thank you,


Joined Apr 20, 2004
The 16F877 has 8 A to D inputs that make analog voltages into digital values. The info about them appears starting on page 111 of the data sheet.


Joined Jan 13, 2010
Hi ,i m using pic 16f877a for my project.i want to know maximum input current and voltage rating of pic 16f877a(i want to measure input current of 5Amps).if i need to reduce means,what type of circuit should i need to use ,,,,Please give suggestion..


Joined Dec 5, 2009
5 amps will fry your pic. did you mean 5 mA?

If not, you want to divide your current by 100 using a circuit, then measure that. In your code you can multiply the measured number by 100 to get the actual number.

Here is information on current dividers:

also, you should have the datasheet for your PIC onhand at all times. You can find all the information on current maximums and many other important facts.
the datasheet is located here:

PAGE 1 shows the MAX sink-source current at 25 mA
Last edited: