1602LCD command Description:
1602 LCD controller within the total 11 control orders, as shown in the table the following table:
Ordinal number instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0
1 Qing ping 0 0 0 0 0 0 0 0 0 1
2 the cursor returns 0 0 0 0 0 0 0 0 1 *
3 reset input mode 0 0 0 0 0 0 0 1 I/D s
Display on/off control 4 0 0 0 0 0 0 1 d c b
5 character or cursor shifted 0 0 0 0 0 1 S/C R/L * *
6 reset the function f * 0 0 0 0 1 DL n *
Character memory address 0 0 0 1 7 reset character memory address
8 reset the data memory address 0 0 1 displays the data memory address
9 0 1 BF counter read busy flag or address address
Write count to 10 or DDRAM CGRAM) 1 0 to write the contents of the data
11 CGRAM or DDRAM reading 1 1 read out the contents of the data
1602 LCD module, reading and writing, screen and cursor operations are achieved through the directive programming. (Note: 1 high, 0 is low level)
Instructions 1: clear display, order code 01H, reset the cursor position to the address 00H.
Instruction 2: reset the cursor, the cursor returns to the address 00H.
Order 3: cursor, and display mode settings I/D: cursor moving direction, move high to the right, low level s to the left:
Move all text is left or right on the screen. High level represents effective, low level is not valid.
Instruction 4: display switch control. D: control of display on and off, high level open display, low power
Flat locked display c: controls the cursor on and off, high level indicates that a cursor, low level indicates no cursor b: control
Whether the cursor is flashing, flashing high level, low level does not Flash.
Directive 5: cursor or display SHIFT S/C: text to display high level moves, low level mobile cursor.
Instruction 6: feature command DL: high level is a 4-bit bus, low level as an 8-bit bus n: low
Usually consist of a single display, high voltage dual line display f: low level display dot matrix characters 5x7, high voltage display
5x10 dot matrix characters.
Directive 7: character generator RAM address settings.
Directive 8:DDRAM address settings.
Directive 9: reading of busy signals and the cursor address BF: for free sign-bit, line busy module can`t get
Receive commands or data, if low level is not busy.
Directive 10: write data.
Directive 11: reading the data.
HD44780 compatible chip timeline is as follows:
Read I RS=L,R/W=H,E=H o D0-D7= status word
Write commands RS=L,R/W=L,D0-D7= script, e = high output pulse is not
Reading data input RS=H,R/W=H,E=H output D0-D7= data
Write data entry RS=H,R/W=L,D0-D7= data E= high output pulse is not
1602LCD initialize (reset):
Delay 15mS
Writing instruction 38H (busy signal will not be detected)
Latency 5mS
Writing instruction 38H (busy signal will not be detected)
Latency 5mS
Writing instruction 38H (busy signal will not be detected)
Each subsequent write command, the read/write data operations are required to detect busy signal
Written instructions 38H: display mode settings
Written instructions 08H: display off
Written instructions 01H: displays a clear screen
Written instructions 06H: displays the cursor settings
Writing instruction 0CH: displaying open and cursor settings
//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 < adc_key_val[k])
{
return k;
}
}
if (k >= NUM_KEYS)
k = -1; // No valid key pressed
return k;
}
LCD4Bit_mod.h