Page 385 - Programming Microcontrollers in C
P. 385
370 Chapter 7 Advanced Topics
This function is tested with the following program:
#include <stdio.h>
void get(char *, int);
#define LENGTH 15
main()
{
char data[LENGTH];
get(data,LENGTH);
if(data[0]==’\0')
printf(“Buffer overflow\n”);
else
puts(data);
}
Listing 7-10: get() Test Routine
This program reads in a line of data and echoes the string to the
computer screen. If the length of the input data is longer than the
specified length, the Buffer overflow message is printed to the screen.
The Monitor Program
The next program to be written is the monitor routine. This
function executes all of the time and receives data from the keyboard.
It will interpret the entries and pass control to the appropriate function
to execute. In building all of the functions, monitor(),
printafter(), printout(), and reset(), there are a large
number of constants and function prototypes that must be included
in each function. All of these items will be collected together into a
single header file to be included in each function. This header file is
shown below as Listing 7-11. This file starts with the usual multiple
inclusion protection. The code for this program will be tested
completely on a DOS-based system before it is compiled for use for
the final microcontroller. There are a couple of items needed for the
DOS-based system that are not needed for the microcontroller.
Therefore, the parameter DOS is defined at the beginning of the header