Qorivva: Blink LED

Showing results for 
Search instead for 
Did you mean: 

Qorivva: Blink LED

No ratings

Qorivva: Blink LED

This tutorial covers the details of Blinking an LED on the TRK-MPC5604B: MPC5604B StarterTRAK evaluation board. It will introduce the evaluation board, and some basic CodeWarrior features.


In this exercise students will run sample code and build an application which enables testing of the Qorivva TRK-MPC5604B board.

Students will:

  • Configure the Software Development Environment
  • Configure the evaluation board hardware
  • Learn how to open CodeWarrior project example files
  • Build a project
  • Download and run the code on TRK-MPC5604B board
  • Learn how to utilize the GPIO Peripheral to blink a LED

  To successfully complete this exercise, students will need the following board and development environment.

  • TRK-MPC5604B evaluation board
  • CWX-MPC-5500P-EX: Evaluation: CodeWarrior for MPC55xx/MPC56xx Microcontrollers V2.8 (Classic)
  • RAppID initialization Tool
  • P&E Micro Driver Software


Read the MCU 101: LEDs article for general information on LED circuits.

The LED's are located on the board and visible in the board schematic on page 4 as below:


This schematic is found here.

Set up the Software Development Environment

There are several steps necessary to prepare the evaluation board and PC for microcontroller programming and development. Interfacing the evaluation board with a PC requires downloading and installing the CodeWarrior IDE, as well as the device drivers for programming the microcontroller via USB.

A. Download and Install Codewarrior

Before completing this example project, download and install CodeWarrior for MPC56xx 2.8 or the latest version.

B. Download and Install Drivers

In addition to CodeWarrior, it may (needs verified) be necessary to install one or both of the following tools:

  1. RAppID initialization tool- RAppID comes on the DVD provided with your evaluation board. In the main directory of the DVD, click on the "TRK_MPC5604B.html" file to open the DVD interface which provides user manuals, software, schematics and documentation for the evaluation board.
  2. P&E Microcomputer Systems, Inc drivers- P&E is a a computer driver for the TRK-MPC5604B device, enabling evaluation board programming via USB through the CodeWarrior debug OSJTAG interface. This driver can be downloaded here Because this isn't found on the disk.

Sample Code

To use the Hyperterminal communications features described in the following sections and in the attached sample code you must populate the U5 on your TRK-MPC5604B board.

Qorivva Sample Code Download

Serial Debugging:

To use hyperterminal style debugging through the Serial port you must populate U5 with a RS232 transceiver and C55.

I made the hardware modifications for serial debugging:

  1. From the Start menu Run the hyper terminal by using All programs> Accessories> Communications> HyperTerminal and make COMx properties port s
    ettings as Baud rate 115200, Data bits 8, Parity None, Stop bits 1 and Flow control None. 8. In the project menu select make (or F7) you will get few warning messages.

I did not make the hardware modifications for serial debugging:

In the project menu select MAKE (or F7) you will get few warning messages and can ignore them. Next select Debug option (or F5) from project menu. The debug window opens with few sub windows such as Code, Status and CPU etc. To run the program, select the Source GO menu button.

Note: Much of the code in the sample file is utilized to send and receive messages serially. Some quick, minor changes can be applied as follows:

Open main.c
within the for loop, remove or comment out all the code. Now, manually call the specific function desired, in this case:

for (; ; )





In sample.mcp project manager window target selection window is set to the default RAM. This means the code runs in the RAM. This target option can be changed using the drop down menu to internal_FLASH. This means the code runs in the flash and this code can run without debugger when the board is powered up. You can select either RAM target or internal_FLASH target for the following test procedure. If you select internal_FLASH target you can test the standalone operation of the board.

If you encounter errors, look in the Problems view and resolve them. You can ignore any warnings.

If the project builds correctly, it is time to download to the board and watch it work. Ensure that the USB cable that came with the board connects the board to the host computer’s USB port.
There are multiple ways to issue the Debug command. Right click the project in the projects view and choose Debug As->CodeWarrior Download. Alternatively, y go to the Run menu and choose Debug (F11).

Learning Step: LED Code Description

