lcd (16x2) user guide

5
 LCD (16x2) User Guide

Upload: xiu-yangying-xiong

Post on 03-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

8/12/2019 LCD (16x2) User Guide

http://slidepdf.com/reader/full/lcd-16x2-user-guide 1/5

 

LCD (16x2)

User Guide

8/12/2019 LCD (16x2) User Guide

http://slidepdf.com/reader/full/lcd-16x2-user-guide 2/5

1.0 The connection of LCD (16 X 2) with microcontroller PIC16F877A

2.0 Pin Declaration

PIN Declaration Function1 VSS Connect to Ground

2 VCC / VDD Connect to VDD / 5V

3 VEE Adjust the contrast of LCD

4 RS 0: Send configure 1: Send character

5 R / W 0: Write to LCD 1: Read from LCD

6 E Give pulse for send configure or character

7 D0 LCD data

8 D1 LCD data

9 D2 LCD data

10 D3 LCD data

11 D4 LCD data12 D5 LCD data

13 D6 LCD data

14 D7 LCD data

15 A For LCD back light (connect to VDD)

16 K For LCD back light (connect to Ground)

8/12/2019 LCD (16x2) User Guide

http://slidepdf.com/reader/full/lcd-16x2-user-guide 3/5

3.0 The source code for interfacing between LCD (16 x 2) with PIC16F877A

#include<PIC.h>

//configuration

 __CONFIG ( 0x3F32 ); //configuration for the microcontroller

#define RS RB4 //RS pin of the LCD display

#define E RB5 //E pin of the LCD display

#define lcd_data PORTD //LCD 8-bit data PORT

//function prototype LCD

void delay(unsigned long data);

void LCD(void);void send_config(unsigned char data);

void send_char(unsigned char data);

void lcd_goto(unsigned char data);

void lcd_clr(void);

void send_string(const char *s);

void main(void)

{

//setup ADC

ADCON1 = 0b00000110; //set ADx pin digital I/O

//set I/O input output

TRISB = 0b00000000;

TRISD = 0b00000000;

//configure lcd

send_config(0b00000001); //clear display at lcd

send_config(0b00000010); //lcd return to home

send_config(0b00000110); //entry mode-cursor increase 1send_config(0b00001100); //display on, cursor off and cursor blink off

send_config(0b00111000); //function set

//display startup message

lcd_clr(); //clear lcd

lcd_goto(5); //set the lcd cursor to location 0

8/12/2019 LCD (16x2) User Guide

http://slidepdf.com/reader/full/lcd-16x2-user-guide 4/5

  send_string("HAPPY"); //display word in 1st line

lcd_goto(24); //set the lcd cursor to location 20

send_string("ROBOSHOP"); //display word in second line

while(1); //loop forever

}

void delay(unsigned long data) //delay function, the delay time

{ //depend on the given value

for( ;data>0;data--);

}

void send_config(unsigned char data) //send lcd configuration

{

RS=0; //set lcd to configuration modelcd_data=data; //lcd data port = data

E=1;

delay(500); //pulse e to confirm the data

E=0;

delay(500);

}

void send_char(unsigned char data) //send lcd character

{

RS=1; //set lcd to display modelcd_data=data; //lcd data port = data

E=1; //pulse e to confirm the data

delay(100);

E=0;

delay(100);

}

8/12/2019 LCD (16x2) User Guide

http://slidepdf.com/reader/full/lcd-16x2-user-guide 5/5

void lcd_goto(unsigned char data) //set the location of the lcd cursor

{ //if the given value is (0-15) the

if(data<16) //cursor will be at the upper line

{ //if the given value is (20-35) the

send_config(0x80+data); //cursor will be at the lower line

} //location of the lcd cursor(2X16):

else // -----------------------------------------------------

{ // | |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| |

data=data-20; // | |20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| |

send_config(0xc0+data); // -----------------------------------------------------

}

}

void lcd_clr(void) //clear the lcd

{send_config(0x01);

delay(600);

}

void send_string(const char *s) //send a string to display in the lcd

{

while (s && *s)send_char (*s++);

}