Плата расширения (Shield) LCD1602 Keypad
Описание пинов и пример скетча:
The VSS power ground 9 D2 data
2 VDD positive power supply 10 D3 data
11 D4 Data 3 VL LCD bias
4 RS data / command select 12 D5 data
5 R / W Read / Write Select 13 D6 data
6 E 14 D7 data enable signal
7 D0 data the 15 BLA backlight source positive
8 D1 data the 16 BLK backlight negative
Pin 1: VSS ground power.
Pin 2: VDD connected to the 5V positive supply.
Pin 3: VL LCD display contrast adjustment terminal connected to the positive power supply contrast weakest ground when contrast
Highest contrast is too high will produce "ghosting", used by a 10K potentiometer to adjust the contrast.
4-pin: RS register select the data register, select, high and low, select the instruction register.
Pin 5: R / W for read and write signal line, a high read operation, write operation is low. When RS
Low and R / W can be written instructions or display address when RS is high for the low-level R / W
Read busy signal, when the RS is high level R / W is low can write data.
: E end of the first 6 feet to enable end, When E Duanyou high jump goes low, the LCD module execute command.
7 to 14 feet: D0 ~ D7 8-bit bi-directional data line.
15 feet: backlight positive.
16 feet: backlight negative.
The 1602LCD the instruction descriptions:
1602 LCD module within the controller 11 control commands, such as table shown in the table below:
The serial directive RS R / W D7 D6 D5 D4 D3 D2 D1 D0
Clear screen 1 0 0 0 0 0 0 0 0 0 1
2 cursor returns 000,000,001 *
3 is set to the input mode 0 0 0 0 0 0 0 1 I / D S
4 shows the ON / OFF control 0 0 0 0 0 0 1 D C B
5 cursor or character shift 0 0 0 0 0 1 S / C R / L **
6 set function 0 0 0 0 1 DL N F **
7 set character generator memory address 0001 character generator memory address
8 set data memory address 001 to display the data memory address
9 read busy flag or address 0 1 BF counter address
10 write the number to CGRAM or DDRAM) 1 0 write data content
11 11 reads out the data content from CGRAM or DDRAM readings
1602 LCD module of read and write operations, the operation of the screen and the cursor are achieved through instruction programming. (Note: a high, 0 low)
Directive 1: clear script 01H, the cursor reset to address 00H position.
Instruction 2: Cursor reset, the cursor returns to the address 00H.
Instruction 3: cursor and display mode settings I / D: Move the cursor direction, high to the right, low level to the left S:
All the text on the screen whether the left or the right. High indicates low invalid.
Instruction 4: switch control. D: on and off, control the overall display a high level open display, low power
Level expressed concern C: control the cursor on and off high indicates the cursor, low non-cursor B: control
Made whether the cursor is flashing, high flash, low level does not blink.
Directive 5: cursor or display shift S / C: high mobile display text, low, move the cursor.
Instruction 6: Function Set command DL: high four bus low level for 8-bit bus N: low power
Usually displayed as a single line, two-line display F: 5x7 dot matrix characters, high low when high
5x10 dot matrix characters.
Directive 7: The character generator RAM address set.
Directive 8: DDRAM address setting.
Directive 9: read a busy signal and cursor address BF: for busy flag high indicates busy, the module can not be connected
Received command or data, if is low is not busy.
Directive 10: write data.
Instruction 11: read data.
Compatible with the HD44780 chip timing table is as follows:
Read Status input RS = L, R / W = H, E = H output D0-D7 = Status Word
Write instructions input RS = L, R / W = L, D0-D7 = script, E = high pulse output without
Read data input RS = H, R / W = H, E = H output D0-D7 = data
Write data input RS = H, R / W = L, D0-D7 = Data, E = high pulse output without
1602LCD general initialization (reset) process:
Delay 15mS
Write command 38H (does not detect a busy signal)
Delay 5mS
Write command 38H (does not detect a busy signal)
Delay 5mS
Write command 38H (does not detect a busy signal)
Each subsequent write instruction, read / write data operations are necessary to detect a busy signal
Write instruction 38H: display mode setting
Written instructions 08H: display off
Written instructions 01H: clear screen
Written instructions 06H: Move the cursor is set
Write instruction 0CH: open and the cursor is set
AUDUINO official routine:
/ / Example use of LCD4Bit_mod library
# Include
/ / Create object to control an LCD.
/ / Number of lines in display = 1
LCD4Bit_mod lcd = LCD4Bit_mod (2);
/ / Key message
char msgs [5] [15] = {"Right Key OK",
"Up Key OK",
"Down Key OK",
"Left Key OK",
"Select Key OK"};
int adc_key_val [5] = {30, 150, 360, 535, 760};
int NUM_KEYS = 5;
int adc_key_in;
int key = -1;
int oldkey = -1;
void setup () {
pinMode (13, OUTPUT); / / we'll use the debug LED to output a heartbeat
lcd.init ();
/ / Optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init ()
/ / Lcd.commandWrite (0x0F) ;/ / cursor on, display on, blink on. (Nasty!)
lcd.clear ();
lcd.printIn ("KEYPAD testing ... pressing");
}
void loop () {
adc_key_in = analogRead (0); / / read the value from the sensor
digitalWrite (13, HIGH);
key = get_key (adc_key_in); / / convert into key press
if (key! = oldkey) / / if keypress is detected
{
delay (50); / / wait for debounce time
adc_key_in = analogRead (0); / / read the value from the sensor
key = get_key (adc_key_in); / / convert into key press
if (key! = oldkey)
{
oldkey = key;
if (key> = 0) {
lcd.cursorTo (2, 0); / / line = 2, x = 0
lcd.printIn (msgs [key]);
}
}
}
/ / Delay (1000);
digitalWrite (13, LOW);
}
/ / Convert ADC value to key number
int get_key (unsigned int input)
{
int k;
for (k = 0; k <NUM_KEYS; k + +)
{
if (input
{
return k;
}
}
if (k> = NUM_KEYS)
k = -1; / / No valid key pressed
return k;
}