Back again in trouble with this basic stuff. Hope some kind guy can explain why this code doesn't work.
I thought ANSEL = 1 caused the selected input to be enabled as analog in an AllDigital environment'
However, the simulator displays the input as digital . So where am I going wrong?
TRISIO = %00000010
ANSEL = 1
AllDigital
GPIO = %00000000
Dim x As Word
main:
Adcin 1, x
GP0 = 1
GP2 = 1
WaitMs x
GP4 = 1
GP5 = 1
WaitMs x
GP0 = 0
GP2 = 0
WaitMs x
GP4 = 0
GP5 = 0
WaitMs x
Goto main
End
hi eric
As a beginner I won't pretend to understand most of the opening statements in your code example, but would I be wrong in assuming that there would be no error in changing Adcin 0, aval1 to Adcin 1, aval1, leaving everything else the same? I notice that your Tris reg is set up to accommodate this and it's the pin I used in my code. But in doing this, I find your example, like mine, doesn't work either. In fact my code worked with GPIO.0 as the adc input as did yours, and didn't work for any of the other pins substituted. Any suggestions as to why this is happening?
Dawning of a bright light. Thanks to you, Eric, I now realise that I was misunderstanding how to use ANSEL. I imagined that setting ANSEL to 1 enabled all analog inputs, and that all one needed to do was specify a particular one in the Adcin statement. I now also realise what Gobbledok meant (he was absolutely right), and I need to thank him too.