HD44780 LCD Module
The HD44780 is one of the most popular alphanumeric LCD modules and is used both in industry and by hobbyists. This module is monochrome and comes in different sizes.
Table 6.10: Pin configuration of HD44780 LCD module
| Pin no. | Name | Function |
|---|---|---|
| 1 | VSS | Ground |
| 2 | VDD | + ve supply |
| 3 | VEE | Contrast |
| 4 | RS | Register select |
| 5 | R/W | Read/write |
| 6 | E | Enable |
| 7 | D0 | Data bit 0 |
| 8 | D1 | Data bit 1 |
| 9 | D2 | Data bit 2 |
| 10 | D3 | Data bit 3 |
| 11 | D4 | Data bit 4 |
| 12 | D5 | Data bit 5 |
| 13 | D6 | Data bit 6 |
| 14 | D7 | Data bit 7 |
Modules with 8, 16, 20, 24, 32, and 40 columns are available. Depending on the model chosen, the number of rows may be 1, 2, or 4. The display provides a 14-pin (or 16-pin) connector to a microcontroller. Table 6.10 gives the pin configuration and pin functions of a 14-pin LCD module. The following is a summary of the pin functions:
VSS is the 0V supply or ground. The VDD pin should be connected to the positive supply. Although the manufacturers specify a 5V DC supply, the modules will usually work with as low as 3V or as high as 6V.
Pin 3, named VEE, is the contrast control pin. This pin is used to adjust the contrast of the display and should be connected to a variable voltage supply. A potentiometer is normally connected between the power supply lines with its wiper arm connected to this pin so that the contrast can be adjusted.
Pin 4 is the register select (RS), and when this pin is LOW, data transferred to the display is treated as commands. When RS is HIGH, character data can be transferred to and from the module.
Pin 5 is the read/write (R/W) line. This pin is pulled LOW in order to write commands or character data to the LCD module. When this pin is HIGH, character data or status information can be read from the module.
Pin 6 is the enable (E) pin, which is used to initiate the transfer of commands or data between the module and the microcontroller. When writing to the display, data is transferred only on the HIGH-to-LOW transition of this line. When reading from the display, data becomes available after the LOW-to-HIGH transition of the enable pin, and this data remains valid as long as the enable pin is at logic HIGH.
Pins 7 to 14 are the eight data bus lines (D0 to D7). Data can be transferred between the microcontroller and the LCD module using either a single 8-bit byte or as two 4-bit nibbles. In the latter case, only the upper four data lines (D4 to D7) are used. The 4-bit mode means that four fewer I/O lines are used to communicate with the LCD. In this book we are using only an alphanumeric-based LCD and only the 4-bit interface.
Connecting the LCD
The mikroC compiler assumes by default that the LCD is connected to the microcontroller as follows:
LCD Microcontroller port
D7 Bit 7 of the port
D6 Bit 6 of the port
D5 Bit 5 of the port
D4 Bit 4 of the port
E Bit 3 of the port
RS Bit 2 of the port
where port is the port name specified using the Lcd_Init statement.
For example, we can use the statement Lcd_Init(&PORTB) if the LCD is connected to PORTB with the default connection.
It is also possible to connect the LCD differently, using the command Lcd_Config to define the connection.
Project Hardware
Figure 6.38 shows the block diagram of the project. The microcontroller reads the analog voltage, converts it to digital, formats it, and then displays it on the LCD.
Figure 6.38: Block diagram of the project
The circuit diagram of the project is shown in Figure 6.39. The voltage to be measured (between 0 and 5V) is applied to port AN0 where this port is configured as an analog input in software. The LCD is connected to PORTC of the microcontroller as in the default four-wire connection. A potentiometer is used to adjust the contrast of the LCD display.
Figure 6.39: Circuit diagram of the project
Project PDL
The PDL of the project is shown in Figure 6.40. At the beginning of the program PORTC is configured as output and PORTA is configured as input. Then the LCD and the A/D converter are configured. The program then enters an endless loop where analog input voltage is converted to digital and displayed on the LCD. The process is repeated every second.
START
Configure PORTC as outputs
Configure PORTA as input
Configure the LCD
Configure the A/D converter
DO FOREVER
Read analog data (voltage) from channel 0
Format the data