LMG1278 LCD Module Datasheet 1) General specification 1.1 Mechanical Dimension Item Number of characters Module dimension (L x W x H) View area

Dimension 16 characters x 1 line 80.5x36.5x6.6

Unit mm.

64.1x13.7

mm.

1.2 Controller IC: SED1278 (EPSON) 1.3 Temperature Range Normal 0~+50˚C -10~+60˚C

Operating Storage

2) Absolute maximum ratings Item Symbol Supply voltage Vdd-Vss Input voltage Vi 3) Electrical characteristics Item Symbol Supply voltage Vdd – Vss Input high VIH Input low VIL Output high VOH Output low VOL Supply current IDD

Min -0.3 Vss Min 2.0 Vss 2.4 -

Type 5.0 0.5

Max 7 Vdd Max Vdd 0.8 Vdd 0.4 0.8

Unit V V Unit V V V V V mA

Pin No. 1 2 3 4 5 6

4) Interface pin function Wire Symbol Level color Black D7 H/L Brown D6 H/L Red D5 H/L Orange D4 H/L Yellow E H,H→ L Green R/W H/L

7

Blue

RS

H/L

8 9 10

Purple Gray White

Vo Vdd Vss

Variable 5.0V 0V

Description Data bit 7 Data bit 6 Data bit 5 Data bit 4 Chip enable H: Read (MCU→Module) L: Write (MCU→Module) H: Data L: Instruction Operating voltage for LCD Supply voltage Ground

5) Display command

6) Character font

7) Drawing

8) Code example Note: Compiled by CCS and deployed on PIC16F913 or PIC16F914. LCD016M001L.C /////////////////////////////////////////////////////////////////////////// //// LCD016M001.C //// //// Driver for common LCD modules (KS0066) //// //// //// //// lcd_init() Must be called before any other function. //// //// //// //// lcd_putc(c) Will display c on the next position of the LCD. //// //// The following have special meaning: //// //// \f Clear display //// //// \n Go to start of second line //// //// \b Move back one position //// //// //// //// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) //// //// //// //// lcd_getc(x,y) Returns character at position x,y on LCD //// //// //// /////////////////////////////////////////////////////////////////////////// // *** Port C of PIC16F9xx, there're pins VLCD1, VLCD2, VLCD3 which are enabled (1) by default // register LCDCON (address 107h, at bit4 VLCDEN). This make these pins can't be used as I/O. // So the must thing to do first is to disable (0) this bit. // For CCS compiler, there will have built-in function as the named setup_lcd() which can be found // in 16F913.h. So we can declare at the first main (before lcd initial) as setup_lcd(LCD_DISABLED); // For Hitech C, there's no built-in function. So we need to clear bit 4 of LCDCON manually. // Like this bitclr(LCDCON, 4); // As defined in the following structure the pin connection is as follows: // RD0 rs // RD1 rw // RD2 e // RD4 D4 // RD5 D5 // RD6 D6 // RD7 D7 // // LCD pins D0-D3 are not used and PIC RD3 is not used. // ***Important thing if use Vishay LCD016M001L version Vee on board // ---> pin 15 is A for B/L and also is Vee (~ -5V). So this can't be drive the B/L // When using B/L, it is strongly noted to use pin A and K (separated from 16 pin connector) // by desoldering RA out (normally RA=0 and shorted pin 15 and pin A (at LED) together both be Vee) // ***Backlighgt at pin A of Vishay brand (LCD-016M001L), it's shown in datasheet that recommended to // supply to pin A only 4.2V. So it must be connected by diode (1N4001 or 1N4002 or BY251) in order to // drop out from 5V supply.

// Normally pin K (for B/L) isn't connected to GND pin // rs = 0 ------> Instruction/ rs = 1 ------> Data // rw = 0 ------> Write / rw = 1 ------> Read // DDRAM = 0x8x (1xxxxxxx) ---> Starting at first line and position. // So example of DDRAM 00H will become to 80H // DDRAM LINE1 0x00 to 0x07 (8, half left) and 0x40 to 0x47 (8, half right) // So DDRAM becomes to: // LINE1 0x80 to 0x87 (8, half left) and 0xC0 to 0xC7 (8, half right) // **This is 1 line but DDRAM is separated to 2 address ranges, so acting like 2 lines (use 2 lines mode) // (n Left shift data in n to 2 bits [Ex. n=0x03 (00000011) ---> 00001100 = 0x0C] // (n >> 4) -----> Right shift data in n to 4 bits [Ex. n=0x28 (00101000) ---> 00000010 = 0x02] // Un-comment the following define to use port B // #define use_portb_lcd TRUE

/* This structure is overlayed on to an I/O port to gain access to the LCD pins. The bits are allocated from low order up. ENABLE will be pin B0. */ struct lcd_pin_map { int1 rs; // RD0 (int1 = int 1 bit) int1 rw; // RD1 int1 e; // RD2 int1 unused; // RD3 int data : 4; // RD4-RD7 } lcd;

#if defined use_portc_lcd #locate lcd = getenv("sfr:PORTC") // This puts the entire structure over the port #define set_tris_lcd(x) set_tris_c(x) #else #locate lcd = getenv("sfr:PORTD") // This puts the entire structure over the port #define set_tris_lcd(x) set_tris_d(x) #endif

#define lcd_type 2

// 0=5x7 and 1 line, 1=5x10, 2=2 lines

#define lcd_line_one_hl 0x00 // LCD RAM address for the half left first line #define lcd_line_one_hr 0x40 // LCD RAM address for the half right first line

// These bytes need to be sent to the LCD to start it up. // 0x0C is display on-off control --> Display on, cursor off, cursor blink off // 0x01 is clear display // 0x06 is entry mode set --> cursor moves to right and DDRAM address is increased by 1 // 0x28 is function set --> 4 bit mode, 2 line display mode, 5x8 dots format int const LCD_INIT_STRING[4] = {0x20 | (lcd_type 00000010 = 0x02 lcd_send_nibble(n & 0x0F); // Send 4 bits LSB then, ex. n=0x28 (00101000) --> 00001000 = 0x08 } // Initialization chip void lcd_init(void)

{ int i; set_tris_lcd(LCD_WRITE); lcd.rs = 0; lcd.rw = 0; lcd.e = 0; delay_ms(15);

// Direction of data pins are set to 0x00 (output)

for(i=0; i Set DDRAM address

} // Data is needed to be sent void lcd_putc(char c) { switch (c) { case '\f' : lcd_send_byte(0, 1); DDRAM 00H delay_ms(2); break; case '\n' : lcd_gotoxy(1, 2); case '\b' : lcd_send_byte(0, 0x10); default : lcd_send_byte(1, c); } }

// Clear and return to home

break; break; break;

// go to half right position

// Returns character at position x,y on LCD char lcd_getc(int x, int y) { char value; lcd_gotoxy(x,y); while ( bit_test(lcd_read_byte(),7) ); lcd.rs = 1; value = lcd_read_byte(); lcd.rs = 0; return(value);

// wait until busy flag is low

}

Main.c /* #include called by compiler

// No need to add header file, it'll be automatically

// Header file must be in the same folder with project #fuses INTRC_IO,NOPROTECT,NOWDT,NOBROWNOUT,NOPUT,MCLR,DEBUG #use delay(clock=4000000) */

#include called by compiler

// No need to add header file, it'll be automatically // Header file must be in the same

folder with project #fuses HS,NOWDT,NOPUT,MCLR,NOPROTECT,NOBROWNOUT,DEBUG #use delay(clock=8000000) #define use_portc_lcd TRUE

#include "LCD016M001L.c" /* LCD command \f clear display \n Go to start of second line \b Move back one position */ void main(void) { setup_lcd(LCD_DISABLED); lcd_init(); while(1) { printf(lcd_putc, "\fWELCOME\nTO..."); delay_ms(2000); printf(lcd_putc, "\fELECTRON\nICS"); delay_ms(2000); printf(lcd_putc, "\fSOURCE C\nO., LTD."); delay_ms(2000); printf(lcd_putc, "\fThe art \nof..."); delay_ms(2000); printf(lcd_putc, "\fELECTRON\nICS"); delay_ms(2000); printf(lcd_putc, "\fThis is \n16x1 dot"); delay_ms(2000); printf(lcd_putc, "\fcharacte\nr LCD"); delay_ms(2000); printf(lcd_putc, "\fPart Num\nber:"); delay_ms(2000); printf(lcd_putc, "\fLMG1278"); delay_ms(2000); printf(lcd_putc, "\fBrand: ES"); delay_ms(2000); } }