Within the sample code, there is a for loop which calls a switch statement. With working hyper-terminal and proper serial connector interface into a PC, entering the numerical characters "1" - "9" into the hyper-terminal will call each separate function initiating the following actions

  1. Blinks Leds & outputs text strings to hyperterminal
  2. Calls the Switch function - which sends text strings to hyperterminal indicating which switch has been pressed
  3. Calls the Servo function which sweeps the servo back and forth; sends text strings to hyperterminal
  4. Calls the motor function which enables and disables the left motor; sends status text strings to hyperterminal
  5. Calls the motor function which enables and disables the right motor; sends status text strings to hyperterminal
  6. Calls the Camera function which sends the correct signals to the camera and reads the data; sends status text strings to hyperterminal
  7. Calls the Left_Motor_Current function; sends status text strings to hyperterminal
  8. Calls the Right_Motor_Current function; sends status text strings to hyperterminal

  (hyperterminal code documentation needs verified )

TransmitData("\n\r**The Freescale Cup**");         TransmitData("\n\r*********************");         TransmitData("\n\r1.Led\n\r");         TransmitData("2.Switch\n\r");         TransmitData("3.Servo\n\r");         TransmitData("4.Motor Left\n\r");         TransmitData("5.Motor Right\n\r");         TransmitData("6.Camera\n\r");         TransmitData("7.Left Motor Current\n\r");         TransmitData("8.Right Motor Current");         TransmitData("\n\r**********************"); option = ReadData(); option = 1;     switch(option)         {             case '1':                 LED();             break;             case '2':                 SWITCH();             break;             case '3':                 SERVO();             break;             case '4':                 MOTOR_LEFT();             break;             case '5':                 MOTOR_RIGHT();             break;             case '6':                 CAMERA();             break;             case '7':                 LEFT_MOTOR_CURRENT();             break;             case '8':                 RIGHT_MOTOR_CURRENT();             break;             default:             break;          }

As visible from the schematic - the LED's are accessed via the following ports.

HardwareChip Port/PinComment


The following function is utilized in the code to blink the LED's

This function is located in main.c

void LED(void) {    SIU.PCR[68].R = 0x0200/* Program the drive enable pin of LED1 (PE4) as output*/    SIU.PCR[69].R = 0x0200/* Program the drive enable pin of LED2 (PE5) as output*/    SIU.PCR[70].R = 0x0200/* Program the drive enable pin of LED3 (PE6) as output*/    SIU.PCR[71].R = 0x0200/* Program the drive enable pin of LED4 (PE7) as output*/    TransmitData("****Led Test****\n\r");    TransmitData("All Led ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x0f000000/* Disable LEDs*/    SIU.PGPDO[2].R &= 0x07000000/* Enable LED1*/    TransmitData("Led 1 ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x08000000/* Disable LED1*/    SIU.PGPDO[2].R &= 0x0b000000/* Enable LED2*/    TransmitData("Led 2 ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x04000000/* Disable LED2*/    SIU.PGPDO[2].R &= 0x0d000000/* Enable LED3*/    TransmitData("Led 3 ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x02000000/* Disable LED3*/    SIU.PGPDO[2].R &= 0x0e000000/* Enable LED4*/    TransmitData("Led 4 ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x01000000/* Disable LED4*/ }

Code Details:

  • SIU - System Integration Unit
  • PCR - Port Configuration Register
  • PGPDO - Parallel GPIO Pad Data Output Registers : definition

From viewing the user manual, under Functional port pin descriptions, it is


Blink the LED(s):

Within the main find the infinite for loop.

for ( ; ; )



loop of Main.c, remove all code, and add the LED's with the following function:





To alter the behavior of the LEDs, change the function itself, or pull specific code from the function and insert it within loops of a program for testing purposes.

LED's are often used for testing important parts of an algorithm. By connecting an oscilloscope to a LED, it is possible to test the duration of a key algorithm, or to verify if signal timing is as expected along with the visual cue.

Other Qorivva Tutorials

  1. Qorivva: Drive DC Motor Tutorial
  2. Qorivva: Turning A Servo
  3. Qorivva: Line Scan Camera Tutorial

Useful Links to Technical Data

TRK-MPC5064B Freescale Webpage
TRK-MPC5064B Freescale Reference Manual
TRK-MPC5064B Freescale Schematic

Labels (1)

Getting errors for this code while debugging ....How to overcome this..?

Version history
Revision #:
2 of 2
Last update:
‎09-10-2020 02:23 AM
Updated by: