help for serial communication PC and 89c51

Status
Not open for further replies.

ehsanelahimirza

Full Member level 6
Joined
Feb 24, 2006
Messages
334
Helped
28
Reputation
56
Reaction score
7
Trophy points
1,298
Activity points
3,570
serial communication with 89c51

hi all


i m doing serial communication with pc and 89c51 but it is not working
i think my code is not correct.

plz correct me or guuide me

thanks

Code:
org 0h

main:



Serial_Init:
        ;Set timer 1 mode to 8-bit Auto-Reload
        mov TMOD,#20H
        ;Enable reception
        ;Set Serial port mode to 8-bit UART
        mov SCON,#50H
        ;Set baudrate to 9600 at 11.0592MHz
        mov TH1,#0FDH
	mov TH2,#0FDH
        mov TL1,#0FDH
	mov TL2,#0FDH
        ;Start Timer
        setb TR1
        
	Serial_Send:
        ;wait for last data to be
        ;sent completely
        jnb TI,Serial_Send
        ;clear the transmit interrupt flag
        clr TI
        ;Then move the data to send in SBUF
        mov SBUF,A
        

	Serial_Read:
        ;Wait for Receive interrupt flag
        jnb RI,Serial_Read
        ;If falg is set then clear it
        clr RI
        ;Then read data from SBUF
        mov A,SBUF
	mov p1,a
	acall delay
	jmp main


	DELAY:
	MOV R6 ,#0FFH
wait1:
	MOV R7 ,#0FFH

wait3: 
	
	DJNZ R7,wait3
	
	DJNZ R6,wait1

	RET
        
       
end
 

serial communication using max232 with 89c51

use this one:

Code:
ORG 0
	AJMP BEGIN
ORG 40h
BEGIN:
	MOV SCON,#01010000B 	; (50H) Mode 1/Rec en
					; bit 4 = REN receive enable				
					; bit 6 = mode 1. -  8 bit uart variable baud rate	
	MOV TH1,#0FDH 		; Reload value for 9600 Bd @11.0592 MHz
	MOV TMOD,#00100000B	; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1
					; bit 5 = 8 bit auto reload for timer 1 (Mode2)
	setb	TR1			; start timer 1

START: 
	JNB RI,START
	CLR RI
	MOV A,SBUF              ;read incoming byte
	MOV SBUF,A              ;send it back
	AJMP START
end
 

89c51 serial communication with pc

this code also not working

my PCB connection are OK

what else problem may be there?
 

89c51 read sbuf problem

The code I posted DOES work. Do you have a max232 in your circuit? In any terminal program you simply type a key and the same char will echo back to the PC.

Are you using an 11.0592 MHz clock? Do you have the terminal application set up for 9600 baud?

Check the above, I am sure you will get it to work.

Good Luck
 

serial reception in 89c51

yes it is working now. there was a problem in my PCB fottprint. pins were connected in wrong way.

but now communication is there, now problem i m facing is that continuous loss of data.

i.e. after sending and receiving 4 chars it will skip 1 char and after let say 6 chars it will receive some unknown char


what would be problem?
thanks for guiding me in advance
 

serial communication betweem 89c51 and pc

i would have to say that it seems like a hardware problem, possibly your max232, or maybe capacitors installed incorrectly.

It is tough to say until I see the actual board you are using, or a schematic.

Did you build the interface or is it a development board you purchased?
 

th1 configuration in 89c51

i built it myself
used max232

i m using polar capacitors
possibly i m wrong in connecting them

can i hv actual polar configuration in a diagram?
thanks
 

89c51 serial communication circuit max232

It's all in the datasheet
 

max232 connection with 89c51

i hv checked capacitors. all are connected in right way. all are 10uF.
what else?
 

serial communication in 89c51

according to the datasheet, the capacitors for the MAX232 should be no more than 1.0uF not 10uF.
 

yes, u r right. i will now change them then check.
actually it was 1.0uF which i read as 10uF and used 10uF

