UART-Keypad-lcd interfacing with 8051

Discussion in 'Embedded Systems and Microcontrollers' started by bobparihar, Feb 27, 2015.

  1. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    i am doing a project in which there is a serial communication between two 8051 microcontroller.
    at transmitting side there is a 4x4 keypad attached at one of the port of 8051
    at receiving side there is a 16x2 LCD attached
    i am simulating it on Proteus first... but there is an error as soon as i start the simulation of the program..
    i am unable to understand this error.. ( see the attached screenshot of protues)

    help me to get rid of this error

    [​IMG]

    this is code of transmitting side.............................


    Code (Text):
    1.  
    2. #include<reg51.h>
    3.  
    4. void serial(void);
    5. void serial(void)
    6. {
    7. TMOD=0x20; //timer 1, mode 2(8-bit autoreload) to set baud rate
    8. TH1=0xFD; //-3 to TH1 for 9600 baud rate
    9. SCON=0x50; // 8 bit txion, 1 start 1 stop bit, REN enable for both txfr and rxve
    10. TR1=1; // start timer
    11. }
    12. void trans(unsigned char);
    13. void trans(unsigned char a)
    14. {
    15. SBUF=a;
    16. while(TI==0);
    17. TI=0;
    18.  
    19. }
    20.  
    21. void main()
    22. {
    23.  
    24. unsigned int ar[]={0xE7,0xD7,0xB7,0x77,0xEB,0xDB,0xBB,0x7B,0xED,0xDD,0xBD,0x7D,0xEE,0xDE,0xBE,0x7E};
    25.  
    26. unsigned int a,b,c,i;
    27.  
    28. serial();
    29. while(1)
    30. {
    31. P1=0x0F;
    32. while(P1==0x0F);
    33. a=P1;
    34. P1=0xF0;
    35. b=P1;
    36. c=a|b;
    37. for(i=0;i<16;i++)
    38. {
    39. if (ar==c)
    40. trans(i);
    41. }
    42. }
    43. }
    44.  


    now this is code of receiving side.................................................

    Code (Text):
    1.  
    2. #include"lcd1.h"
    3. void main()
    4. {
    5. int a;
    6. init();
    7. TMOD=0x20; //timer 1, mode 2(8-bit autoreload) to set baud rate
    8. TH1=0xFD; //-3 to TH1 for 9600 baud rate
    9. SCON=0x50; // 8 bit txion, 1 start 1 stop bit, REN enable for both txfr and rxve
    10. TR1=1; // start timer
    11. while(1)
    12. {
    13. while(RI==0); // check if all the bytes get received
    14. a=SBUF; // place sbuf in a
    15. num(a);
    16. RI=0; // clear RI so that another byte will recive
    17. }
    18. }
    19.  
    20.  
    21.  
    22. header file code for lcd..
    23. #include<reg52.h>
    24. sbit rs=P3^2;
    25. sbit rw=P3^3;
    26. sbit en=P3^4;
    27. void dat(unsigned char);
    28. void cmd(unsigned char);
    29. void delay(unsigned int);
    30. void print(unsigned char *);
    31. void init();
    32. void num(unsigned int);
    33.  
    34.  
    35. void init()
    36. {
    37.  
    38. cmd(0x38);
    39. delay(100);
    40. cmd(0x0E);
    41. delay(100);
    42. cmd(0x06);
    43. delay(100);
    44. cmd(0x01);
    45. delay(100);
    46. cmd(0x80);
    47. delay(100);
    48.  
    49.  
    50.  
    51. }
    52.  
    53. void cmd(unsigned char x)
    54. {
    55. P2=x;
    56. rs=0;
    57. rw=0;
    58. en=1;
    59. delay(1);
    60. en=0;
    61. }
    62. void dat(unsigned char y)
    63. {
    64. P2=y;
    65. rs=1;
    66. rw=0;
    67. en=1;
    68. delay(1);
    69. en=0;
    70. }
    71. void delay(unsigned int z)
    72. {
    73. int j,i;
    74. for(i=0;i<z;i++)
    75. {
    76. for(j=0;j<1275;j++);
    77.  
    78. }
    79. }
    80. void print(unsigned char *p)
    81. {
    82.  
    83. while(*p!='\0')
    84. {
    85. dat(*p);
    86. p++;
    87. }
    88.  
    89. }
    90. void num(unsigned int a)
    91. {
    92. int b,c=1;
    93. b=a;
    94. while(b>9)
    95. {
    96. b=b/10;
    97.  
    98. c=c*10;
    99. }
    100.  
    101.  
    102. while(c!=0)
    103. { delay(50);
    104. dat((a/c)+48);
    105. a=a%c;
    106. c=c/10;
    107.  
    108. }
    109. }
    110.  
    Moderators note: Please use code tags for pieces of code
     
    Last edited by a moderator: Feb 27, 2015
  2. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    Just rename the second 8051 as U2.

    Then load your programs to both U1 and U2 and then it should work.

    Allen
     
    Last edited: Feb 27, 2015
    bobparihar likes this.
  3. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    that helped... thanku
     
Loading...