SlideShare uma empresa Scribd logo
1 de 8
Baixar para ler offline
Published on Your Electronics Open Source (http://dev.emcelettronica.com)


Home > Blog > brumbarchris's blog > Contenuti




Getting Started with CodeWarrior IDE from
Freescale
By brumbarchris
Created May 15 2009 - 08:09


CodeWarrior Development Studio is a complete Integrated Development Environment (IDE) that
provides a highly visual and automated framework to accelerate the development of complex embedded
applications using Freescale processors. One of the best features of this environment is its support across
the most used platforms available to developers: Windows, Linux, Mac, Solaris. Also special versions exist
for specialised operating systems destined for PlayStation 2, Nintendo, Wii. Palm OS and Symbian OS can
also run CodeWarrior to some extent. The IDE is centred on C and C++ compilers and includes all the
tools necessary to complete an embedded (software) project: text editors, compilers, simulators,
debuggers etc.

Due to the huge complexity of a single tool that would support the broad range of Freescale products,
special and smaller versions of CodeWarrior are available being specialised in dealing with particular
families and architectures. This also allows for cost savings, taking into account that if you plan to use the
CodeWarrior for developing on ColdFire architectures, you would hardly need any StarCore DSP
functionality. Thus, various versions of the environment are available for purchasing and download
supporting:

         -56800/E Digital Signal Controllers
         -68k Embedded Systems
         -ColdFire architectures
         -HCS12(X) microcontrollers
         -RS08/HC microcontrollers
         -mobileGT applications
         -MPC55XX processor family
         -Power Architecture Netcomm Processors
         -StarCore DSP

Short history

CodeWarrior was initially developed by a company called Metrowerks (Canadian) and was initially
targeting the PowerPC of the Macintosh. However, after the 1999 acquisition of Metrowerks by Motorola
(the big fish eats the little fish) the scope of CodeWarrior was changed to embedded systems; after 2005
support for Mac processors was discontinued completely. Nowadays the IDE belongs to Freescale and
supports all the above mentioned targets.
On a more mundane note, the name of CodeWarrior was inspired by the Mad Max film series (Mad Max 2:
The Road Warrior)

Get started
The company I work for has recently started using HCS12 micros so we had to purchase the CodeWarrior
version dealing with them. Using a new programming environment might not have been so difficult for our
software developers (they have probably seen tens of them so far), but it was for me (I am a hardware
engineer myself). Normally I should not have dealt with writing any code at all, but due to the strain put on
all the people in the company (or on the ?resources?, as the managers put it) I had to write small pieces of
code just to test various sections of the hardware we are designing.

When I was first told we are using CodeWarrior I just told myself it must be for Freescale just what MPLAB
is for Microchip, or what AVR Studio is for Atmel (I am more familiar with these). And I was not far from the
truth (of course professional software developers might argue against this).
I tried to structure the initial experience with this powerful development environment in a few easy to follow
steps.



Step 1 ? download and installation
CodeWarrior costs money. It does not come cheap. Fortunately, Freescale makes available free versions
which only allow limited code sizes to be built. These versions are more than enough to get a heads-up on
how it looks and works.
Visit Freescale [1] in order to download any of the available packages. Because this was what I needed, I
have downloaded the special version of the HCS12X Microcontroller family and this is what I will refer to
below. Once you have downloaded it, the installation procedure is the familiar Windows style ?Next?->
?Next?->?Finish?-?Launch? process.

Alternatively, Freescale also allows the download of fully functional versions of CodeWarrior, but only for a
30-day evaluation period.



Step 2 ? Creating the project
After you launch CodeWarrior, from the top menu bar choose File->New, which will pop up the ?New?
widow which allows you to start a wizard. Select the Wizard option and enter a name for your project (in
this case, I selected the name ?Tutorial?:




Go through the wizard, selecting the MC9S12E128 as the derivation that you want to compile for and C as
the set of languages to work with:
The project wizard has quite a few pages. Go through all of them selecting successively: no Processor
Expert, no set up for PC-lint, ANSI startup code, no supported floating point format, banked memory
model. On the last page, the wizard lets you select a debugger/programmer or a simulator. For now, just
select the simulator, as you will always be able to switch to a physical device once the project has started.
And I do like to simulate my code:
Step 3 ? Writing the code
Following the successful completion of the last step in the wizard, CodeWarrior will display a Project
window docked on the left side of the environment. To get to the actual files where you write the code, you
will have to click on the small ?+? sign near the ?Sources? folder, which will reveal the existing files in your
code. For now, there are only two, and you will want to edit the main.c file, by double clicking on it.




The code automatically generated is kept to a minimum and should not be too overhelming even for a
beginner:



#include /* common defines and macros */
 #include /* derivative information */
 void main(void) {
 /* put your own code here */
 EnableInterrupts;
 for(;;) {} /* wait forever */
 /* please make sure that you never leave this function */
 }
.h>.h>



The code I needed to write in the beginning was pretty simple. The microcontroller on our project also had
the purpose (amongst others) to turn on the power supply for a different part of the circuit by toggling a pin
high. If I managed to do this, I would have been able to test the entire circuit with no help from the software
guys! They are of course, important ?resources? not to be wasted on such trivial tasks like turning a pin
high or low.
To turn pin PB7 high you only need to write two registers: PORTB and DDRB. Fortunately, all registers are
defined in the mc9s12e128.h file which is included in the beginning of the code, so I did not even have to
search the datasheet for the register addresses. The DDRB register is the direction register for PORTB
pins. When port B is operating as a general-purpose I/O port,
DDRB determines the primary direction for each port B pin. Logic 1 cause the associated port pin to be an
output and a 0 causes the associated pin to be a high-impedance input. The value in a DDR bit also affects
.h>




#include /* common defines and macros */
#include /* derivative information */
void main(void) {
/* put your own code here */
EnableInterrupts;
DDRB=0xFF;
PORTB=0x80;
for(;;) {} /* wait forever */
/* please make sure that you never leave this function */
}
.h>.h>.h>.h>



Before downloading it to the target, I wanted to make sure I got everything right and I wanted to test the
code. .h>.h>.h>.h>




Step 4 ? Simulating the code
.h>.h>.h>.h>

To simulate the code two steps are needed: first you need to build it (using compiler, linker etc) and then
you need to initialise the simulation. This is as simple as two clicks. To make the code, just hit F7.
Alternatively you may use the menu Project->Make. You should get no errors if your code is as simple as
mine.
Before you initialise the simulation you might want to have a look at all the simulation settings that can be
made. The corresponding window may be invoked by ALT+F7 or you may launch it with the menu Edit-
>Full Chip simulation Settings. Just by seeing the many tweaks and settings you can make here, you can
get a pretty good idea of how powerful and useful the simulator (and hence the environment) may be:
.h>.h>.h>.h>
For now, just leave the settings as they are and close the window. To actually start the simulation, you
need to choose from the menu Project->Debug, or alternatively just hit F5. This will open a completely new
window of CodeWarrior (which is actually to big for a print screen) containing all the relevant sub-windows
necessary for simulation (source code, disassembly window, memory map, chip settings etc).
A neat feature of CodeWarrior is that it allows you to have a visual representation of the pin states, through
a component called IO_LED. To activate the component, in the simulation window, chose from the menu
Component->Open. This will display a broad array of ?components? to choose from, the component being
basically a graphic way of displaying information. From all the options available, please choose the
?io_led? one:
.h>.h>.h>.h>




This will activate a new child window displaying 8 small round ?LEDs? to which you can associate a data
register address and a direction register address:.h>.h>.h>.h>




To make the association, I needed to consult the datasheet to find out the register addresses for PORTB
and DDRB. These are 0x0001 for PORTB and 0x0003 for DDRB and in order to associate these
addresses with the LED component you need to right click on the LEDs small window and in the newly
open dialog box enter these two addresses:
.h>.h>.h>.h>
Once this last step is finished, you may consider yourself ready to commence the simulation. This can be
easily done from the green ?Start? button available on the top toolbar, or alternatively by pressing F5 again:
.h>.h>.h>.h>




The simulation is fast, and once the lines of code setting the values for DDRB and PORTB are reached,
you will notice the LEDs change colour to this:
.h>.h>.h>.h>




I guess red means logic high and green means logic low (it?s quite the other way around from what I would
make of things, but of course, this is just a detail).
.h>.h>.h>.h>



Step 5 ? Downloading to the target
.h>.h>.h>.h>

From now on it really gets dependent on the programmer you have. To download the compiled code to the
real microcontroller, in the simulation window that has been created at the previous step select Component-
>Set Connection. This will open a new window where you will be able to select the programmer that you
.h>




Once you complete the above 5 steps you should be able to go ahead on your own. CodeWarrior itself is
not difficult to use, and the sheer array of options makes it very flexible.
More information and download under: CodeWarrior Development Tools [2]
.h>.h>.h>.h>

Read the Italian version: Iniziare con CodeWarrior IDE della Freescale [3]

CONTACT REQUEST
If you want to know more about this Freescale product, please submit your request to Arrow Italy using
this form [4].
NOTE: this form is valid ONLY for Companies or Customers based in Italy and working in the Italian area.

                                    Embedded CodeWarrior Freescale ide programming environment Tutorial

                                                   Trademarks




Source URL: http://dev.emcelettronica.com/getting-started-codewarrior-ide-freescale

Links:
[1] http://www.freescale.com/webapp/sps/site/overview.jsp?code=CW_SPECIALEDITIONS&tid=CWH
[2] http://www.freescale.com/webapp/sps/site/homepage.jsp?nodeId=012726
[3] http://it.emcelettronica.com/iniziare-con-codewarrior-ide-della-freescale
[4] http://it.emcelettronica.com/contact/freescale

Mais conteúdo relacionado

Mais de Ionela

Flyport openPicus datasheet
Flyport openPicus datasheetFlyport openPicus datasheet
Flyport openPicus datasheetIonela
 
Windows phone 7 è l’ultima occasione di microsoft 2010-10-18
Windows phone 7 è l’ultima occasione di microsoft   2010-10-18Windows phone 7 è l’ultima occasione di microsoft   2010-10-18
Windows phone 7 è l’ultima occasione di microsoft 2010-10-18Ionela
 
Videocamera cam ball un mare di caratteristiche nella piccola videocamera a ...
Videocamera cam ball  un mare di caratteristiche nella piccola videocamera a ...Videocamera cam ball  un mare di caratteristiche nella piccola videocamera a ...
Videocamera cam ball un mare di caratteristiche nella piccola videocamera a ...Ionela
 
Utente premium 2010-10-17
Utente premium   2010-10-17Utente premium   2010-10-17
Utente premium 2010-10-17Ionela
 
Unity sostituisce gnome su ubuntu 11.04 2010-11-01
Unity sostituisce gnome su ubuntu 11.04   2010-11-01Unity sostituisce gnome su ubuntu 11.04   2010-11-01
Unity sostituisce gnome su ubuntu 11.04 2010-11-01Ionela
 
Una retina artificiale per ridare la vista 2010-11-10
Una retina artificiale per ridare la vista   2010-11-10Una retina artificiale per ridare la vista   2010-11-10
Una retina artificiale per ridare la vista 2010-11-10Ionela
 
Un orologio elettronico completo basato su i2 c rtcc mcp79410 2010-10-29
Un orologio elettronico completo basato su i2 c rtcc mcp79410   2010-10-29Un orologio elettronico completo basato su i2 c rtcc mcp79410   2010-10-29
Un orologio elettronico completo basato su i2 c rtcc mcp79410 2010-10-29Ionela
 
Ultimo lancio discovery delle perdite rinviano l’ultimo lancio dello shuttle...
Ultimo lancio discovery  delle perdite rinviano l’ultimo lancio dello shuttle...Ultimo lancio discovery  delle perdite rinviano l’ultimo lancio dello shuttle...
Ultimo lancio discovery delle perdite rinviano l’ultimo lancio dello shuttle...Ionela
 
Ubuntu passa a wayland 2010-11-08
Ubuntu passa a wayland   2010-11-08Ubuntu passa a wayland   2010-11-08
Ubuntu passa a wayland 2010-11-08Ionela
 
Touchatag un'applicazione di internet delle cose 2010-11-10
Touchatag  un'applicazione di internet delle cose   2010-11-10Touchatag  un'applicazione di internet delle cose   2010-11-10
Touchatag un'applicazione di internet delle cose 2010-11-10Ionela
 
Tianhe 1, il supercomputer cinese - 2010-11-05
Tianhe 1, il supercomputer cinese - 2010-11-05Tianhe 1, il supercomputer cinese - 2010-11-05
Tianhe 1, il supercomputer cinese - 2010-11-05Ionela
 
Thread o processo quale usare - 2010-11-02
Thread o processo  quale usare  - 2010-11-02Thread o processo  quale usare  - 2010-11-02
Thread o processo quale usare - 2010-11-02Ionela
 
Termometro digitale usando pic16 f84a schema elettrico - 2010-11-03
Termometro digitale usando pic16 f84a   schema elettrico - 2010-11-03Termometro digitale usando pic16 f84a   schema elettrico - 2010-11-03
Termometro digitale usando pic16 f84a schema elettrico - 2010-11-03Ionela
 
Telescopio webb il sistema di engineering del telescopio webb della nasa si ...
Telescopio webb  il sistema di engineering del telescopio webb della nasa si ...Telescopio webb  il sistema di engineering del telescopio webb della nasa si ...
Telescopio webb il sistema di engineering del telescopio webb della nasa si ...Ionela
 
Tecnologia light peak intel potrebbe adottarla da inizio 2011, apple a segui...
Tecnologia light peak  intel potrebbe adottarla da inizio 2011, apple a segui...Tecnologia light peak  intel potrebbe adottarla da inizio 2011, apple a segui...
Tecnologia light peak intel potrebbe adottarla da inizio 2011, apple a segui...Ionela
 
Tastiere capacitive 2010-11-10
Tastiere capacitive   2010-11-10Tastiere capacitive   2010-11-10
Tastiere capacitive 2010-11-10Ionela
 
Supporto wi max toshiba introduce il supporto wimax nei notebook portégé r70...
Supporto wi max  toshiba introduce il supporto wimax nei notebook portégé r70...Supporto wi max  toshiba introduce il supporto wimax nei notebook portégé r70...
Supporto wi max toshiba introduce il supporto wimax nei notebook portégé r70...Ionela
 
Stm32 vl discovery recensione - 2010-11-11
Stm32 vl discovery   recensione  - 2010-11-11Stm32 vl discovery   recensione  - 2010-11-11
Stm32 vl discovery recensione - 2010-11-11Ionela
 
Starter kit cpld cool runner ii della xilinx - 2010-11-09
Starter kit cpld cool runner ii della xilinx - 2010-11-09Starter kit cpld cool runner ii della xilinx - 2010-11-09
Starter kit cpld cool runner ii della xilinx - 2010-11-09Ionela
 
Ssd now v100 kingston lancia i suoi nuovi dischi allo stato solido - 2010-11-10
Ssd now v100  kingston lancia i suoi nuovi dischi allo stato solido - 2010-11-10Ssd now v100  kingston lancia i suoi nuovi dischi allo stato solido - 2010-11-10
Ssd now v100 kingston lancia i suoi nuovi dischi allo stato solido - 2010-11-10Ionela
 

Mais de Ionela (20)

Flyport openPicus datasheet
Flyport openPicus datasheetFlyport openPicus datasheet
Flyport openPicus datasheet
 
Windows phone 7 è l’ultima occasione di microsoft 2010-10-18
Windows phone 7 è l’ultima occasione di microsoft   2010-10-18Windows phone 7 è l’ultima occasione di microsoft   2010-10-18
Windows phone 7 è l’ultima occasione di microsoft 2010-10-18
 
Videocamera cam ball un mare di caratteristiche nella piccola videocamera a ...
Videocamera cam ball  un mare di caratteristiche nella piccola videocamera a ...Videocamera cam ball  un mare di caratteristiche nella piccola videocamera a ...
Videocamera cam ball un mare di caratteristiche nella piccola videocamera a ...
 
Utente premium 2010-10-17
Utente premium   2010-10-17Utente premium   2010-10-17
Utente premium 2010-10-17
 
Unity sostituisce gnome su ubuntu 11.04 2010-11-01
Unity sostituisce gnome su ubuntu 11.04   2010-11-01Unity sostituisce gnome su ubuntu 11.04   2010-11-01
Unity sostituisce gnome su ubuntu 11.04 2010-11-01
 
Una retina artificiale per ridare la vista 2010-11-10
Una retina artificiale per ridare la vista   2010-11-10Una retina artificiale per ridare la vista   2010-11-10
Una retina artificiale per ridare la vista 2010-11-10
 
Un orologio elettronico completo basato su i2 c rtcc mcp79410 2010-10-29
Un orologio elettronico completo basato su i2 c rtcc mcp79410   2010-10-29Un orologio elettronico completo basato su i2 c rtcc mcp79410   2010-10-29
Un orologio elettronico completo basato su i2 c rtcc mcp79410 2010-10-29
 
Ultimo lancio discovery delle perdite rinviano l’ultimo lancio dello shuttle...
Ultimo lancio discovery  delle perdite rinviano l’ultimo lancio dello shuttle...Ultimo lancio discovery  delle perdite rinviano l’ultimo lancio dello shuttle...
Ultimo lancio discovery delle perdite rinviano l’ultimo lancio dello shuttle...
 
Ubuntu passa a wayland 2010-11-08
Ubuntu passa a wayland   2010-11-08Ubuntu passa a wayland   2010-11-08
Ubuntu passa a wayland 2010-11-08
 
Touchatag un'applicazione di internet delle cose 2010-11-10
Touchatag  un'applicazione di internet delle cose   2010-11-10Touchatag  un'applicazione di internet delle cose   2010-11-10
Touchatag un'applicazione di internet delle cose 2010-11-10
 
Tianhe 1, il supercomputer cinese - 2010-11-05
Tianhe 1, il supercomputer cinese - 2010-11-05Tianhe 1, il supercomputer cinese - 2010-11-05
Tianhe 1, il supercomputer cinese - 2010-11-05
 
Thread o processo quale usare - 2010-11-02
Thread o processo  quale usare  - 2010-11-02Thread o processo  quale usare  - 2010-11-02
Thread o processo quale usare - 2010-11-02
 
Termometro digitale usando pic16 f84a schema elettrico - 2010-11-03
Termometro digitale usando pic16 f84a   schema elettrico - 2010-11-03Termometro digitale usando pic16 f84a   schema elettrico - 2010-11-03
Termometro digitale usando pic16 f84a schema elettrico - 2010-11-03
 
Telescopio webb il sistema di engineering del telescopio webb della nasa si ...
Telescopio webb  il sistema di engineering del telescopio webb della nasa si ...Telescopio webb  il sistema di engineering del telescopio webb della nasa si ...
Telescopio webb il sistema di engineering del telescopio webb della nasa si ...
 
Tecnologia light peak intel potrebbe adottarla da inizio 2011, apple a segui...
Tecnologia light peak  intel potrebbe adottarla da inizio 2011, apple a segui...Tecnologia light peak  intel potrebbe adottarla da inizio 2011, apple a segui...
Tecnologia light peak intel potrebbe adottarla da inizio 2011, apple a segui...
 
Tastiere capacitive 2010-11-10
Tastiere capacitive   2010-11-10Tastiere capacitive   2010-11-10
Tastiere capacitive 2010-11-10
 
Supporto wi max toshiba introduce il supporto wimax nei notebook portégé r70...
Supporto wi max  toshiba introduce il supporto wimax nei notebook portégé r70...Supporto wi max  toshiba introduce il supporto wimax nei notebook portégé r70...
Supporto wi max toshiba introduce il supporto wimax nei notebook portégé r70...
 
Stm32 vl discovery recensione - 2010-11-11
Stm32 vl discovery   recensione  - 2010-11-11Stm32 vl discovery   recensione  - 2010-11-11
Stm32 vl discovery recensione - 2010-11-11
 
Starter kit cpld cool runner ii della xilinx - 2010-11-09
Starter kit cpld cool runner ii della xilinx - 2010-11-09Starter kit cpld cool runner ii della xilinx - 2010-11-09
Starter kit cpld cool runner ii della xilinx - 2010-11-09
 
Ssd now v100 kingston lancia i suoi nuovi dischi allo stato solido - 2010-11-10
Ssd now v100  kingston lancia i suoi nuovi dischi allo stato solido - 2010-11-10Ssd now v100  kingston lancia i suoi nuovi dischi allo stato solido - 2010-11-10
Ssd now v100 kingston lancia i suoi nuovi dischi allo stato solido - 2010-11-10
 

CodeWarrior with Open Source C Compilator from Freescale

  • 1. Published on Your Electronics Open Source (http://dev.emcelettronica.com) Home > Blog > brumbarchris's blog > Contenuti Getting Started with CodeWarrior IDE from Freescale By brumbarchris Created May 15 2009 - 08:09 CodeWarrior Development Studio is a complete Integrated Development Environment (IDE) that provides a highly visual and automated framework to accelerate the development of complex embedded applications using Freescale processors. One of the best features of this environment is its support across the most used platforms available to developers: Windows, Linux, Mac, Solaris. Also special versions exist for specialised operating systems destined for PlayStation 2, Nintendo, Wii. Palm OS and Symbian OS can also run CodeWarrior to some extent. The IDE is centred on C and C++ compilers and includes all the tools necessary to complete an embedded (software) project: text editors, compilers, simulators, debuggers etc. Due to the huge complexity of a single tool that would support the broad range of Freescale products, special and smaller versions of CodeWarrior are available being specialised in dealing with particular families and architectures. This also allows for cost savings, taking into account that if you plan to use the CodeWarrior for developing on ColdFire architectures, you would hardly need any StarCore DSP functionality. Thus, various versions of the environment are available for purchasing and download supporting: -56800/E Digital Signal Controllers -68k Embedded Systems -ColdFire architectures -HCS12(X) microcontrollers -RS08/HC microcontrollers -mobileGT applications -MPC55XX processor family -Power Architecture Netcomm Processors -StarCore DSP Short history CodeWarrior was initially developed by a company called Metrowerks (Canadian) and was initially targeting the PowerPC of the Macintosh. However, after the 1999 acquisition of Metrowerks by Motorola (the big fish eats the little fish) the scope of CodeWarrior was changed to embedded systems; after 2005 support for Mac processors was discontinued completely. Nowadays the IDE belongs to Freescale and supports all the above mentioned targets. On a more mundane note, the name of CodeWarrior was inspired by the Mad Max film series (Mad Max 2: The Road Warrior) Get started The company I work for has recently started using HCS12 micros so we had to purchase the CodeWarrior
  • 2. version dealing with them. Using a new programming environment might not have been so difficult for our software developers (they have probably seen tens of them so far), but it was for me (I am a hardware engineer myself). Normally I should not have dealt with writing any code at all, but due to the strain put on all the people in the company (or on the ?resources?, as the managers put it) I had to write small pieces of code just to test various sections of the hardware we are designing. When I was first told we are using CodeWarrior I just told myself it must be for Freescale just what MPLAB is for Microchip, or what AVR Studio is for Atmel (I am more familiar with these). And I was not far from the truth (of course professional software developers might argue against this). I tried to structure the initial experience with this powerful development environment in a few easy to follow steps. Step 1 ? download and installation CodeWarrior costs money. It does not come cheap. Fortunately, Freescale makes available free versions which only allow limited code sizes to be built. These versions are more than enough to get a heads-up on how it looks and works. Visit Freescale [1] in order to download any of the available packages. Because this was what I needed, I have downloaded the special version of the HCS12X Microcontroller family and this is what I will refer to below. Once you have downloaded it, the installation procedure is the familiar Windows style ?Next?-> ?Next?->?Finish?-?Launch? process. Alternatively, Freescale also allows the download of fully functional versions of CodeWarrior, but only for a 30-day evaluation period. Step 2 ? Creating the project After you launch CodeWarrior, from the top menu bar choose File->New, which will pop up the ?New? widow which allows you to start a wizard. Select the Wizard option and enter a name for your project (in this case, I selected the name ?Tutorial?: Go through the wizard, selecting the MC9S12E128 as the derivation that you want to compile for and C as the set of languages to work with:
  • 3. The project wizard has quite a few pages. Go through all of them selecting successively: no Processor Expert, no set up for PC-lint, ANSI startup code, no supported floating point format, banked memory model. On the last page, the wizard lets you select a debugger/programmer or a simulator. For now, just select the simulator, as you will always be able to switch to a physical device once the project has started. And I do like to simulate my code:
  • 4. Step 3 ? Writing the code Following the successful completion of the last step in the wizard, CodeWarrior will display a Project window docked on the left side of the environment. To get to the actual files where you write the code, you will have to click on the small ?+? sign near the ?Sources? folder, which will reveal the existing files in your code. For now, there are only two, and you will want to edit the main.c file, by double clicking on it. The code automatically generated is kept to a minimum and should not be too overhelming even for a beginner: #include /* common defines and macros */ #include /* derivative information */ void main(void) { /* put your own code here */ EnableInterrupts; for(;;) {} /* wait forever */ /* please make sure that you never leave this function */ } .h>.h> The code I needed to write in the beginning was pretty simple. The microcontroller on our project also had the purpose (amongst others) to turn on the power supply for a different part of the circuit by toggling a pin high. If I managed to do this, I would have been able to test the entire circuit with no help from the software guys! They are of course, important ?resources? not to be wasted on such trivial tasks like turning a pin high or low. To turn pin PB7 high you only need to write two registers: PORTB and DDRB. Fortunately, all registers are defined in the mc9s12e128.h file which is included in the beginning of the code, so I did not even have to search the datasheet for the register addresses. The DDRB register is the direction register for PORTB pins. When port B is operating as a general-purpose I/O port, DDRB determines the primary direction for each port B pin. Logic 1 cause the associated port pin to be an output and a 0 causes the associated pin to be a high-impedance input. The value in a DDR bit also affects
  • 5. .h> #include /* common defines and macros */ #include /* derivative information */ void main(void) { /* put your own code here */ EnableInterrupts; DDRB=0xFF; PORTB=0x80; for(;;) {} /* wait forever */ /* please make sure that you never leave this function */ } .h>.h>.h>.h> Before downloading it to the target, I wanted to make sure I got everything right and I wanted to test the code. .h>.h>.h>.h> Step 4 ? Simulating the code .h>.h>.h>.h> To simulate the code two steps are needed: first you need to build it (using compiler, linker etc) and then you need to initialise the simulation. This is as simple as two clicks. To make the code, just hit F7. Alternatively you may use the menu Project->Make. You should get no errors if your code is as simple as mine. Before you initialise the simulation you might want to have a look at all the simulation settings that can be made. The corresponding window may be invoked by ALT+F7 or you may launch it with the menu Edit- >Full Chip simulation Settings. Just by seeing the many tweaks and settings you can make here, you can get a pretty good idea of how powerful and useful the simulator (and hence the environment) may be: .h>.h>.h>.h>
  • 6. For now, just leave the settings as they are and close the window. To actually start the simulation, you need to choose from the menu Project->Debug, or alternatively just hit F5. This will open a completely new window of CodeWarrior (which is actually to big for a print screen) containing all the relevant sub-windows necessary for simulation (source code, disassembly window, memory map, chip settings etc). A neat feature of CodeWarrior is that it allows you to have a visual representation of the pin states, through a component called IO_LED. To activate the component, in the simulation window, chose from the menu Component->Open. This will display a broad array of ?components? to choose from, the component being basically a graphic way of displaying information. From all the options available, please choose the ?io_led? one: .h>.h>.h>.h> This will activate a new child window displaying 8 small round ?LEDs? to which you can associate a data register address and a direction register address:.h>.h>.h>.h> To make the association, I needed to consult the datasheet to find out the register addresses for PORTB and DDRB. These are 0x0001 for PORTB and 0x0003 for DDRB and in order to associate these addresses with the LED component you need to right click on the LEDs small window and in the newly open dialog box enter these two addresses: .h>.h>.h>.h>
  • 7. Once this last step is finished, you may consider yourself ready to commence the simulation. This can be easily done from the green ?Start? button available on the top toolbar, or alternatively by pressing F5 again: .h>.h>.h>.h> The simulation is fast, and once the lines of code setting the values for DDRB and PORTB are reached, you will notice the LEDs change colour to this: .h>.h>.h>.h> I guess red means logic high and green means logic low (it?s quite the other way around from what I would make of things, but of course, this is just a detail). .h>.h>.h>.h> Step 5 ? Downloading to the target .h>.h>.h>.h> From now on it really gets dependent on the programmer you have. To download the compiled code to the real microcontroller, in the simulation window that has been created at the previous step select Component- >Set Connection. This will open a new window where you will be able to select the programmer that you
  • 8. .h> Once you complete the above 5 steps you should be able to go ahead on your own. CodeWarrior itself is not difficult to use, and the sheer array of options makes it very flexible. More information and download under: CodeWarrior Development Tools [2] .h>.h>.h>.h> Read the Italian version: Iniziare con CodeWarrior IDE della Freescale [3] CONTACT REQUEST If you want to know more about this Freescale product, please submit your request to Arrow Italy using this form [4]. NOTE: this form is valid ONLY for Companies or Customers based in Italy and working in the Italian area. Embedded CodeWarrior Freescale ide programming environment Tutorial Trademarks Source URL: http://dev.emcelettronica.com/getting-started-codewarrior-ide-freescale Links: [1] http://www.freescale.com/webapp/sps/site/overview.jsp?code=CW_SPECIALEDITIONS&tid=CWH [2] http://www.freescale.com/webapp/sps/site/homepage.jsp?nodeId=012726 [3] http://it.emcelettronica.com/iniziare-con-codewarrior-ide-della-freescale [4] http://it.emcelettronica.com/contact/freescale