PDA

View Full Version : PIC16F877A adc help



CuE0079
- 17th June 2004, 15:07
hello i am new to the pic chip and i want to read the value of a potentiometer using an adc. i use the picbasic compiler and a detailed explanation of the circuit or schematics would be very helpful. i tried the pot command but it never worked for me. i follwed this schemtatic for it http://www.microengineeringlabs.com/resources/pbcmanual/images/pot.gif. i never was sure where the third leg of the pot went. anyway i would really appreciate it if someone helped me read values from the pot using the adc or pot command. thx.

Melanie
- 17th June 2004, 17:28
Connect your Pot (say 10K as a reasonable value) between Vss (0v) for the bottom end of the Pot, and Vdd (5v) for the top end of the Pot. The wiper of the Pot connects directly to your chosen PIC pin (in my example below it's RA0/AN0). See ADCIN command in PBP manual for further information also reference with the PIC's Datasheet. LCD defines not shown - add appropriately.

MyVar var Byte
CMCON=%00000111
' see Datasheet 12.1
ADCON0=%11000001
' see Datasheet 11.1
ADCON1=%00001110
' see Datasheet 11.2
TRISA=%00000001 ' Set RA0/AN0 to Input
Pause 1000 ' Wait for LCD to Initialise
LCDOut $FE,1 ' Clear Screen
Loop:
ADCIN 0,MyVar ' Get Value
LCDOut $FE,$80,DEC3 MyVar ' Overwrite with New Value
Pause 100
Goto Loop

Note, my example ONLY defines RA0/AN0 pin as ADC Analogue. If you want to add further pins, change TRISA and ADCON1 appropriately.

Melanie

CuE0079
- 17th June 2004, 21:11
sorry i dont hav PBP just the regular pic basic compiler. i'll try to see if i can convert it but it would be very helpful if someone could show me the syntax in picbasic.

Melanie
- 19th June 2004, 19:13
There's a perfect example with detailed comments provided for you...

http://www.melabs.com/resources/samples/x1/pbc/adcx.bas

...it reads an ADC and sends the result to a Serial port.

Work through it... compare the setting of each register against the PIC's Datasheet... if you have any questions then come back and we'll all see what we can do to help.

Melanie