Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.61 KB | None | 0 0
  1. #include<reg51.h>
  2.  
  3. /********************************************* LCD control signals declaration
  4. ***************************************************/
  5.  
  6. sbit RS = P0^0; // <span id="IL_AD1" class="IL_AD">Register</span> Select line
  7. //sbit RW = P0^1; // Read/write line
  8. sbit Enable = P0^1; // Enable line
  9. #define LCD_PORT P2 // define port
  10.  
  11. /********************************************* LCD function prototypes
  12. ************************************************/
  13. void send_cmd(unsigned char);
  14. void send_data(unsigned char*);
  15. void send_char(unsigned char);
  16. void LCD_init(void);
  17. void delayms(unsigned int);
  18. /********************************************* Main Funciton declaration
  19. ***********************************************/
  20. void main()
  21. {
  22.  
  23. LCD_PORT = 0x00; // Make the port as output port
  24.  
  25. LCD_init(); // LCD initialization
  26.  
  27. // while(1)
  28. //{
  29. send_cmd(0x80); // Force cursor to beginning of 1st line, if the number is 0x83 then force the cursor
  30. to 53rd position
  31. delayms(100); // Delay of 100millisec
  32. send_char('S'); // Send data
  33. send_char('J'); // Send data
  34. send_char('E'); // Send data
  35. send_char('C'); // Send data
  36. send_cmd(0xC0); // Force cursor to beginning of 2nd line
  37.  
  38. delayms(100); // Delay of 100millisec
  39. send_char('I'); // Send data
  40. send_char('O'); // Send data
  41. send_char('A'); // Send data
  42.  
  43. //}
  44.  
  45. }
  46.  
  47. /********************************************* LCD Initialization Function declaration
  48. ********************************/
  49.  
  50. void LCD_init()
  51. {
  52. send_cmd(0x38); // configuring LCD as 2 line 5x7 matrix
  53. send_cmd(0x0E); // Display on, Cursor blinking
  54. send_cmd(0x01); // Clear Display Screen
  55. send_cmd(0x06); // Increment Cursor (Right side)
  56. }
  57.  
  58. void send_char(unsigned char character)
  59. {
  60. LCD_PORT = character;
  61. RS = 1; // Select Data Register
  62. // RW = 0; // write operation
  63. Enable = 1; // High to Low pulse provided on the enable pin with nearly 1ms(>450ns)
  64. delayms(1); // 1 millisec delay
  65. Enable = 0;
  66. delayms(100); // 100 millisec delay
  67.  
  68. }
  69.  
  70. /*********************************************LCD Command Sending Function
  71. declaration********************************/
  72.  
  73. void send_cmd(unsigned char Command)
  74. {
  75. LCD_PORT = Command;
  76. RS = 0; // Select Command Register
  77. // RW = 0; // write operation
  78. Enable = 1; // High to Low pulse provided on the enable pin with nearly 1ms(>450ns)
  79. delayms(1); // 1 millisec delay
  80. Enable = 0;
  81.  
  82. }
  83.  
  84. /******************************************* delayms Function
  85. declaration***********************************************/
  86. void delayms(unsigned int val)
  87. {
  88. unsigned int i,j;
  89.  
  90. for(i=0;i<=val;i++)
  91. {
  92. for(j=0;j<=2;j++) ;
  93. //_nop_(); // no operation produce 1us time delay
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement