next up previous
Next: How does one download Up: Background Previous: What are kernel functions?

How does one program the MicroStamp11?

Programs for the MicroStamp11 are written and compiled on a personal computer (PC) and then downloaded into the MicroStamp11 through the PC's serial port. The programs are C-language programs and we're assuming the student is already familiar (from EG111/112) with either C or C++ programming. If you need additional information, a primer on C-language programming for the MicroStamp11 will be found on the project's website.

The lab's PC's have an integrated development environment (IDE) called ICC11 that can be used to write and compile programs for the MicroStamp11. You use the IDE's editor to create C-language source files with the extension *.c. The IDE's compiler/linker then builds an executable file with the extension *.s19. The lab PC's have a batch program, pms91.bat, that is used to download the executable file into to MicroStamp11.

As an example let's consider creating a simple C-language program. Before starting, you should make sure that the home directory c:/EE224 is empty. This means that there should be no files in that directory. If any files are in the directory delete them. You should have the files kernel.c and vector.c on a floppy that you downloaded from the lab's website. Copy these files into the directory and now you're ready to start.

You begin by opening the ICC11 icon on the PC's desktop and then create a new file hello.c. An editor window should open up and you can type in your program. For starters, let's try the following program,

 #include "kernel.c"

 void main(void){

  init();
  while(1){
    OutString("Hello World");
    OutChar(CR);OutChar(LF);
    pause(100);
  }
 }
 #include"vector.c"

The preceding program is more involved than the usual "Hello World" program you may have written for a UNIX operating system (OS) and it is significantly less complex than the program you may have written for the Windows OS.

The preceding program has two include files. The included file kernel.c implements a set of kernel functions that form something like a primitive OS for the MicroStamp11. The included file vector.c defines the absolute address of your program's starting point. The only part of the program you really need to worry about lies within the scope of the main function.

The function main begins by initializing the kernel functions through the function init(). This function must always be the first thing executed by your program.

After initializing the kernel, you will find a while(1) control statement. Since 1 is a logical TRUE, the while loop's pre-condition is always satisfied. This command, therefore, sets up an infinite loop that repeatedly executes the instructions within the curly brackets. The use of while(1) constructions is unusual in traditional programming, but it is often found in embedded programming. Most traditional programs execute a specific list of statements and then terminate after some specified condition has occurred. Embedded programs, on the other hand, are usually intended to execute forever. These programs are often used to monitor a sensor or control some other physical device. In this situation, one doesn't want the program to ever stop. One way to achieve this goal is to use the while(1) statement to set up a non-terminating loop. A number of your programs throughout these labs will require this construction.

Within the while loop are kernel functions OutString(), pause, and OutChar(). The function OutString sends a character string down the serial line to your computer. The function OutChar sends a single character byte to the serial port. You use these functions to write to a terminal program running on your PC. The pause() function forces the program to wait for a specified number of clock ticks.

Note that the arguments for the function OutChar() are CR and LF. These two arguments are macros defined in kernel.c. These macros associate the logical names CR and LF with the ASCII character byte generating a "carriage return" and "line feed". So the end effect of the instructions

 OutChar(CR); OutChar(LF);
is to start a new line. In reading the listing, it should be apparent that the first thing the program does is write "Hello World" to the Hyperterm window, generate a new line, and then wait for 100 clock ticks. Because these statements are embedded within an infinite while loop, the program will repeatedly execute these instructions over and over again. So the output delivered to the PC's screen is an unending column of "Hello World"'s that are generated at a rate specified in the pause command.

To compile your program, pull down the Projects menu and select new to create a new project file. Make sure you save it in the c:\ee224 directory. Once this is done, your project should appear in the far right hand window. Looking at the PROJECT window, you'll find that there are no files in your project. Select the Projects menu and select add file(s) to add the file hello.c, that you just created. (DO NOT add the file kernel.c or vector.c to the project. These files are already includes from hello.c) you can then compile your entire project by hitting the build button in the tool bar (looks like a wall of bricks). The status of your build is displayed in the STATUS window (across the bottom). Building your program in this way creates the file hello.s19 . This file is a packed binary file that you will later download to the MicroStamp11.


next up previous
Next: How does one download Up: Background Previous: What are kernel functions?
Michael Lemmon 2009-02-01