10.Arduino learning notebook--1602 LCD experiment

10.Arduino learning notebook--1602 LCD experiment

          Juvtmall ( a company supply PCB PrototypingPCBA service and sell kinds of components, modules and so on) ( Catduino has the same function of Arduino)

In this experiment, using arduino to drive 1602 liquid crystal display directly.

1602 LCD is widely used in the application, the original 1602 LCD using the HD44780 controller, and now all manufacturers of 1602 modules are basically compatible with the IC, so the characteristics are basically the same.

1602LCD main technical parameters:
Display capacity is 16 × 2 characters;
The working voltage of chip is 4.5 ~ 5.5V;
Working current is 2.0mA (5.0V);
The best working voltage of the Module is 5.0V;
The character size is 2.95 × 4.35 (W × H) mm.

1602 LCD interface pin definition
number
symbol
pin definition
number
symbol
pin definition
1
VSS
GND
9
D2
Date I/O
2
VDD
10
D3
Date I/O
3
VL
Liquid crystal display bias signal
11
D4
Date I/O
4
RS
Data/command selected port(V/L)
12
D5
Date I/O
5
R/W
Reading and writing selected port(H/L)
13
D6
Date I/O
6
E
14
D7
Date I/O
7
D0
Date I/O
15
BLA
Backlight positive pole
8
D1
Date I/O
16
BLK
Backlight negative pole

Interface Description:
1, Two groups of power supply: one group is the power supply of the module, the other group is  power supply of backlight, which are generally used 5V power supply. Backlight also can work with 3.3V power supply in this experiment.
2, VL is to adjust the contrast of the pin, the series is not greater than 5KΩpotentiometer to adjust. This experiment uses a 1KΩ resistor to set the contrast. The connection is divided into high level and low level. The low level connection used in this experiment, series 1KΩresistor and then connect to the GND.

Note: Different LCD has different contrast resistance , it is best to take a potentiometer for testing, This experiment used 1 KΩ resistance in other LCD is not necessarily correct.

3, RS is a pin used in a lot of LCD, is the command / data selected pin. when the pin level is high, the data will be operated; low level of the pin means the command will be operated.
4, RW is also a pin used in a lot of LCD, is the reading and writing selected port. when the pin level is high, that is to read the LCD; low level of the pin means the writing will be operated.
5, E is also a pin used in a lot of LCD, is usually to read the data after the bus signal stabilizing for the positive pulse notification. the bus is not allowed to change when this pin is high level. 
6, D0-D7  8-bit bi-directional parallel bus, used to send commands and data.
7, BLA is the backlight positive, BLK is the backlight negative.

1602 LCD basic operations divided into the following four types:
Read the status
input
RS=L,  R/W=H,  E=H
output
D0~D7=status words
Write the command
input
RS=L,  R/W=L,
D0~D7=command code,
 E=high pulse
output
none
Read the data
input
RS=L,  R/W=H, E=H
output
D0~D7=data
Write the data
input
RS=L, R/W=L, D0~D7=data,E= high pulse
output
none

The below figure is 1602 LCD



1602 can directly communicate with arduino, according to the product manual description, sub-8-bit connection method and 4-bit connection method. Firstly, we use the 8-bit connection method for the experiment. Hardware connection as shown below



