Page 388 - Programming Microcontrollers in C
P. 388

The Monitor Program     373

                              The final portion of this header file is a collection of all of the
                          function prototypes needed for this program. When this program is
                          moved from the DOS-based system to the microcontroller-based
                          system, it is necessary to remove the first line of the above header
                          file. There are three functions found in the standard input/output
                          library that will be rewritten for this program. These functions are
                          inituart(), putchar(), getchar() and puts(). The
                          function prototypes for these functions are included and will be
                          discarded when the parameter DOS is not defined.
                              The monitor program is shown below in Listing 7-12. In the
                          header file above, a structure was typedefed as an Epro. This
                          structure is the size of the EEPROM on board the chip. An external
                          instance of an Epro, named able, is created and it will be used as
                          a destination for all of the nonvolatile stored data in the program.
                              Inside the main() program, two arrays are created: one array to
                          store the name entered from the keyboard and the other to store the
                          phone number entered from the keyboard. Also, the external structure
                          will be passed around from function to function via a pointer. This
                          pointer is created and initialized to the structure able. Also, if the
                          parameter DOS is not defined, the function inituart() is executed
                          to enable the use of the UART on the microcontroller when it is needed.
                              After this initialization is completed, control is passed into a
                          FOREVER loop where it will remain so long as the computer
                          continues to run. Within this loop, an input is read from the keyboard.
                          It is assumed that the keyboard input will read in the data and return
                          ASCII characters. If the system is a part of a telephone or a PDA, the
                          input routine will have to read in the keyboard data and convert it to
                          the correct ASCII value prior to its use in the following program.
                          Therefore, getchar() in the following program can be a function
                          that reads data from a serial port or some other program that will
                          input the data from whatever keyboard is used with the system. Inside
                          of the FOREVER loop, a character is read in and then it is tested in
                          a switch()/case sequence. The current test values are ‘n’, ‘a’,
                          ‘s’, and ‘r’. These inputs are commands that determine what the
                          program will do:

                              Command       Action
                              n             Read in a number/name sequence, encode these
                                            data and save them in the nonvolatile array.
   383   384   385   386   387   388   389   390   391   392   393