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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 -
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.
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 -
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
#IFDEF Var(ANSEL)
ANSEL = 0
#ENDIF
#IFDEF Var(ANSELH)
ANSELH = 0
#ENDIF
#IFDEF Var(ANSEL0)
ANSEL0 = 0
#ENDIF
#IFDEF Var(ANSEL1)
ANSEL1 = 0
#ENDIF
#IFDEF Var(ANSELA)
ANSELA = 0
#ENDIF
#IFDEF Var(ANSELB)
ANSELB = 0
#ENDIF
#IFDEF Var(ANSELC)
ANSELC = 0
#ENDIF
#IFDEF Var(ANSELE)
ANSELE = 0
#ENDIF
#IFDEF Var(ANSELF)
ANSELF = 0
#ENDIF
#IFDEF Var(ANSELG)
ANSELG = 0
#ENDIF
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.
Thanks for your answer we were able to get it working. I guess I can do this for any port that has analog pins?
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.
#IFDEF Var(ANSELD)
ANSELD = 0
#ENDIF
Correct assumption?
Yes that would be right. I didn't notice ANSELD when looking at the new chips.