User Tools

Site Tools


Determining the Number of Pins on the Platform

All Micro-controller platforms running MMBasic show a remarkable degree of native cross-platform code-compatibility.

As such, it is now common to see code with idiosyncratic configuration and switching code.

One such requirement could be determining the number of pins on a particular device thus allowing code to auto-configure for, say, the 28 and 44 pin variants of the '170-based MicroMite Mk2

There is a CFunction which can determine this (by implication) on PIC32MX platforms (in the “Embedded C Modules” folder of the software distribution), but that isolates any ST and Pi platforms - true some of them are beginning to support CSubs but code compatibilty remains a spectre.

Good news; it is not tricky to do in native MMBasic. Also, there is merit in staying within MMBasic and not being limited to platforms that support CSubs, machine code compatibility and the program-space saving on non-library-ised code.

The below code snippet quickly returns the number of pins when run on a PIC32MX170. This could easily be expanded to provide the functionality on any platform, using MM.Device$ to determine a specific set of tests for a given set of like platforms.

The Code:

'determine number of pins
        n=28               'default to 28 - it will get over-written if the below is successful
        On Error Skip 2
        Setpin 44,DIN      'this...
        n=44               '...and this are skipped if we bump into an error (pin 44 doesn't exist)
                           'so the pins stay at 28
'here n=number of pins on device
        Print n
mmbasic/determining_the_number_of_pins_on_the_platform.txt · Last modified: 2024/01/19 09:30 by