LPC812 MAX Experiment: Character LCD

Experiment: Character LCD

In this experiment you will learn how to control a character LCD display. The display is a LMB162AFC-2 from TOPWAY and the manual for it can be found here.

Hardware

In this lab you will need:

  • 1x breadboard
  • 1x character LCD
  • cables

Mount the components on the breadboard and connect the breadboard to the LPC812 as show in the image below.

Breadboard Setup

The pin(s) are specified in the mbed library with the actual pin names as well as some useful aliases:

Schematic Namembed Pin NameArduino Shield AliasDescription
PIO0_0P0_0D0RS - Register Select
PIO0_4P0_4D1R/W - Read / Write Control Bus
PIO0_8P0_8D3E - Data Enable
PIO0_13P0_13D10DB4
PIO0_14P0_14D11DB5
PIO0_15P0_15D12DB6
PIO0_12P0_12D13DB7

As the display will be used in 4 bit mode, the DB0 to DB3 pins are left unconnected.

Description

There is an mbed library that supports our character LCD:

Import library

Public Types

enum LCDType {
LCD8x1 , LCD8x2 , LCD8x2B , LCD12x2 ,
LCD12x4 , LCD16x1 , LCD16x2 , LCD16x2B ,
LCD16x4 , LCD20x2 , LCD20x4 , LCD24x2 ,
LCD24x4 , LCD40x2 , LCD40x4
}

LCD panel format.

More...
enum LCDCtrl { HD44780 , WS0010 , ST7036 }

LCD Controller Device.

More...
enum LCDCursor { CurOff_BlkOff = 0x00, CurOn_BlkOff = 0x02, CurOff_BlkOn = 0x01, CurOn_BlkOn = 0x03 }

LCD Cursor control.

More...
enum LCDMode { DispOff = 0x00, DispOn = 0x04 }

LCD Display control.

More...
enum LCDBacklight { LightOff , LightOn }

LCD Backlight control.

More...

Public Member Functions

TextLCD (PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type=LCD16x2, PinName bl=NC, PinName e2=NC, LCDCtrl ctrl=HD44780)
Create a TextLCD interface for using regular mbed pins.
TextLCD (I2C *i2c, char deviceAddress, LCDType type=LCD16x2, LCDCtrl ctrl=HD44780)
Create a TextLCD interface using an I2C PC8574 portexpander.
TextLCD (SPI *spi, PinName cs, LCDType type=LCD16x2, LCDCtrl ctrl=HD44780)
Create a TextLCD interface using an SPI 74595 portexpander.
int putc (int c)
Write a character to the LCD.
int printf (const char *format,...)
Write a formated string to the LCD.
void locate (int column, int row)
Locate to a screen column and row.
int getAddress (int column, int row)
Return the memoryaddress of screen column and row location.
void setAddress (int column, int row)
Set the memoryaddress of screen column and row location.
void cls ()
Clear the screen and locate to 0,0.
int rows ()
Return the number of rows.
int columns ()
Return the number of columns.
void setCursor ( LCDCursor cursorMode)
Set the Cursormode.
void setMode ( TextLCD::LCDMode displayMode)
Set the Displaymode.
void setBacklight ( TextLCD::LCDBacklight backlightMode)
Set the Backlight mode.
void setUDC (unsigned char c, char *udc_data)
Set User Defined Characters.

The library is described in detail here.

Start with this basic program:

main.cpp

#include "mbed.h"
#include "TextLCD.h"

Serial pc(USBTX, USBRX); // tx, rx

TextLCD lcd(D0, D3, D10, D11, D12, D13, TextLCD::LCD16x2); // rs, e, d4-d7

int main()
{
    pc.printf("LCD Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());

    // Clear screen
    lcd.cls();      
    
    lcd.printf("Hello\nWorld!");
    wait(3);

    // Example using putc() which automatically moves the cursor
    lcd.cls();
    for (char c = '0'; c <= 'Z' ; c++)
    {
        lcd.putc(c);
        wait(0.3);
    }

    while(1)
        ;
}

Test the different functions in the TextLCD library and get to know how the cursor works and how to handle cls() and locate().

If you have a GPS module, go back to the GPS experiment and print the latitude and longitude information on the display instead of the terminal.

Solution(s)

Import programlpc812_exp_solution_character-lcd

Solutions for the Character LCD experiments for LPC812 MAX


1 comment on LPC812 MAX Experiment: Character LCD:

08 Mar 2015

Hi guys,

Once I am trying to compile the program, I am receiving some of the following error messages:

Error: No space in execution regions with .ANY selector matching ctype_c.o(.constdata). Error: No space in execution regions with .ANY selector matching TextLCD.cpp.LPC812.o(i._ZN7TextLCDD1Ev). Error: No space in execution regions with .ANY selector matching FileLike.o(.constdataZTVN4mbed8FileLikeE). Error: No space in execution regions with .ANY selector matching FileBase.o(i._ZN4mbed8FileBaseD1Ev). Error: No space in execution regions with .ANY selector matching Serial.o(i._ZN4mbed6SerialC1E7PinNameS1_PKc). . . . .

Error: Sections of aggregate size 0xac4 bytes could not fit into .ANY selector(s).

I am using LPC812 Max Board. I suppose it is because of the RAM. This LPC has only 4KB.

Any clues?

Thanks,

Filip

Please log in to post comments.