Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int db4 = 13;
- const int db5 = 12;
- const int db6 = 11;
- const int db7 = 10;
- const int en = 9;
- const int rs = 8;
- void setup() {
- pinMode(db4, OUTPUT);
- pinMode(db5, OUTPUT);
- pinMode(db6, OUTPUT);
- pinMode(db7, OUTPUT);
- pinMode(rs, OUTPUT);
- pinMode(en, OUTPUT);
- initlcd();
- // Print 'G'
- sendMachineCode(1, 0, 1, 0, 0, 0, 1, 1, 1);
- // Print 'R'
- sendMachineCode(1, 0, 1, 0, 1, 0, 0, 1, 0);
- // Print 'E'
- sendMachineCode(1, 0, 1, 0, 0, 0, 1, 0, 1);
- // Print 'E'
- sendMachineCode(1, 0, 1, 0, 0, 0, 1, 0, 1);
- // Print 'N'
- sendMachineCode(1, 0, 1, 0, 0, 1, 1, 1, 0);
- }
- void loop() {
- }
- void send4bits(int rrs, int b7, int b6, int b5, int b4) {
- digitalWrite(rs, rrs);
- digitalWrite(db4, b4);
- digitalWrite(db5, b5);
- digitalWrite(db6, b6);
- digitalWrite(db7, b7);
- // Enable pulse
- digitalWrite(en, HIGH);
- delay(1);
- digitalWrite(en, LOW);
- delay(1);
- }
- void sendMachineCode(int rrs, int b7, int b6, int b5, int b4, int b3, int b2, int b1, int b0) {
- // Send higher nibble
- send4bits(rrs, b7, b6, b5, b4);
- // Send lower nibble
- send4bits(rrs, b3, b2, b1, b0);
- }
- void initlcd() {
- // Function set: 4-bit mode
- send4bits(0, 0, 0, 1, 0);
- // Now the LCD is in 4-bit mode, we can send full commands
- sendMachineCode(0, 0, 0, 0, 0, 0, 0, 0, 1); // Clear display
- sendMachineCode(0, 0, 0, 0, 0, 0, 0, 1, 0); // Return home
- sendMachineCode(0, 0, 0, 0, 0, 1, 1, 0, 0); // Display ON/OFF control: display on, cursor off, blink off
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement