next up previous
Next: Compiling your Program Up: MicroStamp11 Familiarization Previous: Programming the MicroStamp11

Creating the Source File

You need to create a C-language source file. You can use any editor to create your file, but the Imagecraft ICC11 integrated development environment has a program editor built into it, so we suggest you use that one.

To use the Imagecraft ICC11, you first need to click on the ICC11 icon in the computer's desktop. You then need to create a new file in the projects directory. For starters, try typing in the following program.


 void main(void){
   int i;
   OutString("Hello World");
   PORTA = 0x00;
       PORTA ^= 0xFF;
       OutString("Goodbye CRUEL World");

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

The preceding program has two include files. The include file kernel.c contains the listing of several kernel functions. The kernel functions are special subroutines that constitute something like a rudimentary operating system for the MicroStamp11. Essentially these functions encapsulate the interface to certain micro-controller resources such as timers and I/O lines. The other include file is vector.c. This file defines the absolute address for the program's start position as well as certain interrupt vectors. In this learning module, the only part of the program you need to worry about lies within the scope of the main program.

The function main begins by declaring the integer variable $i$ and by initializing the kernel functions. This initialization is performed by the kernel function init(). The function init() must always be the first executable line in your program. After initializing the kernel, your program uses kernel functions OutString and OutChar to send characters over the serial line to the PC. The function OutString sends a character string whereas OutChar sends a single character. In this program we use OutChar to send special characters CR and LF. CR and LF are logical names for ASCII characters corresponding to line feed and carriage return. So the end effect of sending these two characters over the serial line is to cause the Hyperterm shell to start a new line.

After your program writes "Hello World" to the Hyperterm window, it sets all of the bits in the output port PORTA to zero. Remember PORTA is the logical name associated with pins 1-8 on the MicroStamp11. By setting these bits to zero we are setting the "output" pins on PORTA to their low TTL-logic value of zero volts. Remember that we've attached an LED to PA5 (pin 3), so when this command is executed, you'd expect the LED to be switched off.

After clearing PORTA, your program enters a non-terminating while loop. In this loop you first increment the integer i and then check to see if i is zero. If i==0, then you toggle the state of PORTA (causing the LED to blink) and output a different string to Hyperterm. Remember that $i$ is a 16 bit word. This means that if $i=2^{16}-1$, then adding one to this variable will reset the variable to zero. So we expect the $i==0$ condition to be periodically satisfied. The end result is that you should see the LED blinking on and off and the Hyperterm will spit out the string "Goodbye CRUEL World" every time the LED blinks.

next up previous
Next: Compiling your Program Up: MicroStamp11 Familiarization Previous: Programming the MicroStamp11
Bill Goodwine 2002-09-29