Arduino code
1. int DI = 12;
2. int RW = 11;
3. int DB [= {3, 4, 5, 6, 7, 8, 9, 10}; // use arrays to define the pins required by the bus
4. int Enable = 2;
5. 
6. void LcdCommandWrite (int value) {
7. // define all the pins
8. int i = 0;
9. for (i = DB [0; i <= DI; i ++) // bus assignment
10. {
11.     digitalWrite(i,value & 01);// because 1602 LCD signal identification is D7-D0 (not D0-D7), here is used to reverse the signal.
12.    value >> = 1;
13. }
14. digitalWrite (Enable, LOW);
15. delayMicroseconds (1);
16. digitalWrite (Enable, HIGH);
17. delayMicroseconds (1); // delay 1ms
18. digitalWrite (Enable, LOW);
19. delayMicroseconds (1); // delay 1ms
20. }
21. 
22. void LcdDataWrite (int value) {
23. // define all the pins
24. int i = 0;
25. digitalWrite (DI, HIGH);
26. digitalWrite (RW, LOW);
27. for (i = DB [0; i <= DB [7; i ++) {
28.    digitalWrite (i, value & 01);
29.    value >> = 1;
30. }
31. digitalWrite (Enable, LOW);
32. delayMicroseconds (1);
33. digitalWrite (Enable, HIGH);
34. delayMicroseconds (1);
35. digitalWrite (Enable, LOW);
36. delayMicroseconds (1); // delay 1ms
37. }
38. 
39. void setup (void) {
40. int i = 0;
41. for (i = Enable; i <= DI; i ++) {
42.    pinMode (i, OUTPUT);
43. }
44. delay (100);
45. // initialize the LCD after a short pause
46. // for LCD control
47. LcdCommandWrite (0x38); // set as 8-bit interface, 2 lines display, 5x7 text size
48. delay (64);
49. LcdCommandWrite (0x38); // set as 8-bit interface, 2 lines display, 5x7 text size
50. delay (50);
51. LcdCommandWrite (0x38); // set as 8-bit interface, 2 lines display, 5x7 text size
52. delay (20);
53. LcdCommandWrite (0x06); // input mode setting
54.                          // auto increment, no display shift
55. delay (20);
56. LcdCommandWrite (0x0E); // display the settings
57.                          // turn on the display, the cursor is displayed, no flicker
58. delay (20);
59. LcdCommandWrite (0x01); // The screen is cleared and the cursor position is reset to zero
60. delay (100);
61. LcdCommandWrite (0x80); // display the settings
62.                          // turn on the display, the cursor is displayed, no flicker
63. delay (20);
64. }
65. 
66. void loop (void) {
67.   LcdCommandWrite (0x01); // the screen is cleared and the cursor position is reset to zero
68.   delay (10);
69.   LcdCommandWrite (0x80 + 3);
70.   delay (10);
71.   // Write the welcome message
72.   LcdDataWrite ('W');
73.   LcdDataWrite ('e');
74.   LcdDataWrite ('l');
75.   LcdDataWrite ('c');
76.   LcdDataWrite ('o');
77.   LcdDataWrite ('m');
78.   LcdDataWrite ('e');
79.   LcdDataWrite ('');
80.   LcdDataWrite ('t');
81.   LcdDataWrite ('o');
82.   delay (10);
83.   LcdCommandWrite (0xc0 + 1); // Defines the cursor position as the second position of the second row.
84.   delay (10);
85.   LcdDataWrite ('g');
86.   LcdDataWrite ('e');
87.   LcdDataWrite ('e');
88.   LcdDataWrite ('k');
89.   LcdDataWrite ('-');
90.   LcdDataWrite ('w');
91.   LcdDataWrite ('o');
92.   LcdDataWrite ('r');
93.   LcdDataWrite ('k');
94.   LcdDataWrite ('s');
95.   LcdDataWrite ('h');
96.   LcdDataWrite ('o');
97.   LcdDataWrite ('p');
98.   delay (5000);
99.   LcdCommandWrite (0x01); // The screen is cleared and the cursor position is reset to zero
100.   delay (10);
101.   LcdDataWrite ('I');
102.   LcdDataWrite ('');
103.   LcdDataWrite ('a');
104.   LcdDataWrite ('m');
105.   LcdDataWrite ('');
106.   LcdDataWrite ('h');
107.   LcdDataWrite ('o');
108.   LcdDataWrite ('n');
109.   LcdDataWrite ('g');
110.   LcdDataWrite ('y');
111.   LcdDataWrite ('i');
112.   delay (3000);
113.   LcdCommandWrite (0x02); / / set the mode as the new text to replace the old one, no new text where the display is unchanged.
114.   delay (10);
115.   LcdCommandWrite (0x80 + 5); // define the cursor position as the sixth position of the first row.
116.   delay (10);
117.   LcdDataWrite ('t');
118.   LcdDataWrite ('h');
119.   LcdDataWrite ('e');
120.   LcdDataWrite ('');
121.   LcdDataWrite ('a');
122.   LcdDataWrite ('d');
123.   LcdDataWrite ('m');
124.   LcdDataWrite ('i');
125.   LcdDataWrite ('n');
126.   delay (5000);
127. }



The other blog


评论

此博客中的热门博文

21. Arduino learning notebook-- Experiment of controlling steering engine

20.Arduino learning notebook--Use Arduino Duemilanove to download the bootloader to other chips

19.Arduino learning notebook--Atmega8 makes the minimum arduino system