PORTC Problems on a PIC16F1823

  • william

    william - 2013-04-06

    I was testing and noticed that RC0, RC1, RC2, and RC3 are not working correctly as an input or an output. The data sheet (PIC16F1823) shows these 4 pins as possible analog inputs. The strange thing is though, it's also showing all the pins on PORTA with the same option and I did nothing to set these up except to list them as "in" or "out" and they all work fine. RC4 and RC5 also work fine. Something is definitely up with the first 4 pins of PORTC but I have no idea how to fix it.

  • Frank

    Frank - 2013-04-06

    ANSELC the register that sets whether the PORTC pins are analogue or digital isn't being cleared by GCBASIC in the INITSYS sub it generates so they default to analogue inputs. You could either include a line in every program you write for the chip to clear the ANSELC register -

    ANSELC = 0

    or for a more permanent solution edit the system.h file in the include/lowlevel subdirectory of GCBASIC  and add some lines to sub InitSys to account for the newer ANSEL variants like this -

    'Clear whatever ANSEL variants the chip has
    ANSEL = 0
    ANSELH = 0
    #IFDEF Var(ANSEL0)
    ANSEL0 = 0
    #IFDEF Var(ANSEL1)
    ANSEL1 = 0
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    ANSELE = 0
    ANSELF = 0
    ANSELG = 0

    The first 6 ANSEL registers are already there so you could  just add the lines for ANSELC. ANSELE, F and G cover every chip upto the 16F1947 I think.

  • william

    william - 2013-04-06

    Thanks for your answer we were able to get it working. I guess I can do this for any port that has analog pins?

  • Anobium

    Anobium - 2013-06-26

    Would I be correct in assuming that ANSELD would need to be added to this adaption?

    I am 'trying' to use a 16F1937 and I cannot get RD2 to operate as a digital input. I am guessing that if I add to INITSYS then this may fix my issue.

    ANSELD = 0

    Correct assumption?

  • Frank

    Frank - 2013-06-27

    Yes that would be right. I didn't notice ANSELD when looking at the new chips.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks