Download Set Digital IO Library 2.4


Here's an updated version of SetAllDigital() with support for many of the J and K series parts and the SE compiler. I tried to cover some of the odd-ball ones like those that have non-access bank registers and parts that have shared overlaying register addresses, but the list is far from complete. I didn't really change the standard F series parts.

There are two new macros... read_sfr() and write_sfr() that should allow this to work with the SE compiler even for registers that are located outside of Bank 0. If you're using the SE compiler, set

#option SWORDFISH_SE = true

either in this file or before including it. I did this as a separate module, but you could always incorporate it into utils.bas (where the current one resides). If you have any comments, please post them here. You may also want to check that thread for any updates/fixes.

In addition to the original SetAllDigital() routine there is now a corresponding SetAllAnalog(), and a SetAnalogPort() routine that will let you change a single pin mode from digital<->analog. Pin names typically follow the 'ANx' names in the datasheet, but these vary with device so you'll have to check the source for how to specify your pins.

Example usage:

device = 18F26K22
include "setdigitalio.bas"

// set all pins to digital

// example 2 - set all pins to digital and then change AN3 to analog
SetAnalogPort(AN3, ANA)    // AN3 is PORTA.3 in the 26K22

// example 3 - set all pins to analog and then change AN3 to digital
SetAnalogPort(AN3, DIG)    // AN3 is PORTA.3 in the 26K22

NOTE: SetAnalogPort() relies on being able to change the mode for an individual pin, and some older devices don't allow you to do that... you have to set them in groups. If you get a "warning - unknown analog select map" then you're out of luck using the function. SetAnalogPort() can be disabled by adding the following #option before including the module

#option DigitalIO_AnalogPort = false      // disable SetAnalogPort
include "setdigitalio.bas"

Version 2.4 changes:

  - add support for 18FxxQ10 devices

Version 2.3 changes:

  - add support for 18LFxxK50 devices
  - add missing 18LF4xK22 to analog pin definitions

Version 2.2 changes:

  - add support for 18LF devices

Version 2.1 changes:

  - add support for 18FxxK40 family
  - add SetAnalogPort() functions

Version 1.8 changes:

  - add slew-rate control SLRCON settings for K series devices and set default to standard rate 
  - add #option DigitalIO_SLEWRATE to change default

Version 1.7 changes:

  - add 18F2xK50/4xK50
  - add J94/J99 series
  - add check for _IsCompilerSE define
  - move ADSHR definition since not all devices have WDTCON

Also, the Swordfish "utils.bas" library now hooks into this library. Simply copy any updated SetDigitalIO.bas file into the library or userlibrary folder will now keep "utils.bas" up to date.