Added after 26 minutes:

in my book of 8051 by mazidi it is written that these capacitors may have a range from 1uF to 22uF. if i go with book then my circuit should work. but in data sheet also 0.1 or 1uF is mentioned, it is not said that above these capacitor will not work.
i m confused now.

what to do ...........?
plz help me out.....
 


There are so many manufacturers, and most of them are different. It is always best to go with the data sheet.

Good Luck
 

#include <AT89X51.H>

unsigned int del,i,x,temp;

char getCharacter (void)
{
char chr; // variable to hold the new character
while (RI != 1) {;}
chr = SBUF;
RI = 0;
return(chr);
}
void send (char a)
{
SBUF = a;
while (TI != 1);
TI=0;
}

void main (void){
char chr;
int i=0,j=0,count=0,inc=47;//inc=47
int index=0;
P1=0X00;
P2=0X00;

SCON = 0x50; // mode 1, 8-bit uart, enable receiver
TMOD = 0x20; // timer 1, mode 2, 8-bit reload
TH1 = 0XE6; // 1200
TL1 = 0XE6;
TR1 = 1;
TI = 0;
SBUF =0;

while(1){

your code

}
}
 

i m siddhartha.i am doing a project on "microcontroller based inter computer communication without lan".now i have to do serial communication between pc and 8951 microcontroller using MAX232.now i have have facing aproblem of the c program because i have no idea on programming.so if anyone help me with a c program that i can compile in keil software then i am greatful to him.
my email id sankar_622@yahoo.co.in.
plz help me immidiately.its urgent.
 

hi
i have same problem i m using 10uf capacitor i don't get the actual result...when i send something to controller (89s51) it revived perfectly but i read somthing from ccontroller it gives me garbage results... i m using HyperTerminal for communication...Plzzz help me out
 

Hii casamiro,

if you're using max 232 for UART, please check the datasheet. the datahseet suggest

capacitor 1uf polar.



here is the sampe code for setting UART 9600 Bps

in c :


Code:
#include <at89x51.h>

volatile char acceptext;
volatile bit status=0;

void IntSerial()Interrupt 4 using 1
{
Es=0;
RI=0;
status = 1;
acceptext = SBUF;
ES=1
}


Void inituart(void)   // serial port initialization
{
SCON = 0x50; // uart in mode 3
TMOD = TMOD | 0X20; // timer 1 in mode2
TH1 = 0xfd  ;// setting baudrate 9600 bps
TL1 = 0xfd;
ES=1        ; // enable serial interrupt 
EA = 1      ; // enable global interrupt
TR1 = 1      ; // start timer 1 running
}

void sendchar(char datasent) // for sending one charater
{
   SBUF = datasent;
   while (!TI)
   {;}
   TI = 0;
} 

void sendtext(char *text) //for sending text
{
  char i=0;
  while (text[i]!=0)
 {
  sendchar(text[i]);
  i++;
  }
}

Void main(void)
{
   inituart();
   sendtext("TRIAL 1");
}

Use SDCC for compile it, if you don't have use just download MIDE IDE for SDCC

http://www.opcube.com/home.html

Hope this help U

Deny(Bodat'z)
 

Thanks for reply
buddy when i compiled your given code it's shows an error .Plz check it.

Casamiro
 

@ the_balistic

Dude the code is working fine !!!!!!!! just has a problem of caps lock!!!

Change the Void---> void

Es--------> ES

Interrupt-------> interrupt

Thats it!!
 

after a long time i opened this website all of you guys have problem with PC and Micro Controller serial communication the little hint is re- check the baurd rate i had all these problems in my time what you r discussing here use 1200

- - - Updated - - -

after a long time i opened this website all of you guys have problem with PC and Micro Controller serial communication the little hint is re- check the baurd rate i had all these problems in my time what you r discussing here use 1200
 



Well I think now every one come out from this problem thank you for your suggestion.;-)
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…