An operating system (OS) is a set of functions or programs that coordinate a user program's access to the computer's resources (i.e. memory and CPU). Large operating systems such as UNIX and Windows are probably familiar to most students. The MicroStamp11 is also a computer but it is so simple that no OS is hardwired into it. In particular, every program you write for the MicroStamp11 will need to include certain functions that can be thought of as forming a primitive OS for the device. These functions are called the MicroStamp11's kernel functions.
We've written a set of kernel functions that can be used by
your program. These functions are contained in
kernel.c
, a file that can be downloaded off the
course's website. A partial list of the functions that you
might need for this lab are provided below. A more
complete list will appear in some of the later labs.
For the program you'll be asked to write in this lab you will need functions that allow the MicroStamp11 to communicate with the PC over a serial link. These communication kernel functions are:
void init(void);
Description: This function initializes the global variables within the MicroStamp11 kernel functions. It must be the first function called by any MicroStamp11 program using the kernel.
Usage: init();
void OutChar(char data)
Description: This function writes a single byte
data
to the MicroStamp11's asynchronous serial
interface (SCI). This function is used to write single
characters to a terminal program running on a PC connected
to the MicroStamp11 over the SCI port. Some special
character macros are CR
(carriage return), LF
(line feed), SP
(space), BS
(backspace),
DEL
(delete), ESC
(escape). These special
characters can be used for advanced control of the
terminal's output.
Usage: The following statement
OutChar('n');outputs the ASCII string for the letter 'n' to the serial port.
void OutString(char *pt)
Description: This function writes a character string
defined by the character pointer pt
to the
MicroStamp11's asynchronous serial interface (SCI). This
function is used to write a string of characters to a
terminal program running on a PC connected to the
MicroStamp11 over the SCI port.
Usage: The following statement
OutString("Hello World");writes the string
Hello World
to the terminal
window.
void OutUDec(unsigned short number)
Description: This function translates an unsigned
short integer number
into an ASCII string and then
sends that string to the MicroStamp11's asynchronous
serial interface (SCI).
Usage: The following statements
i = 5; OutUDec(i);would write the integer 5 in the terminal window.
char InChar(void)
Description: This function waits for the asynchronous serial port to receive a single character from the terminal program and returns the received character byte.
Usage: The following statement
char i; i=InChar();reads a single character from the terminal window and assigns that character to the variable
i
.
void InString(char *string, unsigned int max)
Description: This function waits for the
asynchronous serial port to receive data from the terminal
program. The received string is then stored in the
character string with pointer string
having a
maximum of max
entries.
Usage: The following statements
char my_string[10]; InString(my_string,10);declare a character array
my_string
consisting
of 10 characters, waits for the SCI port to receive data,
and
then fills the declared string my_string
with the
received characters.
unsigned short InUDec(void)
Description This function waits for the asynchronous serial port to receive ASCII bytes representing unsigned integers from the terminal program. The received bytes are then translated from their ASCII format to an unsigned integer and the resulting number is returned by the function.
Usage: The following statements
unsigned short i; i=InUDec();wait for the SCI system to receive data, transforms the received bytes into a short unsigned integer and then stores the received number in the variable
i
.