External IRQ interrupt on HCS08

Freescale’s HCS08 microcontrollers have two external interrupt sources: the IRQ interrupt and the keyboard interrupt. The IRQ pin can be configured to generate interrupts on falling or rising edges or on high/low logic states.

When a configured edge or level is detect on IRQ, the IRQF flag is set and can generate an interrupt. That interrupt source can also be used to wakeup the chip from a low-power mode.

The following example, from my HCS08 Unleashed book, demonstrates how to use that interrupt on the MC9S08QG8 microcontroller (using Freescale’s DEMOQG8 board).

// DEMO9S08QG8 IRQ controlled led blinker for DEMOQG8
// LED1's cathode is connected to PTB6
// RESET switch is connected to PTA5
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "hcs08.h" // HCS08 Unleashed definition file

unsigned char blinking=0;
// this is the IRQ ISR
void interrupt VectorNumber_Virq IRQ_isr()
  IRQSC_IRQACK = 1; // acknowledges IRQ (clear IRQF)
  blinking = !blinking; // toggle the blink control variable
  // IRQ interrupt is disabled to avoid noise (debounce)
  IRQSC_IRQIE = 0; //disables IRQ interrupt
void main(void)
  unsigned int temp;
  SOPT1 = bBKGDPE; //configures SOPT1, enables BDM mode on BKGD pin
  PTADD = 0; //all PTA pins as inputs
  PTBDD = 0xFE; // PTB0 as input, PTB1 to PTB7 as outputs
  PTBD = 0xC0; //turn leds off
  PTAPE = BIT_5; // enables PTA5's internal pullup
  IRQSC = bIRQPE | bIRQIE; //enable pin IRQ and its interrupt
  EnableInterrupts; // interrupt enable (CCR:I = 0)
  while (1)
    if (blinking)
      PTBD_PTBD6 = 0; // turn led on
      for (temp=3000; temp; temp--); // wait
      PTBD_PTBD6 = 1; // turn led off
      for (temp=30000; temp; temp--); //wait
    IRQSC_IRQIE = 1; // enable IRQ interrupt

Leave a Reply

Your email address will not be published.

eleven + 16 =