Once the main board is assembled, it can be tested without waiting for the sensor or motor driver boards to be ready. In time honoured fashion, we start with a little program to flash the LEDs.With any new microcontroller project, it is a good idea to start with some simple code that will allow you to test your ability to create a project in the chosen development environment, compile the program, transfer it to the microcontroller and run it. While you are at it, you get to test the simplest part of the system hardware.Development for Primus used the MPLAB IDE from Microchip and the free Microchip C30 port of the GCC C compiler. Between them, these are powerful tools if a little fussy in places. To get started, you will need to install both these packages to their default locations on your PC.The complete project for MPLAB/C30 is contained an a ZIP file that you can download here:
Create a folder in a convenient place on your hard drive and use MPLAB to open the primus.mcp file which defines the project. this project, like all those that follow, contains a number of folders, each with a specific purpose.
|src||holds all the C source code files. These all have the extension .c|
|include||holds all the C header files. These all have the extension .h|
|tmp||used by the compiler during compilation and linking. Let the compiler handle these. You don’t normally have to worry about them.|
|output||where the compiler creates the actual rom image that gets sent to the processor. Again, you don’t need to worry about them unless you are using an external programmer and need to find the hex file to download|
|config||not normally used here but can hold configuration options for building the code using a command line compiler.|
The file include/primus.h is where all the hardware is defined for the mouse as well as som common definitions for things like directions and such. this file is included by most other source files in the project. Ensure that you have configured MPLAB to allow you to set the configuration bits in the code, then the macros in primus.c will set things up for you. Primus uses an 8MHz crystal with a x8 PLL multiplier. This gives an effective processor clock of 64MHz which in turn runs the processor at 16MIPs.This short piece of code not only test that the LEDs and speaker are wired correctly but, if you can measure the frequency of the signal driving LEDA, it will be 500hz if you have the oscillator correctly set up. This will be essential when we come to drive the sensors and motors so get it right now, before doing anything else.