Advertisement
DrAungWinHtut

lcdOKskeleton.ino

May 29th, 2024
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int db4 = 13;
  2. const int db5 = 12;
  3. const int db6 = 11;
  4. const int db7 = 10;
  5. const int en = 9;
  6. const int rs = 8;
  7.  
  8. void setup() {
  9.   pinMode(db4, OUTPUT);
  10.   pinMode(db5, OUTPUT);
  11.   pinMode(db6, OUTPUT);
  12.   pinMode(db7, OUTPUT);
  13.   pinMode(rs, OUTPUT);
  14.   pinMode(en, OUTPUT);
  15.  
  16.   initlcd();
  17.     // Print 'G'
  18.     sendMachineCode(1, 0, 1, 0, 0, 0, 1, 1, 1);
  19.     // Print 'R'
  20.     sendMachineCode(1, 0, 1, 0, 1, 0, 0, 1, 0);
  21.   // Print 'E'
  22.     sendMachineCode(1, 0, 1, 0, 0, 0, 1, 0, 1);
  23.     // Print 'E'
  24.     sendMachineCode(1, 0, 1, 0, 0, 0, 1, 0, 1);
  25.   // Print 'N'
  26.     sendMachineCode(1, 0, 1, 0, 0, 1, 1, 1, 0);
  27.    
  28. }
  29.  
  30. void loop() {
  31.  
  32. }
  33.  
  34. void send4bits(int rrs, int b7, int b6, int b5, int b4) {
  35.   digitalWrite(rs, rrs);
  36.   digitalWrite(db4, b4);
  37.   digitalWrite(db5, b5);
  38.   digitalWrite(db6, b6);
  39.   digitalWrite(db7, b7);
  40.  
  41.   // Enable pulse
  42.   digitalWrite(en, HIGH);
  43.   delay(1);
  44.   digitalWrite(en, LOW);
  45.   delay(1);
  46.  
  47. }
  48.  
  49. void sendMachineCode(int rrs, int b7, int b6, int b5, int b4, int b3, int b2, int b1, int b0) {
  50.   // Send higher nibble
  51.   send4bits(rrs, b7, b6, b5, b4);
  52.   // Send lower nibble
  53.   send4bits(rrs, b3, b2, b1, b0);
  54.  
  55. }
  56.  
  57. void initlcd() {
  58.   // Function set: 4-bit mode
  59.   send4bits(0, 0, 0, 1, 0);
  60.   // Now the LCD is in 4-bit mode, we can send full commands
  61.   sendMachineCode(0, 0, 0, 0, 0, 0, 0, 0, 1); // Clear display
  62.   sendMachineCode(0, 0, 0, 0, 0, 0, 0, 1, 0); // Return home
  63.   sendMachineCode(0, 0, 0, 0, 0, 1, 1, 0, 0); // Display ON/OFF control: display on, cursor off, blink off
  64. }
  65.  
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement