PortA Doesn't Work


+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Jul 2003
    Posts
    2,358

    Default PortA Doesn't Work

    PortA Doesn't Work
    Parts of PortE do not work
    I can't transfer my program from a PICF84 to a PICF628



    PortA Doesn't Work

    Oh yes it does. It might need to be switched ON for Digital use though.

    Whilst you weren't looking, Microchip have been busy stuffing the PICs full of goodies. Some of these goodies are ANALOG interface parts. A/D Convertors (eg 16F876) or Comparators (eg 16F628), or even BOTH (eg 16F877A and 12F675). Mostly (but not always), the Analog hardware is multiplexed with PortA (and PortE).

    By default, on many PICs which have these Analog parts, when the PIC powers up, it defaults into Analog mode (the controlling Registers are usually set to zero) – which is why you can't do Digital I/O until you set that port into Digital mode.


    If your PIC has Comparators…

    Then the Comparators are most likely controlled by the CMCON Register. This is most common thing that is overlooked by people transferring programs over from one PIC to another (for example from a 16F84 to a 16F628).

    CMCON=%00000111

    Will normally switch the Analogue Comparator pins to Digital I/O mode. (CMCON=$07 or CMCON=7 will do the same thing). Go check with your PICs Datasheet to see what setting the CMCON Register to this value does.


    If your PIC has A/D Convertors then…

    The A/D Convertors are controlled usually by the ADCON1 Register (again check with your PICs datasheet – eg it’s ANSEL with the 12F series).

    ADCON1=%00000111

    Will normally switch the Analogue A/D pins to Digital I/O mode. (ADCON1=$07 or ADCON1=7 will do the same thing). Go check with your PICs Datasheet to see what setting the ADCON1 Register to this value does.


    If your PIC has BOTH A/D Convertors and Comparators…

    The you’ll need to set both ADCON1 and CMCON appropriately.

    Example 1 - if you have a 12F like a 12F675, then

    ANSEL=%00000000
    CMCON=%00000111

    Is the sequence for you.

    Example 2 - if you have a 16F628 then all you need is...

    CMCON=%00000111

    Example 3 - if you have a 16F876 or 16F877 then this one is for you...

    ADCON1=%00000111


    ALWAYS check the correct Register settings for your own needs, by looking in the Comparator Section, and/or the A/D Converter Section in your PICs Datasheet.

    Melanie

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Maybe some may also download the following PDF and keep it handy somewhere in their PC.

    Common 8-Bit PIC® Microcontroller I/O Pin Issues (TB3009)
    http://ww1.microchip.com/downloads/e...tes/93009A.pdf
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by mister_e View Post
    Maybe some may also download the following PDF and keep it handy somewhere in their PC.

    Common 8-Bit PIC® Microcontroller I/O Pin Issues (TB3009)
    http://ww1.microchip.com/downloads/e...tes/93009A.pdf
    I've not only downloaded and printed TB3009, I've attached Melanie's post to it!

    Thanks to both of you!
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  4. #4
    Join Date
    Jan 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default PORTA 18f

    and for 18f4620 it`s ADCON=00001111 isnt it? do you do that right after tris initialsation or after?

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


    Did you find this post helpful? Yes | No

    Default

    I do not have the data sheet with me but if you have the correct register and all it should be
    ADCON=%00001111
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bluestar84 View Post
    and for 18f4620 it`s ADCON=00001111 isnt it? do you do that right after tris initialsation or after?
    From the data sheet:
    19.0 10-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE

    The Analog-to-Digital (A/D) converter module has
    10 inputs for the 28-pin devices and 13 for the 40/44-pin
    devices. This module allows conversion of an analog
    input signal to a corresponding 10-bit digital number.
    The module has five registers:
    • A/D Result High Register (ADRESH)
    • A/D Result Low Register (ADRESL)
    • A/D Control Register 0 (ADCON0)
    • A/D Control Register 1 (ADCON1)
    • A/D Control Register 2 (ADCON2)

  7. #7
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RussMartin View Post
    I've not only downloaded and printed TB3009, I've attached Melanie's post to it!

    Thanks to both of you!
    In the 5 Min it took me to read this thread started by Melanie in 2004 & the PDF referenced by mister_e.
    you have solved:
    • I now understand how to read and make sense out of the Microchip data sheets.
    • using the PIC16F628A I understand what CMCON=7 is actually CMCON=%00000111 (which is binary for 7, and $07 is hexadecimal. lol you think a programmer of as many languages as me would have picked that up, shows I'm still a rookie in my career)
    • How registers work and how to set them
    • And many more things

    This post is a great aid in going from playing with PBP to being confident in the ability of having a task and completing it.
    Thank you

  8. #8
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    There's nothing nicer than knowing the time spent in posting something has been of help - even after all the years. *smiles*

  9. #9
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks Melanie,

    That is a good troubleshooting doc to have on hand and review.


    And as sbobowski noted it is much easier for a newbie to understand why/how to set a particular register if it is depicted as a binary value.

    ie. cmcon = %00000111 instead of =07, Since each bit has a unique function, showing it in binary rather than hex or dec is easier for me to understand.

    Thanks
    Dwight
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  10. #10
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Some folks think in Binary, some in Decimal, other in Hexadecimal.

    I like Binary (when dealing with say up to 8 bits), because in my mind it immediately relates to those BIT positions in the PICs Registers.

    It doesn't matter what you use, or if you chop and change throughout your code, the compiler doesn't care - it's there just for YOUR convenience.

    The biggest confusion is when folks come along and say "What's inside the BYTE - is it Decimal or Hex or Binary?". It takes some explaining to convince people the answer is YES - It's ALL OF THOSE simultaneously! It's simply a matter of how you perceive it YOURSELF.

    If you wanted to extract say just BIT 5 out of a BYTE... what's easier to visualise what is going on...

    Example A.

    NewByte=OldByte & %00100000

    or...

    Example B.

    NewByte=Oldbyte & 32

    or...

    Example C.

    NewByte=Oldbyte & $20

    All three examples are EXACTLY the same. Use whichever one turns you on.

  11. #11
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136


    Did you find this post helpful? Yes | No

    Post Re: PortA Doesn't Work

    Another option to set PortA to digital automatically is Darrel's "AllDigital.pbp" . It will set the required registers on the selected device to make PortA digital and there is also a provision to see which registers have been set by the "All Digital" include.
    http://www.picbasic.co.uk/forum/showthread.php?t=11100
    I have used this in almost all of my 16F designs.
    Last edited by shahidali55; - 9th May 2012 at 14:46.

  12. #12
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: PortA Doesn't Work

    Port A works, it’s port A bit 4 that doesn’t work lol!

Similar Threads

  1. pls help me verify my code not work, why???
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2010, 10:19
  2. error worring pbp247
    By chai98a in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th January 2010, 05:51
  3. 16f876 PortA set-up trouble?
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2006, 20:31
  4. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 6th May 2005, 00:29
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 13:03

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