Advertisement
Guest User

Untitled

a guest
Dec 26th, 2020
2,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. //LCD Functions Developed by electroSome
  2.  
  3.  
  4. void Lcd_Port(char a)
  5. {
  6. if(a & 1)
  7. D4 = 1;
  8. else
  9. D4 = 0;
  10.  
  11. if(a & 2)
  12. D5 = 1;
  13. else
  14. D5 = 0;
  15.  
  16. if(a & 4)
  17. D6 = 1;
  18. else
  19. D6 = 0;
  20.  
  21. if(a & 8)
  22. D7 = 1;
  23. else
  24. D7 = 0;
  25. }
  26. void Lcd_Cmd(char a)
  27. {
  28. RS = 0; // => RS = 0
  29. Lcd_Port(a);
  30. EN = 1; // => E = 1
  31. __delay_ms(4);
  32. EN = 0; // => E = 0
  33. }
  34.  
  35. Lcd_Clear()
  36. {
  37. Lcd_Cmd(0);
  38. Lcd_Cmd(1);
  39. }
  40.  
  41. void Lcd_Set_Cursor(char a, char b)
  42. {
  43. char temp,z,y;
  44. if(a == 1)
  45. {
  46. temp = 0x80 + b - 1;
  47. z = temp>>4;
  48. y = temp & 0x0F;
  49. Lcd_Cmd(z);
  50. Lcd_Cmd(y);
  51. }
  52. else if(a == 2)
  53. {
  54. temp = 0xC0 + b - 1;
  55. z = temp>>4;
  56. y = temp & 0x0F;
  57. Lcd_Cmd(z);
  58. Lcd_Cmd(y);
  59. }
  60. }
  61.  
  62. void Lcd_Init()
  63. {
  64. Lcd_Port(0x00);
  65. __delay_ms(20);
  66. Lcd_Cmd(0x03);
  67. __delay_ms(5);
  68. Lcd_Cmd(0x03);
  69. __delay_ms(11);
  70. Lcd_Cmd(0x03);
  71. /////////////////////////////////////////////////////
  72. Lcd_Cmd(0x02);
  73. Lcd_Cmd(0x02);
  74. Lcd_Cmd(0x08);
  75. Lcd_Cmd(0x00);
  76. Lcd_Cmd(0x0C);
  77. Lcd_Cmd(0x00);
  78. Lcd_Cmd(0x06);
  79. }
  80.  
  81. void Lcd_Write_Char(char a)
  82. {
  83. char temp,y;
  84. temp = a&0x0F;
  85. y = a&0xF0;
  86. RS = 1; // => RS = 1
  87. Lcd_Port(y>>4); //Data transfer
  88. EN = 1;
  89. __delay_us(40);
  90. EN = 0;
  91. Lcd_Port(temp);
  92. EN = 1;
  93. __delay_us(40);
  94. EN = 0;
  95. }
  96.  
  97. void Lcd_Write_String(char *a)
  98. {
  99. int i;
  100. for(i=0;a[i]!='\0';i++)
  101. Lcd_Write_Char(a[i]);
  102. }
  103.  
  104. void Lcd_Shift_Right()
  105. {
  106. Lcd_Cmd(0x01);
  107. Lcd_Cmd(0x0C);
  108. }
  109.  
  110. void Lcd_Shift_Left()
  111. {
  112. Lcd_Cmd(0x01);
  113. Lcd_Cmd(0x08);
  114. }
  115.  
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement