Page 396 - Programming Microcontrollers in C
P. 396
Reset 381
Reset
The reset function is dependent on the system being used. When
programming for the DOS-based system, the array that represents
the EEPROM is put into a state that simulates erased EEPROM. Then
the first three entries in the array data[] are initialized to the proper
values. Recall that data[0] will always contain the index to the
next open entry in the data[] array. This index is defined by a
macro in the phone.h file to be NEXT_OPEN. The next two
members data[0] and data[1] contain the index to the starting
index into the header array, START_OF_LIST and the number of
entries in the list LIST_ENTRIES respectively. The first three
members of this array are used as described above. The first available
member for storage of data is at the index 3. Therefore, NEXT_OPEN
is assigned a value of 3 and both START_OF_LIST and
LIST_ENTRIES are initialized to 0. Remember, that this data array
is the second member of a structure of the type Epro. An external
instance of this structure named able is defined in the file
monitor.h, and a pointer to this structure epro is also defined
there.
The reset() function is the first in this program that requires
code for the DOS implementation that differs from the HC12. When
the EEPROM is initialized, all bits in the memory are turned on: the
memory is filled with 0XFFFF. Therefore when simulating this
memory, the initialization will fill the memory similarly. There is a
library function in the Cosmic library, eepera(), that erases the
memory. Therefore, when coding for the HC12, this function will be
used. The code for the reset() function is shown in Listing 7-16.
#include “phone.h”
void reset(Epro *epro)
{
int i;
#ifdef DOS
memset(epro,0xff,EEPROMLEN);
/*make arrays look like EEPROM */
#else
eepera();/* erase the EEPROM with library function */

