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] Send data from Matlab to 8051 using proteus simulation.

Status
Not open for further replies.

kishore680

Member level 5
Member level 5
Joined
Mar 14, 2012
Messages
81
Helped
3
Reputation
6
Reaction score
4
Trophy points
1,298
Location
Bangalore
Activity points
1,833
Hi i have written small matlab code
Code:
s = serial('COM4','BaudRate',9600);
 fopen(s);
 fprintf(s,'A');
My circuit in proteus eda.JPG.. IF i send higood. i got this as output in virtual terminal eda1.JPG. And the keil code for receiving data serially is
Code:
#include<reg51.h>
void sertex(unsigned char);
void main(void)
   {							  unsigned char z;
						   TMOD=0x20;
						   TH1=0xFD;
						   SCON=0x50;
						   TR1=1;
				 		  
						   
			while(1)
{

while(RI==0);
z=SBUF;
P1=z;
RI=0;


}
}
. Please someone tell me whats the fault in circuit or in programme.I need to send data from PC and make sure microcontroller received it properly.Thanku
 

You have connected Rx pin and Tx pin of MCU to RxD and TxD pins of Virtual Terminal. It is wrong. You have to cross the wires. Rx to TxD and Tx to RxD.
 

HI tried that.In that case no data is displayed in the virtual terminal!!! Its blank... IF i take connection from COMPIM to virtual terminal i am getting exact result in virtual terminal
 
Last edited:

Where is your UART initialization settings? i.e., TMOD, EA, etc...

Ok. I see it is there. 9600 bps is your baudrate.

There is no serial transmit code. It receives serial data and assigns it to some port. How can you expect data in Virtual Terminal?

Just connect Rx pin of MCU to TxD pin of VT and remove the other connection from Tx of MCU and also RTS to CTS in VT.
 
Last edited:

TMOD=0x20;
TH1=0xFD;
SCON=0x50;.. Baud rate s 9600 everywhere!!.IS the max232 connection proper?

- - - Updated - - -

Ohk i thought i can tap that serial output and display . MY bad!! .So sir, what changes i have to make to appear data in the virtual terminal ?
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
void Tx_Char(unsigned char Data)
{
    SBUF=Data;              //SEND CHARACTER TO SERIAL BUFFER
    while(!TI);             //WAIT HERE TILL THE TRANSMIT INTERRUPT FLAG GOES TO                        //HIGH
    TI=0;                   //CLEAR TRANSMIT INTERRUPT FLAG
}
 
unsigned char Rx_Char()
{
    while(!RI);             //WAITING FOR CHARACTER
    RI=0;                   //CLEAR RECEIVE INTERRUPT FLAG
    return SBUF;                //RETURN DATA
}



Try receiving data in mcu and transmitting it again to VT. Have you selected COM4 in VT?
 

I have selected COM2 in COMPIM,,COM2 and com4 are in pair.I have done that using virtual serial emulator IN virtual terminal i have just set baud rate to 9600 .Didnt see any option for com port.
 

Code:
#include<reg51.h>
void Tx_Char(unsigned char);
void main(void)
   {							  unsigned char z;
   
   
						   TMOD=0x20;
						   TH1=0xFD;
						   SCON=0x50;
						   TR1=1;
						  
						   
						  
						   
			while(1)
{

	while(RI==0)
	z=SBUF;
	Tx_Char(z);
	RI=0;

}
}
	void Tx_Char(unsigned char c)
	{SBUF=c;
	while(TI==0);
	TI=0;
	}
This i modified and tried,YEt VT is blank.
 

IF i connect COMPIM to virtual terminal.I m getting exact result.But how do i knw microcontroller has received exact data?
 

Receive data in MCU and resend it. It will appear in VT. Just connect Tx pin of MCU to RxD pin of VT. Don't connect any other connections for RTS, CTS and Rx of MCU to TxD of VT.
 

eda3.JPG Code is the modified one. But didnt get..I tried sending from 8051 to VT. I got output!
 

Thank you. i have attached!Hex file is in keil folder. you have to load that into 8051
 

Attachments

  • eda.rar
    33.4 KB · Views: 78

See this image.

I finally found the problem and its solution. See image 2. The data out of the MAX232 is inverted. In VT between COMPIN and MAX232 select invert.
 

Attachments

  • uart.jpg
    uart.jpg
    368 KB · Views: 138
  • uart2.jpg
    uart2.jpg
    403 KB · Views: 125
Last edited:
Thank you very much for finding the problem.. sir can u attach that proteus file?. And what about code.Did u modify
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top