Page 397 - Programming Microcontrollers in C
P. 397

382    Chapter 7  Advanced Topics

                       #endif
                       /* Start the linked list */
                       NEXT_OPEN = 3;/* next open entry in the list */
                       START_OF_LIST =0;/* start of the list */
                       LIST_ENTRIES=0;/* number of entries in the list */
                       epro->header[0].dataindex=NEXT_OPEN;/* start
                   the list */
                       for(i=0;i<DLEN;i++)
                        epro->header[i].next=END;


                   }
                              Listing 7-16:  The Reset Function


            Input/Output Functions

                              There are three input/output functions that are usually found in
                          the standard I/O library that we will replace with microcontroller
                          specific code here. These functions are putchar(), getchar(),
                          and puts(). In the first two instances, rather than sending and
                          receiving data from devices like stdout and stdin, all output
                          will go to the serial port on the HC12 and input will come likewise
                          from the serial port. Therefore, these routines will have to be written
                          from scratch. In addition to the direct input/output functions, an
                          initialization function that enables the serial port will be needed. This
                          function must set the bit rate for the serial port and enable both the
                          UART transmitter and receiver. This function is as follows:

                   #include “hc12.h”

                   #define BAUD9600           52


                   #define BAUDREG *(BYTE *)&SC0BDL

                   void inituart(void)
                   {
                       BAUDREG=BAUD9600;  /* Set the bit rate */
                       SC0CR2.TE=ON;              /* turn on transmitter */
                       SC0CR2.RE=ON;              /* and the receiver */
                   }
   392   393   394   395   396   397   398   399   400   401   402