Page 389 - Programming Microcontrollers in C
P. 389

374    Chapter 7  Advanced Topics

                              r             Reset the system and erase the EEPROM array
                                            which destroys all stored information.
                              s             Display all stored data in sequence.
                              a             Display the next stored number and name.

                          The functions that perform these various operations are discussed in
                          the following sections. All of the case choices merely call the required
                          function with the exception of the ‘n’ command. The ‘n’ command
                          calls the function get() twice to read in the number followed by
                          the name. These data are stored in the designated arrays and the two
                          arrays containing the data are passed to the function saveit()
                          along with a pointer to the nonvolatile structure able. Otherwise, the
                          program remains in the FOREVER loop, exiting the loop only to
                          execute commands entered from the keyboard.

                   /* monitor.c is the initial program that is being
                       developed to use on the HC12.The end product
                       can be used as a part of a PDA or a telephone
                       that requires that you enter names and phone
                       numbers.These entries are to be saved in
                       nonvolatile RAM such as flash or EEPROM,
                       perhaps both.  In order to save memory space,
                       encoding of the stored data will be used. All
                       numbers will be stored as BCD digits and
                       letters will be stored as a Huffman code.It
                       is assumed that letter fields and number
                       fields will not contain mixed data.
                          The code in this program is programmed
                       for the DOS based system. No printf is used,
                       but other i/o functions are used as needed. It
                       is assumed now that any input will be
                       received as serial data from a serial port
                       on the chip.
                          This particular program reads data in
                       from the keyboard. The numeric field is
                       written first and the alpha field is written
                       second. If it is a numeric field, the data
                       are converted to BCD and stored in an
                       allocated memory field. If it is alpha data,
                       it is written to an allocated memory field.
   384   385   386   387   388   389   390   391   392   393   394