PortA analog and digital IO


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2007
    Posts
    50

    Default PortA analog and digital IO

    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”

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Code:
    ADCON1=2
    I like to recommend this for people getting started with analog.
    http://www.rentron.com/PICX2.htm
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Oh yeah. Don't forget to set the TRIS registers to enable the port as an input.
    TRISA = %00000001 'set RA0 to input

  5. #5
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Smile Thank You...

    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!”

Similar Threads

  1. analog and digital
    By lerameur in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2008, 02:40
  2. 16F877a PORTA ADC and digital help
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th February 2008, 18:44
  3. Replies: 2
    Last Post: - 14th April 2006, 09:42
  4. Analog pins for digital input
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th September 2005, 00:32
  5. Partial Digital PORTA?
    By actionplus in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th March 2004, 06:47

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts