Page 459 - Programming Microcontrollers in C
P. 459

444    Chapter 8  MCORE, A RISC Machine

                   {
                       LCDDRV.COMMAND=command;
                       delay(25);
                   }
                   /* send data to the LCD */
                   void LCDData(BYTE data)
                   {
                       if (data==’\r’)
                          LCDDRV.DATA=0X01;
                       else
                          LCDDRV.DATA=data;
                       delay(25);
                   }
                          These functions do essentially the same thing. The main difference
                          is that the Command function writes to the upper byte of the specified
                          address and the Data function writes to the lower byte of this address.
                          One other special operation has been put into the Data function. If
                          the data string contains a ‘\r’ character, it is intended that the cursor
                          should be returned to the beginning of the line. The 0x01 command
                          does just that. Otherwise, the data received is sent to the screen for
                          display. It is recommended that a 25-ms delay be executed after each
                          write to the LCD system. This delay is included in both of the above
                          functions.
                              A sequence of events is needed to bring the LCD display into
                          operation. The code below first executes the initialization routine
                          above so that the LCD display is connected to the computer. There
                          immediately follows a repeated execution of the LCD command 0x03
                          three times. These instructions prepare the LCD display for operation.
                          There follows a series of commands: set the display for 2 by 40
                          character display, turn the display off, clear the display and move the
                          cursor to the home position, automatically increment cursor position
                          after each write, turn the display and cursor on, and finally shift the
                          cursor right after each input. These commands are all executed by
                          the following code.

                   /* initialize the LCD */
                   InitLCD()
                   {
                       int i;
                       initperip();         /* initialize memory block */
                       for(i=0;i<3;i++)
   454   455   456   457   458   459   460   461   462   463   464