Working with Analog Pins in PIC16F877 (C language)

Thread Starter

Gtofig

Joined Jan 4, 2008
14
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,
Gtofig
 

beenthere

Joined Apr 20, 2004
15,819
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.
 

ramar

Joined Jan 13, 2010
1
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..
 

retched

Joined Dec 5, 2009
5,207
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.

[ed]
Here is information on current dividers:
http://en.wikipedia.org/wiki/Current_divider

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:
ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf

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