hi,
i am new to embedded programming. after i flashed a serial program to make serial communication between two 8051 MCUs in both of my MCU, the parallel ports(P0,P1,P2,P3) are not working. even after flashing a new program no output in any port of both the MCUs.
the code i have used in sender 8051 is
given below :
#include<REG51.h>
unsigned char a;
int i;
void front()
{
unsigned char b=0x0a;
SBUF=b; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}
void back()
{
unsigned char b=0x05;
SBUF=b; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}
void left()
{
unsigned char b=0x02;
SBUF=b; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
for(i=0;i<=10;i++);
SBUF=0x00; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}
void right()
{
unsigned char b=0x08;
SBUF=b; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
for(i=0;i<=10;i++);
SBUF=0x00; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}
void stop()
{
unsigned char b=0x00;
SBUF=b; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}
void fire()
{
unsigned char b=0x00;
SBUF=b; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}
void off()
{
unsigned char b=0x00;
SBUF=b; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}
void main()
{
P0=0xff;
P2=0x00;
P1=0x00;
P0=0x00;
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1;
while(1)
{
a=P0;
if(a==0x01)
{
front();
}
else if(a==0x02)
{
back();
}
else if(a==0x03)
{
left();
}
else if(a==0x04)
{
right();
}
else if(a==0x05)
{
stop();
}
else if(a==0x06)
{
fire();
}
else if(a==0x07)
{
off();
}
else
stop();
}
}
The above program not worked for me.
the receiver side program is
given below:
#include <reg51.h>
void main()
{
unsigned char mybyte;
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1; //start timer
while(1)
{ //repeat forever
while (RI==0); //wait to receive
mybyte=SBUF; //save value
P0=mybyte; //write value to port
RI=0;
}
}
the receiver side program also not working.
i cant find any problem.
even after erasing all flash in two 8051s,the new program that flashed for checking port also not working.
the new program that i used is given below.
#include<reg51.h>
void main(void)
{
while(1)
{
P0=0xFF;
}
}
the above program doesn't give any output on port0 pins.
the two mcus are not responding to even very simple program like above.
any software reset should be done.
I also attached the project source files in this thread. link to the source file:
View attachment keil.rar
i really need help to resolve this issue.