GPIO DIY Embedded Code

Below is a framework for code for the GPIO hardware, in fact the whole Codewarrior project, that can be used to generate your own code for controlling a GPIO board's inputs and outputs for your own custom functions. These can be as complex or as simple as you like.

The C language code project below is designed with the novice programmer in mind, and the configuration and logic is very thoroughly commented. The CAN communications, serial communications, and port set-up is completely finished. The analog-digital converters (ADCs) are set up on some pins/circuits, and there are some timers set up (for things like VR inputs). There are also examples of how to configure outputs.

In most cases, users will need to modify the code to suit their particular needs, and the code is designed to make this possible for the programming neophyte.

There are many hints in the comments included in the source code that explain how to change the existing configuration to suit your needs if you wish. The code has a number of example snippets on how to configure the inputs and outputs based on sample parameters to suit your application. In short, it is a quick step towards writing your own GPIO programs in the C programming language.

By writing your code in the C language, you will be learning the valuable skill of embedded programming. This is ultimately what the GPIO board and template code project are intended to encourage.

This template code project has:

This program reads all the runtime variables from MS-II™ over CAN many times per second and allows you to input logic conditions based on any of the CAN variables as well as the 12 on-board GPIO input channels (6 ADCs, 4 digital, and 2 timer channels), and allows you to use these to control 12 outputs (4 PWM and 8 on/off):

TemplateCWproject.zip
(Contains the Monitor.abs.s19 file you load to your GPIO, it is in the /BIN/ folder.)

A completed compatible tuning software (MegaTune or TunerStudio) files that go with the above code are contain in the tuning software project folder zipped below:

template1.000 tuning project folder
(Has a copy of the Monitor.abs.S19 file, renamed to Template.abs.s19, in the template1.000 folder)

The INI file is here:

GPIO_template.ini
(You will need to rename this file to GPIO.ini for MegaTune/TunerStudio to recognize it.)

This code was developed entirely on Codewarrior 4.7 Special Edition. This compiler (actually a cross-compiler/linker/locator) is available for free from Freescale (which used to be called Motorola):

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=CW-HCS12X

You have to register to get the software. (Note that the link may eventually become stale. If it does, start at www.freescale.com and search for 'codewarrior HCS12(X) special edition')

The 'Special Edition' of Codewarrior has a 32 Kbyte code compile limit, and a maximum of 32 files (the number of files and code size are listed on the bottom left side of the Freescale Codewarrior IDE - integrated development environment). This code is well under those limits at 23 files and ~21 Kbytes.

In addition to the many hints, tips, and examples in the source code itself, there is a draft introduction to programming in C for HCS12 embedded applications on B&G hardware here:

C.htm, a HCS12 C-language primer

as well as many, many others on the internet.



©2007, 2010 Al Grippo and Bruce Bowling - All rights reserved. MegaSquirt® and MicroSquirt® are registered trademarks.