Newhaven LCD
The NHD-320240WG model listed here.
Wiring¶
Pin Name | LCD Pin # | mbed Pin # |
---|---|---|
Ground | 1 | Gnd |
+5 V | 2 | Vu |
Op. Enable | 4 | p5 |
RW select | 5 | p6 |
Reg. select | 6 | p7 |
Data bus | 7-14 | p8 - p15 |
Chip select | 15 | p16 |
Reset | 16 | p17 |
Frame Ground | 18 | Gnd |
Backlight Power | p19 | Vu |
Backlight Ground | p20 | Gnd |
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); } }
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: