UART-Keypad-lcd interfacing with 8051

Thread Starter

bobparihar

Joined Jul 31, 2014
93
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



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


Code:
#include<reg51.h>

void serial(void);
void serial(void)
{
TMOD=0x20; //timer 1, mode 2(8-bit autoreload) to set baud rate
TH1=0xFD; //-3 to TH1 for 9600 baud rate
SCON=0x50; // 8 bit txion, 1 start 1 stop bit, REN enable for both txfr and rxve
TR1=1; // start timer
}
void trans(unsigned char);
void trans(unsigned char a)
{
SBUF=a;
while(TI==0);
TI=0;

}

void main()
{

unsigned int ar[]={0xE7,0xD7,0xB7,0x77,0xEB,0xDB,0xBB,0x7B,0xED,0xDD,0xBD,0x7D,0xEE,0xDE,0xBE,0x7E};

unsigned int a,b,c,i;

serial();
while(1)
{
P1=0x0F;
while(P1==0x0F);
a=P1;
P1=0xF0;
b=P1;
c=a|b;
for(i=0;i<16;i++)
{
if (ar==c)
trans(i);
}
}
}


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

Code:
#include"lcd1.h"
void main()
{
int a;
init();
TMOD=0x20; //timer 1, mode 2(8-bit autoreload) to set baud rate
TH1=0xFD; //-3 to TH1 for 9600 baud rate
SCON=0x50; // 8 bit txion, 1 start 1 stop bit, REN enable for both txfr and rxve
TR1=1; // start timer
while(1)
{
while(RI==0); // check if all the bytes get received
a=SBUF; // place sbuf in a
num(a);
RI=0; // clear RI so that another byte will recive
}
}



header file code for lcd..
#include<reg52.h>
sbit rs=P3^2;
sbit rw=P3^3;
sbit en=P3^4;
void dat(unsigned char);
void cmd(unsigned char);
void delay(unsigned int);
void print(unsigned char *);
void init();
void num(unsigned int);


void init()
{

cmd(0x38);
delay(100);
cmd(0x0E);
delay(100);
cmd(0x06);
delay(100);
cmd(0x01);
delay(100);
cmd(0x80);
delay(100);



}

void cmd(unsigned char x)
{
P2=x;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
}
void dat(unsigned char y)
{
P2=y;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
void delay(unsigned int z)
{
int j,i;
for(i=0;i<z;i++)
{
for(j=0;j<1275;j++);

}
}
void print(unsigned char *p)
{

while(*p!='\0')
{
dat(*p);
p++;
}

}
void num(unsigned int a)
{
int b,c=1;
b=a;
while(b>9)
{
b=b/10;

c=c*10;
}


while(c!=0)
{ delay(50);
dat((a/c)+48);
a=a%c;
c=c/10;

}
}
Moderators note: Please use code tags for pieces of code
 
Last edited by a moderator:

absf

Joined Dec 29, 2010
1,968
Just rename the second 8051 as U2.

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

Allen
 
Last edited:
Top