Page 460 - Programming Microcontrollers in C
P. 460
Adding a Display 445
LCDCommand(0x03); /* get things turned on */
LCDCommand(0x3c); /* 2x40 display */
LCDCommand(0x08); /* display off */
LCDCommand(0x01); /* clear display and home cursor */
LCDCommand(0x06); /* increment cursor position */
LCDCommand(0x0f); /* Display and cursor on */
LCDCommand(0x14); /* Shift cursor right */
}
The function LCDData() shown above performs the essential
operation of the putchar() that we have used so often above. In
our program above, we used putchar() everywhere. It seems that
we should have a separate command for the LCD display, but at the
same time, it would be desirable that we could write to the LCD with
a putchar() and not have to worry about changing all of the
occurrences of putchar() in the earlier code. A way around this
problem is to use a simple macro
#define putchar(a) LCDData(a)
and now we can use putchar() in place of LCDData(). Of course,
it is important that we do not link serial1.o to the program, and
the inclusion of serial.h is no longer needed.
One item that must be considered here is the use of the function
delay(). Recall that delay() uses the pit to clock the delay time.
The function in Listing 8-1 turns the pit on at the beginning of the
operation and off at the end. We cannot allow this function to turn
the pit off because the pit is being used by the basic clock function.
Therefore, the two lines of code
ITCSR.EN=ON;
.
.
.
ITCSR.EN=OFF;
must be removed from the delay routine. The function now will work
correctly, and it will not interfere with the operation of the basic pit
operation used by the clock. This modified function is delay2.c
on the CD-ROM.
Usually, a complete listing of the program is included in earlier
chapters of this text. In this case, the code is approximately 250 lines
long, and it is not so important to see this amount of code. It is all

