Advertisement
Fshibu321

Untitled

Mar 17th, 2025
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include<reg51.h>
  2.  
  3. #define display_port P2  // Data pins connected to port 2 on microcontroller
  4.  
  5. sbit rs = P3^2;  // RS pin connected to pin 2 of port 3
  6. sbit rw = P3^3;  // RW pin connected to pin 3 of port 3
  7. sbit e =  P3^4;  // E pin connected to pin 4 of port 3
  8.  
  9. void msdelay(unsigned int time)  // Function for creating delay in milliseconds
  10. {
  11.     unsigned i, j;
  12.     for(i = 0; i < time; i++)    
  13.         for(j = 0; j < 1275; j++);
  14. }
  15.  
  16. void lcd_cmd(unsigned char command)  // Function to send command instruction to LCD
  17. {
  18.     display_port = command;
  19.     rs = 0;
  20.     rw = 0;
  21.     e = 1;
  22.     msdelay(1);
  23.     e = 0;
  24. }
  25.  
  26. void lcd_data(unsigned char disp_data)  // Function to send display data to LCD
  27. {
  28.     display_port = disp_data;
  29.     rs = 1;
  30.     rw = 0;
  31.     e = 1;
  32.     msdelay(1);
  33.     e = 0;
  34. }
  35.  
  36. void lcd_init()  // Function to prepare the LCD and get it ready
  37. {
  38.     lcd_cmd(0x38);  // Using 2 lines and 5x7 matrix of LCD
  39.     msdelay(10);
  40.     lcd_cmd(0x0F);  // Turn display ON, cursor blinking
  41.     msdelay(10);
  42.     lcd_cmd(0x01);  // Clear screen
  43.     msdelay(10);
  44.     lcd_cmd(0x81);  // Bring cursor to position 1 of line 1
  45.     msdelay(10);
  46. }
  47.  
  48. void main()
  49. {
  50.     unsigned char a[] = "EKNM GPTC TKPR";    
  51.     unsigned char b[] = "Electronics Dept";    
  52.  
  53.     int l = 0;
  54.     lcd_init();
  55.  
  56.     while(a[l] != '\0') // Display first line
  57.     {
  58.         lcd_data(a[l]);
  59.         l++;
  60.         msdelay(30);
  61.     }
  62.  
  63.     lcd_cmd(0xC0); // Move cursor to second line
  64.     l = 0;
  65.     while(b[l] != '\0') // Display second line
  66.     {
  67.         lcd_data(b[l]);
  68.         l++;
  69.         msdelay(30);
  70.     }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement