• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What's the problem of the lcd by using 8051?

Thread starter #1
Hi everyone,

I am interfacing lcd (JHD 162A) using 8051(89c51). The lcd's lamp only lit up otherwise nothing is displaying on the lcd.


i have checked all the connections to the lcd and they are good.

I wrote the code on keil uvision4

please tell me the problem!

your help is greatly appriciated

here is my code:


  1. #include<regx51.h>
  2. void lcdmd(unsigned char value);
  3. void lcddata(unsigned char value);
  4. void busyflag();
  5. void delay(unsigned char value);
  6. sbit rs=P2^0;
  7. sbit rw=P2^1;
  8. sbit e=P2^2;
  9. sbit busy=P1^7;
  10. sfr ldata=0x90;

  11. int main(){



  12. P0_2=0; //just for checking

  13. //initilization
  14. //step 1
  15. delay(20);
  16. rs=0;
  17. rw=0;
  18. P1_7=0;
  19. P1_6=0;
  20. P1_5=1;
  21. P1_4=1;

  22. e=1;
  23. delay(200);
  24. e=0;

  25. //step 2
  26. delay(10);
  27. rs=0;
  28. rw=0;
  29. P1_7=0;
  30. P1_6=0;
  31. P1_5=1;
  32. P1_4=1;

  33. e=1;
  34. delay(200);
  35. e=0;

  36. //step 3
  37. delay(200);
  38. rs=0;
  39. rw=0;
  40. P1_7=0;
  41. P1_6=0;
  42. P1_5=1;
  43. P1_4=1;

  44. e=1;
  45. delay(200);
  46. e=0;

  47. //step 4
  48. delay(100);
  49. busyflag();
  50. rs=0;
  51. rw=0;
  52. P1_7=0;
  53. P1_6=0;
  54. P1_5=1;
  55. P1_4=0;

  56. e=1;
  57. delay(200);
  58. e=0;

  59. delay(100);
  60. rs=0;
  61. rw=0;
  62. P1_7=0;
  63. P1_6=0;
  64. P1_5=1;
  65. P1_4=0;

  66. e=1;
  67. delay(200);
  68. e=0;

  69. // lines and font
  70. delay(100);
  71. rs=0;
  72. rw=0;
  73. P1_7=1;
  74. P1_6=0;
  75. P1_5=0;
  76. P1_4=0;

  77. e=1;
  78. delay(200);
  79. e=0;

  80. delay(100);
  81. rs=0;
  82. rw=0;
  83. P1_7=0;
  84. P1_6=0;
  85. P1_5=0;
  86. P1_4=0;

  87. e=1;
  88. delay(200);
  89. e=0;

  90. delay(100);
  91. rs=0;
  92. rw=0;
  93. P1_7=1;
  94. P1_6=0;
  95. P1_5=0;
  96. P1_4=0;

  97. e=1;
  98. delay(200);
  99. e=0;

  100. delay(100);
  101. rs=0;
  102. rw=0;
  103. P1_7=0;
  104. P1_6=0;
  105. P1_5=0;
  106. P1_4=0;

  107. e=1;
  108. delay(200);
  109. e=0;

  110. delay(100);
  111. rs=0;
  112. rw=0;
  113. P1_7=0;
  114. P1_6=0;
  115. P1_5=0;
  116. P1_4=1;

  117. e=1;
  118. delay(200);
  119. e=0;

  120. delay(100);
  121. rs=0;
  122. rw=0;
  123. P1_7=0;
  124. P1_6=0;
  125. P1_5=0;
  126. P1_4=0;

  127. e=1;
  128. delay(200);
  129. e=0;

  130. // I/D S
  131. delay(100);
  132. rs=0;
  133. rw=0;
  134. P1_7=0;
  135. P1_6=1;
  136. P1_5=1;
  137. P1_4=1;

  138. e=1;
  139. delay(200);
  140. e=0;


  141. P0_3=0; //just for checking

  142. //initilization ends
  143. lcdmd(0x0E);
  144. lcdmd(0x06);
  145. lcddata('P');
  146. lcddata('h');
  147. lcddata('a');
  148. lcddata('s');
  149. lcddata('e');
  150. lcddata('1');
  151. lcdmd(0xC0);
  152. lcddata('P');
  153. lcddata('h');
  154. lcddata('a');
  155. lcddata('s');
  156. lcddata('e');
  157. lcddata('2');
  158. while(1){
  159. if(P3_1==0){
  160. lcddata(' ');
  161. lcddata('o');
  162. lcddata('n');
  163. }
  164. else{
  165. lcddata(' ');
  166. lcddata('o');
  167. lcddata('f');
  168. lcddata('f');
  169. }

  170. if(P3_0==0){
  171. lcdmd(0x86);
  172. lcddata(' ');
  173. lcddata('o');
  174. lcddata('n');
  175. }
  176. else{
  177. lcdmd(0x86);
  178. lcddata(' ');
  179. lcddata('o');
  180. lcddata('f');
  181. lcddata('f');
  182. }
  183. }










  184. return 0;
  185. }


  186. void lcdmd(unsigned char value){
  187. busyflag();
  188. ldata=value;
  189. rs=0;
  190. rw=0;
  191. e=1;
  192. delay(200);
  193. e=0;

  194. return;

  195. }


  196. void lcddata(unsigned char value){
  197. busyflag();
  198. ldata=value;
  199. rs=1; //data register
  200. rw=0; //write

  201. e=1;
  202. delay(200);
  203. e=0;

  204. return;
  205. }



  206. void busyflag(){

  207. rs=0;
  208. rw=1;
  209. busy=1; //input

  210. while(busy==1){
  211. e=0;
  212. delay(200);
  213. e=1;
  214. }

  215. return;
  216. }


  217. void delay(unsigned char value){
  218. unsigned int i,j;
  219. for(i=0;i<value;++i)
  220. for(j=0;j<1275;++j);

  221. }
 

Cicero

Active Member
#2
I'm not diving into your code just yet.

First things first, have you got the contrast set up right?

Secondly, post us a pic/diagram of your wiring.

Thirdly, don't try to do "on" and "off" displays or anything dynamically to start with. Wait until you have good code with a readable display first, so just try to display something like "Hello World" on the first line and then sit in a while loop.
 

Cicero

Active Member
#3
I see problems in your code from a quick glance over it.
It looks like you're using 4bit mode but you aren't shifting your data in lcddata() and lcdmd().
Also you're trying to do the initialisation routine by bitbanging, but why not just use the lcdmd() functions?

Here are some extracts from an HD44780 library I've used to help you get further, I've tried to use your code function names/style where applicable as well to help you understand:
Code:
void lcden(void) {
 e = 1;
 delay(1);
 e = 0;
}

void lcddata(unsigned char value) {
 rs=1;  //data register

 ldata=((value>> 4) & 0x0F);
 lcden();
 ldata=(value& 0x0F);
 lcden();
}

void lcdmd(unsigned char value) {
 rs=0;
 ldata=((value>> 4) & 0x0F);
 lcden();
 ldata=(value& 0x0F);
 lcden();
}

void lcd_clearDisplay (void) {
  lcdmd(0x01);
}

void lcd_init (void) {
  e = 1;
  rs = 0;
 rw = 0;
 //Initialization of HD44780-based LCD (4-bit HW)
 lcdmd(0x33);
 delay(4);
 lcdmd(0x32);
 delay(4);
 //Function Set 4-bit mode
 lcdmd(0x28);
  //Display On/Off Control
  lcdmd(0x0C);
  //Entry mode set
  lcdmd(0x06);
  lcd_clearDisplay();
  //Minimum delay to wait before driving LCD module
  delay(200);
}


void lcd_home (void) {
  lcdmd(0x02);
}

void lcd_2ndrow(void) {
  lcdmd(0xC0);
}


void lcd_printstring(char *text) {
  do
  {
    lcddata(*text++);
  }
  while (*text != '\n');
}

void lcd_printHelloWorld (void) {
  lcd_home();
  lcd_printstring("Hello World\n");
  lcd_2ndrow();
  lcd_printstring("Hello World\n"); 
  while(1);
}
Use lcd_init() to do the initialisations, then simply call lcd_printHelloWorld();
 

Latest threads

EE World Online Articles

Loading

 
Top