Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(6, 8, 9, 10, 11, 12); //Ordem dos pinos RS EN D4 D5 D6 D7
- #define RS 6
- #define RW 7
- #define ENA 8
- #define DB7 9
- #define DB6 10
- #define DB5 11
- #define DB4 12
- //------------------------------
- void setup()
- {
- Serial.begin(9600);
- pinMode( RS , OUTPUT);
- pinMode( RW , OUTPUT);
- pinMode(ENA, OUTPUT);
- pinMode( DB7 , OUTPUT);
- pinMode( DB6 , OUTPUT);
- pinMode( DB5 , OUTPUT);
- pinMode( DB4 , OUTPUT);
- // lcd.begin(16, 2);
- initLCD();
- }
- //----------------------------
- void initLCD()
- {
- delay(15);
- digitalWrite( ENA, LOW);
- digitalWrite( RS , LOW);
- digitalWrite( RW , LOW);
- write4bits(3);
- delayMicroseconds(4500); // wait min 4.1ms
- write4bits(3);
- delayMicroseconds(40); // wait min 4.1ms
- write4bits(3);
- delayMicroseconds(40);
- write4bits(2);
- delayMicroseconds(40);
- // 28
- write4bits(2);
- write4bits(8);
- delayMicroseconds(60); // wait min 4.1ms
- // 2E
- write4bits(0);
- write4bits(8);
- delayMicroseconds(60); // wait min 4.1ms
- // 2E
- write4bits(0);
- write4bits(1);
- delayMicroseconds(3000); // wait min 4.1ms
- // 2E
- write4bits(0);
- write4bits(6);
- // clear 0C
- write4bits(0);
- write4bits(0x0C);
- delay(500);
- }
- //------------------------
- void loop()
- {
- // lcd.begin(16, 2);
- // lcd.print("hello, world!");
- write4bits(3);
- write4bits(1);
- delay(500);
- write4bits(3);
- write4bits(2);
- delay(500);
- // initLCD();
- }
- //-----------------------------------
- void write4bits(byte value)
- {
- digitalWrite( DB7 , (value ) & 0x01);
- digitalWrite( DB6 , (value >> 1) & 0x01);
- digitalWrite( DB5 , (value >> 2) & 0x01);
- digitalWrite( DB4 , (value >> 3) & 0x01);
- pulseEnable();
- }
- //-----------------------------------
- void pulseEnable()
- {
- digitalWrite(ENA, LOW);
- delayMicroseconds(1);
- digitalWrite(ENA, HIGH);
- delayMicroseconds(1); // enable pulse must be >450ns
- digitalWrite(ENA, LOW);
- delayMicroseconds(100); // commands need > 37us to settle
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement