Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define LCD pin connections
- const int rs = 8;
- const int en = 9;
- const int db4 = 13;
- const int db5 = 12;
- const int db6 = 11;
- const int db7 = 10;
- void pulseEnable() {
- digitalWrite(en, LOW);
- delayMicroseconds(1);
- digitalWrite(en, HIGH);
- delayMicroseconds(1); // Enable pulse must be >450ns
- digitalWrite(en, LOW);
- delayMicroseconds(100); // Commands need > 37us to settle
- }
- void sendNibble(int value) {
- digitalWrite(db4, (value >> 0) & 0x01);
- digitalWrite(db5, (value >> 1) & 0x01);
- digitalWrite(db6, (value >> 2) & 0x01);
- digitalWrite(db7, (value >> 3) & 0x01);
- pulseEnable();
- }
- void sendByte(int value, int mode) {
- digitalWrite(rs, mode);
- sendNibble(value >> 4);
- sendNibble(value & 0x0F);
- }
- void initLCD() {
- pinMode(rs, OUTPUT);
- pinMode(en, OUTPUT);
- pinMode(db4, OUTPUT);
- pinMode(db5, OUTPUT);
- pinMode(db6, OUTPUT);
- pinMode(db7, OUTPUT);
- delay(50);
- sendNibble(0x03);
- delay(5);
- sendNibble(0x03);
- delayMicroseconds(150);
- sendNibble(0x03);
- sendNibble(0x02); // Switch to 4-bit mode
- sendByte(0x28, 0); // 4-bit mode, 2 lines, 5x8 dots
- sendByte(0x0C, 0); // Display on, cursor off, blink off
- sendByte(0x01, 0); // Clear display
- delay(2); // Clear command requires a delay
- sendByte(0x06, 0); // Increment cursor
- }
- void setup() {
- initLCD();
- sendByte(0x80, 0); // Set cursor to the beginning of the first line
- sendByte('G', 1); // Send 'H'
- sendByte('R', 1);
- sendByte('E', 1);
- sendByte('E', 1);
- sendByte('N', 1);
- sendByte(' ', 1);
- sendByte('H', 1);
- sendByte('A', 1);
- sendByte('C', 1);
- sendByte('K', 1);
- sendByte('E', 1);
- sendByte('R', 1);
- sendByte('S', 1);
- }
- void loop() {
- // Nothing to do here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement