automatically calling SetAllDigital

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1487
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

automatically calling SetAllDigital

Post by Jerry Messina » Thu Apr 20, 2023 12:50 pm

Devices that have shared analog/digital IO pins power up with the pins set to analog mode.
This can cause various issues since pins set to analog will always read as a '0', so it's typical to include setdigitalio.bas and call SetAllDigital at startup to set all the pins to digital mode.

Code: Select all

device = 18F26K22

include "setdigitalio.bas"

main:
	SetAllDigital()
The setdigitalio module has an option that will automatically add the call to SetAllDigital for you...

Code: Select all

device = 18F26K22

#option DIGITALIO_INIT = true	// add call to setalldigital at startup
include "setdigitalio.bas"

main:
	// all pins will be in digital mode
The downside to this is that you have to remember to set the #option before including the file.

If you would like to change the default so that the call is automatic, copy the file setdigitalio.bas
from the library folder to your userlibrary folder and edit the file to change the default setting of the option:

Code: Select all

// added V2.6 to automatically call SetAllDigital at startup
#option DIGITALIO_INIT = true      // default was 'false'
Now, anytime you include setdigitalio.bas SetAllDigital() will automatically be called for you.

Code: Select all

device = 18F26K22

include "setdigitalio.bas"

main:
	// all pins will be in digital mode... 

	// you can change some back to analog if need be
	SetAnalogPort(AN3, ANA)		
The one caveat to this is you must remember to update your userlibrary copy of the file whenever a new version of setdigitalio.bas is available.

Post Reply