Advertisement
DrAungWinHtut

LCDcodesample.ino

Oct 27th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // C++ code
  2. //
  3. const int RS = 13;
  4. const int E = 12;
  5. const int DB4 = 11;
  6. const int DB5 = 10;
  7. const int DB6 = 9;
  8. const int DB7 = 8;
  9.  
  10. void setup()
  11. {
  12.   pinMode(RS,  OUTPUT);
  13.   pinMode(E,   OUTPUT);
  14.   pinMode(DB4, OUTPUT);
  15.   pinMode(DB5, OUTPUT);
  16.   pinMode(DB6, OUTPUT);
  17.   pinMode(DB7, OUTPUT);
  18.   //initialize
  19.   initlcd();
  20.   sent(1,0,0,1,0); sent(1,0,0,0,1); //H
  21.   sent(1,0,0,1,0); sent(1,1,0,0,1); //I
  22.   writeAlpha(' ');
  23.   writeAlpha('A');
  24.   writeAlpha('B');
  25.   writeAlpha('C');
  26. }
  27.  
  28. void loop()
  29. {
  30.  
  31. }
  32. void initlcd()
  33. {
  34.   sent(0,0,1,0,0);
  35.   sent(0,0,0,0,0); sent(0,1,0,0,0);
  36.   sent(0,0,0,0,0); sent(0,0,1,0,0);
  37.   sent(0,0,0,0,0); sent(0,0,0,1,1);
  38.  
  39. }
  40.  
  41. void writeAlpha(char ch)
  42. {
  43.   switch(ch){
  44.     //0010 0000
  45.     case ' ': sent(1,0,1,0,0); sent(1,0,0,0,0);  break;
  46.     //
  47.     case 'A': sent(1,0,0,1,0); sent(1,1,0,0,0);  break;
  48.     //0100 0010
  49.     case 'B': sent(1,0,0,1,0); sent(1,0,1,0,0);  break;
  50.     //0100 0011
  51.     case 'C': sent(1,0,0,1,0); sent(1,1,1,0,0);  break;
  52.   }
  53. }
  54.  
  55. void sent(int rs,int db4,int db5,int db6,int db7)
  56. {
  57.   digitalWrite(RS,rs);
  58.   delay(10);
  59.   digitalWrite(DB4,db4);
  60.   digitalWrite(DB5,db5);
  61.   digitalWrite(DB6,db6);
  62.   digitalWrite(DB7,db7);
  63.   delay(10);
  64.   digitalWrite(E,0);
  65.   delay(10);
  66.   digitalWrite(E,1);
  67.   delay(10);
  68.   digitalWrite(E,0);
  69.   delay(10);
  70. }
  71.  
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement