Page 391 - Programming Microcontrollers in C
P. 391

376    Chapter 7  Advanced Topics

                                         break;
                          case ‘r’: /* reset the system */
                                         reset(&epro);
                                         break;
                        }
                       }
                   }
                              Listing 7-12: Monitor Program


            The SAVEIT() Routine

                              The saveit() function receives the data entered from the
                          keyboard in monitor(), encodes these data and saves the result in
                          EEPROM for later use. This program is set up to save the data in a
                          linked list. The linked list is an array DLEN, found in phone.h, long
                          and each member of the list is of the type Entry. These data are
                          stored in the main data array and access to these data is made through
                          the values stored in the corresponding Entry for each set of data.
                              In the header file phone.h, several macros are defined that make it
                          somewhat easier to code this function. The first three entries in the data
                          array are used for special purposes. Therefore, these values are renamed
                          as macros to make the code more understandable. These macros are:
                   #define NEXT_OPEN epro->data[0]
                   #define START_OF_LIST epro->data[1]
                   #define LIST_ENTRIES epro->data[2]

                          Useful names can now be used rather than the cryptic actual names
                          of these various memory locations.
                              On entry to this function, both the name and number parameters
                          are encoded and the result is saved in the array name[] and
                          number[] respectively. The next block of code determines if there
                          is enough room in the EEPROM array to store all of the data. In the
                          event that there is not enough room, the message “*** buffer
                          full***” is sent to the output and control is returned to the monitor
                          program when return is executed.
                   /************************************************
                       This program works in conjunction with moni­
                   tor(). It receives the input found in monitor
   386   387   388   389   390   391   392   393   394   395   396