10600 - LCD

2011.06.30

LCD

The full name is alpha-numeric-dot-matrix liquid crystal display.

Traditionally, the first step in getting familiar with a new microcontroller is to add some LED's to a parallel port, with or without a buffer, and to show some LED patterns.

Subsequently, a shift register can be added immediately, perhaps to play with a 7-segment display. The shift register is helpful later for the addition of an LCD.

Nowadays, the availability of LCD's and OLED's makes the LED's look primitive.
Besides, with an LCD, development work can be more pleasant. Besides, more information can be displayed on the LCD than on 8 LED’s. It is harder to program for an LCD. But the learning is worthwhile and the knowledge gained can be applied for any microcontroller. In the academic environment, the teacher can write the driver for the beginners.

The most commonly used LCD has two lines by 16 characters.

The first problem with an LCD is that it has 14 terminals. But nowadays, with 4-wire mode, only 10 terminals are required. Although this is still quite a lot to connect, the connections are straight forward.

If the LCD is connected to and driven by GPIO pins, 6 GPIO pins will be required. Besides, the driver codes written would have to be changed if the GPIO pins are changed for a different application or if a different microcontroller is used. So it is more efficient to connect the LCD to the microcontroller through the SPI port, with just one additional GPIO pin for the E pin of the LCD.


            STM8S105                  74HC164                    LCD

            Vdd                 to         Vdd and /MR to         Vcc
            Vss                  to         Vss                  to         Ground, Vo and R/W

            SClk(PC5)       to         Clock
            MOSI(PC6)    to         A1 and A2 (A and B)

                                                Qh                   to         D7
Qg                   to         D6
Qf                    to         D5
Qe                   to         D4
Qa                   to         RS
                                                [or Qb,…]
            PG1                                                     to         E


The second problem is that most affordable LCD operates at 5 V. So a separate 5-V supply may be required for the LCD. The signals can still be at 3.3 V. Alternatively the board can be connected to operate at 5 V using the jumper on the board.

The initialization (and programming) for the LCD is more complicated in 4–wire mode than in 8–wire mode. But such details can be obtained from LCD manuals. The following sequence had been tested and worked many times:

    LCDinit(0x30);
    LCDinit(0x30);     
    LCDinit(0x30);
    LCDinit(0x30);    
    LCDinit(0x30);   // Actually 3 lines should be sufficient
    LCDinit(0x20);  
  
    LCDinit(0x20);
    LCDinit(0x80);     
    LCDinit(0x00);
    LCDinit(0xF0);    
    LCDinit(0x00);
    LCDinit(0x60);          
    LCDinit(0x00);
    LCDinit(0x10); 
   
    LCDinit(0x80);  // Upper row
    LCDinit(0xA0);  // Column 10     
    LCDinit(0x51);  // 'S' 
    LCDinit(0x31);   


Finally, it is better to write many functions for the LCD which can be used as required.