Вы находитесь на странице: 1из 12

Interfacing LCD with PIC Microcontroller

• 16×2 Character LCD is a very basic LCD module


which is commonly used in electronics projects
and products. It contains 2 rows that can display
16 characters.
PIN Description of LDC display module
• EN – Enable:
This control line is used to inform the LCD that you are sending in
data. To send data to the LCD, put data on the data bus, then
make EN high (1) and wait a little bit and end by bringing EN to
low (0) again.
• RS – Register Select:
When RS is low (0), the information in the DB0 to DB7 pins are
to be considered as an instruction (command- such as Clear
screen, Display set, etc.). When RS is high (1), the information in
the DB0 to DB7 pins are to be considered valid text data to print
on the LCD screen. For example, to display the letter “i” on the
screen you should set RS= high.
• RW – Read/Write:
When RW is low (0), the information on the data bus is written
to the LCD module.
• DB0 to DB7:
Data bus lines of LCD display.
• LED+, LED-:
Used for enabling back light on the screen. If you don’t want the
back light you can leave it unconnected.
LCD modes of Interfacing with PIC Microcontroller
• 4 Bit Mode Circuit Diagram
8 Bit Mode Circuit Diagram
Lab. Exercise 3
LCD Text Display using PIC16F877 Microcontroller

• Circuit Design
LCD1
RV1 LM016L
98%

1k

VDD
VSS

VEE

RW
RS

D0
D1
D2
D3
D4
D5
D6
D7
E
1
2
3

4
5
6

7
8
9
10
11
12
13
14
U1
13 33
OSC1/CLKIN RB0/INT
14 34
OSC2/CLKOUT RB1
1 35
MCLR/Vpp/THV RB2
36
RB3/PGM
2 37
RA0/AN0 RB4
3 38
RA1/AN1 RB5
4 39
RA2/AN2/VREF- RB6/PGC
5 40
RA3/AN3/VREF+ RB7/PGD
6
RA4/T0CKI
7 15
RA5/AN4/SS RC0/T1OSO/T1CKI
16
RC1/T1OSI/CCP2
8 17
RE0/AN5/RD RC2/CCP1
9 18
RE1/AN6/WR RC3/SCK/SCL
10 23
RE2/AN7/CS RC4/SDI/SDA
24
RC5/SDO
25
RC6/TX/CK
26
RC7/RX/DT
19
RD0/PSP0
20
RD1/PSP1
21
RD2/PSP2
22
RD3/PSP3
27
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877
Simulation Code
• // Lcd pinout settings
• sbit LCD_RS at RB0_bit;
• sbit LCD_EN at RB1_bit;
• sbit LCD_D4 at RB2_bit;
• sbit LCD_D5 at RB3_bit;
• sbit LCD_D6 at RB4_bit;
• sbit LCD_D7 at RB5_bit;

• // Pin direction
• sbit LCD_RS_Direction at TRISB0_bit;
• sbit LCD_EN_Direction at TRISB1_bit;
• sbit LCD_D4_Direction at TRISB2_bit;
• sbit LCD_D5_Direction at TRISB3_bit;
• sbit LCD_D6_Direction at TRISB4_bit;
• sbit LCD_D7_Direction at TRISB5_bit;

• void main()
• {
• Lcd_Init();
• Lcd_Out(1, 1, "Hello!");
• Lcd_Cmd(_LCD_CURSOR_OFF);

• }

Lab. Exercise 4
Temperature value of LM35 Display in LCD

Materials Required
• LM35 temperature sensor
• LM016L LCD
• Crystal Oscillator 4Mhz
• Two 22pF capacitors
• 5V DC power supply
• PIC16F877 Microcontroller Chip
Circuit Design
VCC

C1 LCD1
C2 22PF
RV1 LM016L
22PF

X1

52%
VEE

CRYSTAL VSS
1k

VDD
VSS

VEE

RW
RS

D0
D1
D2
D3
D4
D5
D6
D7
E
VCC

1
2
3

4
5
6

7
8
9
10
11
12
13
14
1 U2
U5
13 33
OSC1/CLKIN RB0/INT
14 34
146.0 OSC2/CLKOUT RB1
1 35
MCLR/Vpp/THV RB2
36
RB3/PGM
2 2 37
VOUT RA0/AN0 RB4
3 38
RA1/AN1 RB5
4 39
RA2/AN2/VREF- RB6/PGC
5 40
RA3/AN3/VREF+ RB7/PGD
3 LM35 6
RA4/T0CKI
7 15
RA5/AN4/SS RC0/T1OSO/T1CKI
16
RC1/T1OSI/CCP2
8 17
RE0/AN5/RD RC2/CCP1
9 18
RE1/AN6/WR RC3/SCK/SCL
10 23

VEE
RE2/AN7/CS RC4/SDI/SDA
24
RC5/SDO
25
RC6/TX/CK
26
RC7/RX/DT
19
RD0/PSP0
20
RD1/PSP1
21
RD2/PSP2
22
RD3/PSP3
27
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877
Simulation Code
• / Lcd pinout settings
• sbit LCD_RS at RB0_bit;
• sbit LCD_EN at RB1_bit;
• sbit LCD_D4 at RB2_bit;
• sbit LCD_D5 at RB3_bit;
• sbit LCD_D6 at RB4_bit;
• sbit LCD_D7 at RB5_bit;

• // Pin direction
• sbit LCD_RS_Direction at TRISB0_bit;
• sbit LCD_EN_Direction at TRISB1_bit;
• sbit LCD_D4_Direction at TRISB2_bit;
• sbit LCD_D5_Direction at TRISB3_bit;
• sbit LCD_D6_Direction at TRISB4_bit;
• sbit LCD_D7_Direction at TRISB5_bit;
• int value;
• char value1 [15];

• void main()
• {
• TRISA.RA0=1; //set port A0 as analog input
• ADC_INIT();
• LCD_INIT();
• Lcd_Cmd(_LCD_CLEAR); // Clear display
• Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
• Lcd_Out(1,1," Temperature"); // Write text in first row
• Delay_ms(2000);
• while (1)
• {
• value=adc_read (0);
• value=value*0.488;
• floattostr(value,value1);
• lcd_chr(2,10,39);
• lcd_out(2,10,"C");
• lcd_out(2,1,value1);
• delay_ms(500);
• }
• }

Вам также может понравиться