Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 8051 Serial Communication - Data is sent once but received repeatedly

Status
Not open for further replies.

praveenrpk92

Newbie level 6
Joined
Dec 28, 2015
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
98
I am trying to interface my PC with 8051 using a CP2102 USB to UART bridge. I tried sending the characters 'M' & 'C' and view them using hyper terminal. I am able to receive the characters but instead of receiving them once, the data is received repeatedly in a loop fashion. I simulated this in Proteus and it works as expected i.e. I'm getting characters MC and them the program halts in while loop. Same results as proteus in Keil Debug as well. Please help me fix this issue.


Code:
#include <REGX52.h>
void delay_us(unsigned int d);
void send(unsigned char x);
void main(void)
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
	TR1=1;
	RI=0;
	TI=0;
	 send('M');
	delay_us(1000);
	send('C');
while(1){


	
  }
}


void delay_us(unsigned int d)
{
   unsigned int i, limit;
   limit = d/15;

   for(i=0;i<limit;i++);
	
}

void send(unsigned char x)
{
SBUF=x;
while(TI==0);
	//delay_us(10000);
	TI=0;
}

8051SerialSimulation.PNG
 

Turns out the circuit I was working on has a DS1232 WDT & it was resetting the controller.Thank you for the quick response!
 

ST pin(7) of DS1232 has to be driven from high to low state within the WDT time-out period(150 ms) or else it would reset the controller. ST pin is connected to my micro-controller at PORT 1 pin 0 , so I simply had to make it HIGH at the beginning of the while loop & LOW at the end.
 
Hi Praveen,

You can use below code & check:

Code:
#include <reg51.h>
#include <stdio.h>

void init()     // Initialize Timer 1 for serial communication
{
TMOD=0x20;  //Timer1, mode 2, baud rate 9600 bps
TH1=0XFD;
SCON=0x50;
TR1=1;
}

void recieve()  //Function to receive serial data
{
unsigned char value;
while(RI==0);
value=SBUF;
P1=value;
RI=0;
}

void transmit()  // Funtion to transmit serial data
{
P2=P1-32;
SBUF=P2;
while(TI==0);
TI=0;
}

void main()
{
while(1)
{
  init();
  recieve();
  transmit();
}
}


Image of Proteus Simulation for your reference:
5866703200_1451464009.png
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top