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.

8051 serial port enable

Status
Not open for further replies.

Hareesh Kumar

Junior Member level 2
Joined
May 17, 2011
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,450
#include <reg52.h>

void delay_max()
{
unsigned int i=0,j=0;
for(j=0; j<100; j++)
for(i=0; i<6000; ++i);
}

void main(void){

TMOD |= 0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1; //start timer
//RI=0;
//TI=0;
while (1) {

SBUF=0x0A; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;

delay_max();

SBUF=0x0F; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;

delay_max();
}
}
i used this code for enabling serial communication in hyperterminal but connection is geting,not geting corect result in the hyperterminal...settings are alright...
 

What's is the exact make and model of the of the 8051 you are using?

And what is the crystal frequency as well.

Are you getting any characters or garbage on the hyperterminal?
 

what characters you get on the window........ is it purposeful that you have put it in an infinite loop???????? you will get ascii value of these in the terminal window only.......

what do you expect the result????

---------- Post added at 11:32 ---------- Previous post was at 11:30 ----------

you will get * and / when it prints.........
 

iam getting a symbol like * in hyperterminal..but in keil debugger i can see the corect values 0x0f and 0x0a
 

Well 0x0A is the ASCII value for a linefeed (LF) and 0x0F is the ASCII value for the Shift In (SI) which may appear as a little star.

Try modifying your code:

Code:
#include <reg52.h>

void delay_max()
{
unsigned int i=0,j=0;
for(j=0; j<100; j++)
for(i=0; i<6000; ++i);
}

void main(void){

TMOD |= 0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1; //start timer
//RI=0;
//TI=0; 
while (1) {

SBUF='A';       //place ASCII value Character 'A' in buffer
while (TI==0); //wait until transmitted
TI=0;

delay_max();

SBUF='F';       //place ASCII value Character 'F' in buffer
while (TI==0); //wait until transmitted
TI=0;

delay_max();
}
}

This should improve your output, dont't confuse hex with ASCII Values:

**broken link removed**
 
Last edited:

how can i enable timer 2 for serial communication?what the value of registers in that situation?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top