Setting the 18F24K20 to digital.

Status
Not open for further replies.

Peet19

Member
Hi!
How should the PIC18F24K20 be set to have all pins digital output?
Is it enough to set the ANSEL register or do you need something else?
CLRF ANSEL
Thanks in advance for your help!
 
That sets them all to digital, but not definitely outputs.

Write zero to the TRIS registers as well, to guarantee all the pins are set to output mode.
 
Pins set to analogue will still work as digital outputs when set to output. However, a big gotcha is they always read as zero so RMW operations can produce strange results.

Mike.
 
Last edited:
Turn off any comparators as well, they conflict with digital modes.
That's not been an issue for a great many years (basically the 16F628), the default now is comparators OFF.

If in doubt, set the pins using the MCC, which the OP is probably using to set the config fuses anyway? (I certainly do) - then either use it 'as is', or cut and paste the parts you want to your main code.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…