Programming_in_C_Tutorial

Programming_in_C_Tutorial - PURDUE UNIVERSITY Programming...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
PURDUE UNIVERSITY Programming the 9S12C32 Microprocessor in C Microprocessor System Design and Interfacing ECE 362 Course Staff 1/31/2012
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1 1 Introduction This tutorial is made to help the student use C language for programing the microcontroller. It assumes that the student knows how to program using C language. For more information about programming in C you can refer to online sources like: http://users.ece.utexas.edu/~valvano/embed/toc1.htm 2 Starting a new project in C The purpose of a using high level language like C is to speedup programming while focusing on functionality. Specific details, such as memory addresses, CPU registers, and assembly language instructions are transparent to the programmer. Such low level details are managed by the language compiler. In CodeWarrior, this is done automatically when a new C project is created. To create a new C project in CodeWarrior follow the steps below: Select File then New Project. The new project wizard will start. From Device and Connection step - Select your processor (MC9S12C32) and connection (P&E USB BDM Multilink). You may also select Full Chip Simulation if you wish to simulate the hardware. From Project Parameters step – Select the programming language (C), the project name (e.g. Test1.mcp), and the location for the files. Select Finish After CodeWarrior creates your project you will see the project window. In the left-hand window pane you will see a folder structure for the files that are part of your project. The “Sources” folder contains your source files. You should add you “C” files here. The “Includes” folder contains files specific to the model (part number) of microcontroller you are using. The “mc9s12c32.h” file declares variable names you can use to read and write the internal registers of your microcontroller. The “Libs” Folder contains files to support the specific model of microcontroller being used as well as the ANSI-C libraries you may use. The “Startup Code” folder contains code used to allow the processor to run C-language code. The “Linker Files” folder, contains files used the CodeWarrior program to compile and link your program. The most important file is the “.prm” file that specifies the overall memory map of your program (Like RAM/ROM areas) and also provides the ability to register your interrupt service routines (ISR’s). It defines “SEGMENTS” which identify portions of memory and your code and variables can be placed in those segments. The “PLACEMENT” section of the PRM file defines the names are associated with each segment.
Background image of page 2
2 3 First Program #include <hidef.h> /* common defines and macros */ #include <MC9S12C32.h> /* derivative information */ #pragma LINK_INFO DERIVATIVE "MC9S12C32" void main(void) { /* put your own code here */
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Programming_in_C_Tutorial - PURDUE UNIVERSITY Programming...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online