You are on page 1of 7

ANADOLU UNIVERSITY

DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING


EEM489 MICROPROCESSORS LABORATORY

INTRODUCTION TO ADAPT9S12E128
A SIMPLE C-PROJECT
Oct 19th, 2009
TA: KR GRGL

Adapt9S12E128 Microcontroller Module

It is important to be familiar with the development environment for a successful design and
implementation of a project. Hence, before getting started to this lab, it is assumed that you have
checked the Getting Started with CodeWarrior section of the CodeWarrior IDE software.

Creating a C Project in CodeWarrior (CW)

In CW, you can either create a project using startup wizard during CW launch or using New Project
item from the File menu.
When started to create a Project, one should select the target device or derivative for the project.
Each lab-kit Adapt9S12E128 Microcontroller Module generally has a MC9S12E128MPV 112-pin
LQFP MCU on it. Hence, the project is targeted on a MC9S12E128 MCU. You can use several
connection options such as Full Chip Simulation and HCS12 Serial Monitor for debugging your
codes.

Target Device and Connection Type

After selecting your derivative and connection type, a list of programming languages are shown to
the user. This time, select only C language, name your project and locate its path.

Project Parameters

After selecting the languages you want to use in your project and naming it, press Next button. The
Add Additional Files window appears which will allow you to add existing files to your project. This
time we have no existing files, thus, we will skip this step. Press Next button in Add Additional Files
step without any change.

Add Additional Files

The next step in creation of new projects is the Processor Expert stage. Processor Expert can
generate for you all the device initialization code. It includes many low-level drivers. Hence, we will
use processor expert to easily set device drivers and peripheral settings during the development of
the project. Select Processor Expert option and press Next.

Activating Processor Expert

The next step is selecting settings for C/C++ options. Do not change anything in this stage. Press
Finish to launch the development environment.

After creation of the project, a CPU selection window appears. Select MC9S12E128MPV 112-pins
LQFP and press OK. You can check the name-code of your CPU over the package of chip.

General CodeWarrior Project View

The following view is a snapshot after creation of a new project. There can be seen some toolboxes
such as Project View, Bean Inspector, Target CPU, and Bean Selector etc Many of them are
parts of Processor Expert tool.

Processor Expert is a very useful tool to help you in initializing device drivers and adjusting
peripherals of your MCU. Beans are used to individually set many properties of peripherals.

Controlling An I/O Pin and Setting A Periodical Timer Interrupt

In the first stage of our lab work, we will set a periodical timer interrupt to toggle (turn on and off) a
red LED on the board.
We will use Bean Selector Tool to initialize a timer interrupt. Double Click on Timing item.

Under the Timing item, double-click on Periodical Interrupt item. When you double-clicked on it,
TI1:TimerInt bean will added to your project, as you can see from the project view on the left. You
will have to set a valid timing period from the Bean Inspector toolbox for TI1 bean. Set it to 16 Hz.
Now, we will add a bean to control the red LED on board. If you look at the pdf-manuals of adapt9s12
which are located in path eem489\E128\Adapt9S12E128Docs, you will find that the red LED is
attached to the primary I/O pin PP0. Hence, we will set a bean to control PP0 pin. In Bean Selector
toolbox, click on START, then double-click on Digital input/output  Standard I/O  Individual pins.
This will add Bit1:BitIO bean to your project.
In Processor Expert view, click on Bit1:BitIO bean and see features of it in Bean Inspector toolbox.
You will select the PP0_PW00 pin from the Pin for I/O combo-box. You can set the direction of the
pin as Input, Output or both Input/Output from the Direction item in the list.

Now, MAKE your project by pushing to the Make button. During Make operation, low-level
initializations of your beans are created by processor expert tool (After adding/removing a bean, one
should remake the project to apply new settings). This also makes new bean functions be available to
the programmer (its you).

After Make operation, you will notice that some new files are added to the project.
Now, in processor expert view, expand the Bit1:BitIO bean to see the functions available.

You will use Bit1_PutVal(bool Val) function to change the value of PP0 pin, and bool
Bit1_GetVal() function to detect the value of the pin.
Now, we will set the timer interrupt functions. In processor expert view, expand TI1:TimerInt bean to
see timer functions available. Find the function TI1_OnInterrupt from the expanded list and doubleclick on it to open its c-code definition and modify TI1_OnInterrupt function as following;

void TI1_OnInterrupt(void)
{
/* Write your code here ... */
Bit1_PutVal(1 - Bit1_GetVal()); /* Toggle the value of the pin */
}

Modifications of the project have now been completed. Re-Make the project and push the Debug
button near the Make button. If you cannot see the Loading Code dialog, check following: Set the
Load-Run switch on the board to Load-mode, and be sure that your board is power-ON, serial-cableconnected, and reset. Then, retry. After load complete, debugger will not be able connect to the
board. This does NOT mean the load failed. Close the Connection Alert dialog by pushing Cancel
button. Set the Load-Run switch to Run-mode and reset the board. If everything is fine, you will see
the toggling red LED.
-

Another Simple LAB-Work

This time, your next job is to send an ascii character via the Timer interrupt created above. You
expected to achieve this task yourself. You can find a bean for Serial Communication Interface from
the Bean Selector toolbox, add it and apply necessary modifications (setting a baud-rate, putting a
code to TI1_OnInterrupt function for sending a character, etc) in your project. In each timer
interrupt, your program will send an ascii character that will be received and displayed by a serialport-terminal program such as Hyper-Term (There are a variety of programs in path
eem489\DEMOQE_Toolkit, check them). In other words, your code will communicate with terminal
using standard protocol.

You might also like