With the preliminary shakedown tests out of the way it was now time to delve into the detail.
I spent bits of today learning about the ins and outs of the CodeWarrior IDE, its C compiler and freescale MC9S08MM128.
I learned a few interesting things that might be of interest to all. Here they are;
1. MC9S08MM128 bit fields
The MC9S08MM128.h files contains structures and explicit definitions to support bit fields for some of the MC9S08MM128 registers.
These are quite useful but there is at least one caveat to their use. See the next item about optimisations for details.
These definitions allows direct reference to a specific register bits.
PTAD_PTAD4 = 0; // Turn "14-bit data" Green LED on
By default some optimisations are on and have some unwanted side effects.
My general rule is to turn all optimisations off until your program is fully working and work on optimisations afterwards.
// Standard method - works with default optimisations PTAD = 0xFF; PTAD = ~(0x01<<4); PTAD = 0xFF; PTAD = ~(0x01<<4); // Bit field method - requires default optimisations off PTAD_PTAD4 = 1; PTAD_PTAD4 = ~PTAD_PTAD4; PTAD_PTAD4 = ~PTAD_PTAD4; PTAD_PTAD4 = ~PTAD_PTAD4;
3. Interrupt vectors - ANSI style
The XL_STAR demo program does not specify the interrupt vector for an ISR in the C code file.
interrupt void button_press_isr (void) interrupt void accelerometer_isr (void)
This requires altering the .prm file to specify the required vector for ISR declarations.
VECTOR 27 button_press_isr /* KBI1 keyboard pins from push buttons SW1 - SW3 */ VECTOR 28 accelerometer_isr /* KBI2 keyboard pins from MMA_INT1/2 outputs accelerometer */
I prefer to have the vector specified in the source code and not touch any external files such as .prm files unless absolutely necessary.
For this technique it is best done with the associated constant (from the device header file).
interrupt void VectorNumber_Vkeyboard1 button_press_isr (void) interrupt void VectorNumber_Vkeyboard2 accelerometer_isr (void)