PDA

View Full Version : PortA analog and digital IO



krohtech
- 29th November 2007, 07:53
Hello Everyone and thank you for all the help.

I have benefited greatly form searching many other posts and using the information, this is however my first post. I am a new user to the PIC microcontroller, but have used basic stamps for some time now.

I am about to try using an analog input for the first time. I will be using a pic16F819 to read a potentiometer for speed adjustment. Until now, I have been using the POT and RCTIME commands, but I am tired of the weird performance curve near the low end of the potentiometer. In the past I have used a pic16F648A and when using portA ports I have used the CMCON=$07 command to turn all the portA pins to digital IO.

Is it possible to selectively turn some pins digital while leaving other pins as analog inputs?

Best Regards,

Kurt A. Kroh
“Goodbye and thanks for all the fish”

mackrackit
- 29th November 2007, 09:15
Look in the data sheet under analog.

You will set the
ADCON1=%????????
or the
ANSEL=%????????

I can not remember which one for the chip you are using.
The selection may not be just one but two or more pins analog.

You can also us a decimal number. On the 16F877A this will make AN0 through AN3 analog.


ADCON1=2


I like to recommend this for people getting started with analog.
http://www.rentron.com/PICX2.htm

peterdeco1
- 29th November 2007, 10:33
Hi Kurt. The easiest thing to do is set all of the ports to digital. When you use the ADCIN command, it will convert the particular port to analog. I put these lines on the top of almost all of my 16F819 programs.
OSCCON = $60 'set int osc to 4mhz
ADCON1 = 7 ' set all inputs to digital. adcin command will convert to analog
@ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON
X VAR BYTE

START:
ADCIN 0,X ' read pot on ANA0 & place value in x

peterdeco1
- 29th November 2007, 10:36
Oh yeah. Don't forget to set the TRIS registers to enable the port as an input.
TRISA = %00000001 'set RA0 to input

krohtech
- 30th November 2007, 02:25
Thanks so much for all the help!

I knew this analog stuff would be easier then I had feared. Come to think of it everything I have attempted to do with the PIC and PBP have been easier that I initially feared. I can’t believe how easy it is to build fairly complex projects. I am going to attempt to tackle RS485 and DMX later this year or early next January.

Best Regards,

Kurt
KrohTech

“Good by and thanks for all the fish!”