Newhaven LCD

The NHD-320240WG model listed here.

Wiring

Pin NameLCD Pin #mbed Pin #
Ground1Gnd
+5 V2Vu
Op. Enable4p5
RW select5p6
Reg. select6p7
Data bus7-14p8 - p15
Chip select15p16
Reset16p17
Frame Ground18Gnd
Backlight Powerp19Vu
Backlight Groundp20Gnd

Sample Code

#include "mbed.h"
#include "newhaven.h"

BusInOut  MyBus(p8,p9,p10,p11,p12,p13,p14,p15);
NHLCD   MyLCD(p5,p6,p7,p16,p17,&MyBus);

int main() {
    int i;
    MyLCD.Init();
    MyLCD.clearScreen();
    wait(.5);
    while(1)
    {
        MyLCD.text("Hello World!", 10, 1);
        wait(1);
        for(i = 0; i < 20; i++){
            MyLCD.setPixel(i,i);
        }
        wait(1);
        MyLCD.clearScreen();
        wait(1);
    }
}

/media/uploads/pbevans89/nhd1.png

Functions

  • NHLCD(PinName PIN_E,PinName PIN_RW,PinName PIN_A0,PinName PIN_CS,PinName PIN_RST, BusInOut *BUSLCD)
    • Creates an NHLCD object, specifying the control and bus pins
  • void Init()
    • Initializes the LCD. Sets the text mode to a 40x30 array. In drawing mode each address byte consists of 8 pixels.
  • void comm_out(unsigned char j)
    • Outputs an 8-bit command to the LCD.
  • void data_out(unsigned char j)
    • Outputs 8-bit data to the LCD.
  • void clearScreen()
    • Clears both the text screen and drawing screen.
  • void text(char* text, char row, char col)
    • Writes a string of text at a particular row and column. Each character is 8x8 pixels. Row and column refer to the 40x30 grid of the text screen.
  • void setPixel(int row, int col, int color)
    • Sets a pixel either on (color=1) or off (color=0). Row and column refer to the 320x240 grid of the drawing screen.
  • void drawLine(int r1, int c1, int r2, int c2, int color)
    • draws a line between two coordinates on the drawing screen.
  • void fillRect(int row, int col, int width, int height, int color)
    • fills in a rectangle on the drawing screen.

Program

Import programNewhaven_LCD

Newhaven 320x240 LCD

The above program includes a sample Pong demonstration:

/media/uploads/pbevans89/a.jpg