Abt C program for blinking led

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Abt C program for blinking led

7,847 Views
kudrekod
Contributor I
Hi
I am using the MC9S08QE128 microcontroller of development board DEMOQE128 series.for my project
I am new so don't know much abt C programming in Codewarrior.I want to write a simple program for blinking LED using C in Code warrior.Can anyone help??
Labels (1)
0 Kudos
3 Replies

1,568 Views
Rodo55
Contributor I
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 */
}
 
0 Kudos

1,568 Views
J2MEJediMaster
Specialist I
You might want to check out the (CodeWarrior Examples) directory, located in the directory where you installed CodeWarrior. One of the example programs in this directory handles blinking an LED on a evaluation board. I don't know if any of the current exampes supports your particular set up, but it's worth starting there. It's also probably worth examining some of the other code examples for information.

---Tom

0 Kudos