Below is a simple C program I wrote to teach myself about the QE8 MCU and STOP modes. It was written for the DEMOQE Board with a MC9S08QE8 loaded on it. You should be able to use it on your MCU without very many changes.
I hope this helps.
Rodo
// Simple interrupt routine written for DEMOQE board.
// It toggles LED PTC5 once every two seconds using a RTC ISR
// and at the same time monitors switch PTA2 to see if it has
// been pressed and if it is toggle LEDs PTC0 and PTC1.
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "main_asm.h" /* interface to the assembly module */
/* Define LED's ON or OFF,*/
#define ON 1
#define OFF 0
/* Define LED's*/
#define LED1 PTCD_PTCD0
#define LED2 PTCD_PTCD1
#define LED3 PTCD_PTCD5
/*Define Switch 1*/
#define SW1 PTAD_PTAD2
void main(void) {
SCGC1 = 0x00; /* Disable clocks to peripherals */
SCGC2 = 0x04; /* Disable clocks to peripherals except clock to RTC */
SOPT1 = 0x21; /* Disable COP timer, Enable STOP Mode and Disable BKGDPE */
SPMSC1 = 0x00; /* Disable LVD in Stop3 Mode */
SPMSC2 = 0xA6; // Sets Low Power mode
PTADD = 0xFB; /*PortA bit 2 input all others outputs */
PTBDD = 0xFF; /*all port B outputs */
PTCDD = 0xFF; /*all port C outputs */
PTDDD = 0xFF; /*all port D outputs */
PTCD = 0xFF; /* turn off all LEDs */
PTAPE = 0x04; /*enable pullup on PTA bit 2 */
RTCSC = 0x91; /* Enable RTC interrupt, prescaler to 8, CLK = 1kHz LPO */
RTCMOD = 0xFC; /* Set RTC Modulo to 252 = 2 second interrupt */
EnableInterrupts; /* enable interrupts */
while (1) { /* this line gives an error about always true, just ignore error */
if (SW1) {
LED1=ON;
LED2=OFF;
// asm STOP; /* you can uncomment this line to see STOP3 work */
} else {
LED1=OFF;
LED2=ON;
// asm STOP; /* you can uncomment this line to see STOP3 work */
}
}
}
// RTC ISR to toggle LED3 every two seconds, 2 seconds on then 2 seconds off
void interrupt VectorNumber_Vrtc rtc_isr(void)
{
RTCSC_RTIF = 1; /* Clear RTIF */
LED3 = !LED3; /* Toggle LED3 */
}