Advertisement
DrAungWinHtut

LCDcontrol

May 25th, 2023 (edited)
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // C++ code
  2. //
  3. void send_8bits_command(int RS1,int D01,int D11,int D21,int D31,int D41,int D51,int D61,int D71);
  4. void send_4bits_command(int RS1,int D01,int D11,int D21,int D31,int D41,int D51,int D61,int D71);
  5.  
  6. #define D0 9
  7. #define D1 8
  8. #define D2 7
  9. #define D3 6
  10. #define D4 5
  11. #define D5 4
  12. #define D6 3
  13. #define D7 2
  14. #define RS 13
  15. #define E  12
  16.  
  17. //#define 4bit_mode send_8bits_command(0,0,0,0,0,0,1,0,0)
  18. //#define clear_display send_4bits_command(0,0,0,0,0,0,0,0,1);
  19. //#define return_home send_4bits_command(0,0,0,0,0,0,0,1,0);
  20. //#define display_on send_4bits_command(0,0,0,1,0,1,0,0,0);
  21.  
  22. void setup()
  23. {
  24.   pinMode(D0 , OUTPUT);
  25.   pinMode(D1 , OUTPUT);
  26.   pinMode(D2 , OUTPUT);
  27.   pinMode(D3 , OUTPUT);
  28.   pinMode(D4 , OUTPUT);
  29.   pinMode(D5 , OUTPUT);
  30.   pinMode(D6 , OUTPUT);
  31.   pinMode(D7 , OUTPUT);
  32.   pinMode(RS , OUTPUT);
  33.   pinMode(E  , OUTPUT);
  34.  
  35.   send_8bits_command(0,0,0,0,0,0,1,0,0);
  36.   send_4bits_command(0,0,0,0,0,0,0,0,1);
  37.   send_4bits_command(0,0,0,0,0,0,0,1,0);
  38.   send_4bits_command(0,0,0,0,0,1,1,0,0);
  39.  
  40. }
  41.  
  42. void loop()
  43. {
  44.   send_4bits_command(1,0,1,0,0,0,0,0,1);
  45.   //send_4bits_command(0,1,0,0,0,1,1,0,0);
  46.   delay(1000);
  47.   send_4bits_command(1,0,1,0,0,0,0,1,0);
  48.   //send_4bits_command(0,1,0,0,0,1,1,0,0);
  49.   delay(1000);
  50.   send_4bits_command(1,0,1,0,0,0,0,1,1);
  51.   //send_4bits_command(0,1,0,0,0,1,1,0,0);
  52.   delay(1000);
  53.  
  54.   //send_4bits_command(0,0,0,0,0,0,0,0,1);
  55.   //send_4bits_command(0,0,0,0,0,0,0,1,0);
  56.  
  57.   send_4bits_command(0,1,0,0,0,0,0,0,0);
  58.  
  59. }
  60.  
  61. void send_8bits_command(int RS1,int D01,int D11,int D21,int D31,int D41,int D51,int D61,int D71)
  62. {
  63.   digitalWrite(RS,RS1);
  64.   digitalWrite(D0,D01);
  65.   digitalWrite(D1,D11);
  66.   digitalWrite(D2,D21);
  67.   digitalWrite(D3,D31);
  68.   digitalWrite(D4,D41);
  69.   digitalWrite(D5,D51);
  70.   digitalWrite(D6,D61);
  71.   digitalWrite(D7,D71);
  72.  
  73.   digitalWrite(E,LOW);
  74.   digitalWrite(E,HIGH);
  75.   digitalWrite(E,LOW);
  76.   delay(1);
  77. }
  78.  
  79. void send_4bits_command(int RS1,int D01,int D11,int D21,int D31,int D41,int D51,int D61,int D71){
  80.   digitalWrite(RS,RS1);
  81.  
  82.   digitalWrite(D7,D01);
  83.   digitalWrite(D6,D11);
  84.   digitalWrite(D5,D21);
  85.   digitalWrite(D4,D31);
  86.  
  87.   digitalWrite(E,LOW);
  88.   digitalWrite(E,HIGH);
  89.   digitalWrite(E,LOW);
  90.   delay(1);
  91.  
  92.   digitalWrite(RS,RS1);
  93.  
  94.   digitalWrite(D7,D41);
  95.   digitalWrite(D6,D51);
  96.   digitalWrite(D5,D61);
  97.   digitalWrite(D4,D71);
  98.  
  99.   digitalWrite(E,LOW);
  100.   digitalWrite(E,HIGH);
  101.   digitalWrite(E,LOW);
  102.   delay(1);
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement