Page 102 - Programming Microcontrollers in C
P. 102

Structures     87

                   *(void **) 0xfffc = isr;

                          places the beginning address of the function isr into the memory
                          location 0xfffc.
                              A convenient method of executing this operation is to create a
                          macro. The following macro definition works:

                   #define vector(isr, address) (*(void **)(address)=(isr))
                              Now the function call

                   vector(timer, 0xffd0);
                          will place the address of the function named timer into the loca­
                          tion 0xffd0 in the computer memory map. It is important that
                          timer be defined as a function that returns a type void.

            Structures

                              Another feature of C not found in many high-level languages is
                          the structure. A structure is similar to an array, but far more general.
                          A structure is a collection of one or more variables identified by a
                          single name. The variables can be of different types. Structures are
                          types in the sense that an int is a type. Therefore, if you have prop­
                          erly declared a structure, you may declare another structure of the
                          same type. Examine the following structure:
                   struct person
                   {
                       char *name;
                       char *address;
                       char *city;
                       char *state;
                       char *zip
                       int height;
                       int weight;
                       float salary;
                   };

                              This structure contains some of the features that describe a per­
                          son. The person’s name and address are given as pointers to character
                          strings. The person’s height and weight are integers, and the salary is
   97   98   99   100   101   102   103   104   105   106   107