Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.

Latest threads

New Articles From Microcontroller Tips

Back
Top