Arduino Full Stack
  • Preface
  • Part 1 - Introduction
  • Chapter 1. Getting Started with Arduino
    • 1.1 Arduino UNO R3
    • 1.2 LVR Arduino Exntesion Board
    • 1.3 Sensor Kits for Arduino
    • 1.4 Race Car Chassis Model
    • 1.5 Arduino Online Resource
    • 1.6 Arduino IDE for Prototyping
    • 1.7 FIRST Arduino Project - Hello World
  • Chapter 2. Programming Grammar
    • 2.1 AVR C
    • 2.2 Digital IO
    • 2.3 Analog IO
    • 2.4 More About IO
    • 2.5 Time Functions
    • 2.6 Interrupt Functions
    • 2.7 Communication Classes
    • 2.8 Arduino Libraries
  • Part 2 - Sensors
  • Chapter 3. LED Sensors
    • 3.1 LED Blinking
    • 3.2 LED SMD RGB
    • 3.3 Mini LED Red Green GND-Shared
    • 3.4 LED RGB GND-Shared
    • 3.5 Photoresistor
    • 3.6 LED Light Cup
    • 3.7 LED Red Green GND-Shared
    • 3.8 LED 7 Colors
  • Chapter 4. Infrared Sensors
    • 4.1 Infrared Emitter and Receiver
    • 4.2 Laser Emitter
    • 4.3 Infrared Remote Control
    • 4.4 IR Obstacle Avoidance
    • 4.5 IR Line Tracking
  • Chapter 5. Audio Sensors
    • 5.1 Passive Buzzer
    • 5.2 Active Buzzer
    • 5.3 Microphone Big Sound
    • 5.4 Microphone
  • Chapter 6. Magnetic Sensors
    • 6.1 Hall Magnetic Sensor
    • 6.2 Mini Reed
    • 6.3 Linear Hall Magnetic Sensor
    • 6.4 Reed
    • 6.5 Analog Hall
  • Chapter 7. Touch Sensors
    • 7.1 Tap Sensor
    • 7.2 Shock Sensor
    • 7.3 Touch Sensor
  • Chapter 8. Thermist Sensors
    • 8.1 Temperature Sensor - DS18B20
    • 8.2 Analog Thermister
    • 8.3 Digital Temperature
    • 8.4 Temperature and Humidity Sensor
  • Chapter 9. Switches
    • 9.1 Button
    • 9.2 Switch -Mercury Tilt
    • 9.3 Switch - Ball
    • 9.4 Relay
  • Chapter 10. Other Sensors
    • 10.1 Joystick
    • 10.2 Flame
    • 10.3 Pulse Monitor
    • 10.4 Rotary Encoders
  • Chapter 11. More Discussions on Sensors
    • 11.1 Arducam
    • 11.2 IMU - BNO055
  • Part 3 - Motors
  • Chapter 12. Motors
    • 12.1 DC Motor
    • 12.2 AC Motor
    • 12.3 Stepper Motor
    • 12.4 Servo Motor
  • Part 4 - Display
  • Chapter 13. Display
    • 13.1 Nixie Light LG5011B
    • 13.2 Crystal Display 1602A
    • 13.3 Crystal Display 12864
  • Part 5 - Communication
  • Chapter 14. Communication
    • 14.1 Serial
    • 14.2 Wifi - ESP8266
    • 14.3 Bluetooth
    • 14.4 Integrate Wifi & Bluetooth - ESP32
  • Part 6 - Arduino Based Mini Automated Vehicle
  • Chapter 15. Assemble a Mini Automated Vehicle
    • 15.1 4-Wheel DC-Motor Driven
    • 15.2 Arduino UNO and LVR Arduino Extension Board
    • 15.3 Speed Sensors
    • 15.4 Servo Motor for Pan Tilt Control
    • 15.5 Tracking Sensor
  • Chapter 16. Remote Control
    • 16.1 IR Remote Control
    • 16.2 Bluetooth Remote Control
    • 16.3 Wifi Remote Control
    • 16.4 Automatic Control
Powered by GitBook
On this page
  • Hardware Wiring
  • Sketch
  1. Chapter 13. Display

13.2 Crystal Display 1602A

Previous13.1 Nixie Light LG5011BNext13.3 Crystal Display 12864

Last updated 7 years ago

Hardware Wiring

Sketch

int DI = 12;
int RW = 11;
int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};//Use an array to define all needed pins
int Enable = 2;

void LcdCommandWrite(int value) {
// define for all pins
int i = 0;
for (i=DB[0]; i <= DI; i++)   //assign all data bus
{
   digitalWrite(i,value & 01);  // 1602 Crystal Display sequence: D7->D0, instead of D0->D7, this is used to revert the signal sequence.
   value >>= 1;
}
digitalWrite(Enable,LOW);
delayMicroseconds(1);
digitalWrite(Enable,HIGH);
delayMicroseconds(1);  // delay 1ms
digitalWrite(Enable,LOW);
delayMicroseconds(1);  // delay 1ms
}

void LcdDataWrite(int value) {
// define for all pins
int i = 0;
digitalWrite(DI, HIGH);
digitalWrite(RW, LOW);
for (i=DB[0]; i <= DB[7]; i++) {
   digitalWrite(i,value & 01);
   value >>= 1;
}
digitalWrite(Enable,LOW);
delayMicroseconds(1);
digitalWrite(Enable,HIGH);
delayMicroseconds(1);
digitalWrite(Enable,LOW);
delayMicroseconds(1);   // Deplay 1ms
}

void setup (void) {
int i = 0;
for (i=Enable; i <= DI; i++) {
   pinMode(i,OUTPUT);
}
delay(100);
// Intialize LCD after a short-term detaly
// particularly for LCD control
LcdCommandWrite(0x38);  // Setup 8-bit interface, 2-line display, 5x7 character size
delay(64);                      
LcdCommandWrite(0x38);  // Setup 8-bit interface, 2-line display, 5x7 character size
delay(50);                      
LcdCommandWrite(0x38);  // Setup 8-bit interface, 2-line display, 5x7 character size
delay(20);                      
LcdCommandWrite(0x06);  // Setup input
                        // Automatic Increasement, no shift
delay(20);                      
LcdCommandWrite(0x0E);  // Setup display
                        // Turn on screen, display cursor, no flashing
delay(20);                      
LcdCommandWrite(0x01);  // Clear up screen, cursor's position -> 0
delay(100);                      
LcdCommandWrite(0x80);  // Setup display
                        // Turn on screen, display cursor, no flashing
delay(20);                      
}

void loop (void) {
  LcdCommandWrite(0x01);  // Clear up screen, cursor's position -> 0
  delay(10); 
  LcdCommandWrite(0x80+3); 
  delay(10);                     
  // Write in the Welcome info
  LcdDataWrite('W');
  LcdDataWrite('e');
  LcdDataWrite('l');
  LcdDataWrite('c');
  LcdDataWrite('o');
  LcdDataWrite('m');
  LcdDataWrite('e');
  LcdDataWrite(' ');
  LcdDataWrite('t');
  LcdDataWrite('o');
  delay(10);
  LcdCommandWrite(0xc0+1);  // Set the cursor's location: 2nd line, 2nd position
  delay(10); 
  LcdDataWrite('l');
  LcdDataWrite('o');
  LcdDataWrite('n');
  LcdDataWrite('g');
  LcdDataWrite('e');
  LcdDataWrite('r');
  LcdDataWrite('-');
  LcdDataWrite('v');
  LcdDataWrite('i');
  LcdDataWrite('s');
  LcdDataWrite('i');
  LcdDataWrite('o');
  LcdDataWrite('n');
  delay(5000);
  LcdCommandWrite(0x01);  // Clear up screen, cursor's position -> 0
  delay(10);
  LcdDataWrite('I');
  LcdDataWrite(' ');
  LcdDataWrite('a');
  LcdDataWrite('m');
  LcdDataWrite(' ');
  LcdDataWrite('d');
  LcdDataWrite('r');
  LcdDataWrite('.');
  LcdDataWrite('p');
  LcdDataWrite('e');
  LcdDataWrite('i');
  delay(3000);
  LcdCommandWrite(0x02);  // Set the mode to: "New characters are used to replace old characters; No change where there is NO characters." 
  delay(10);
  LcdCommandWrite(0x80+5);  // Set the cursor's location: 1st line, 6th position
  delay(10);  
  LcdDataWrite('t');
  LcdDataWrite('h');
  LcdDataWrite('e');
  LcdDataWrite(' ');
  LcdDataWrite('a');
  LcdDataWrite('d');
  LcdDataWrite('m');
  LcdDataWrite('i');
  LcdDataWrite('n');
  delay(5000);
}
Crystal Display 1602A