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] UART Programming Problem /MicroC / Proteus / MATLAB

Status
Not open for further replies.

Zulo

Newbie level 4
Joined
Dec 27, 2010
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,351
The Problem Have Solved... You can see it end of this page. Thanks
Hi guys,

I'm new here. i have checked many topics but cant find the problem like mine.

Thanks For all your helps.

What i have to do is:
Send data from MATLAB!
Receive it from PIC16f877!
control some pins...
*Problems
I can Send data from MATLAB
I can see it on Virtual Terminal out of RS232
But i cant see it out of PIC. The data changes...
*
I tried another one (without MAX232)
i send integer 11
But PIC can not understand the data which MATLAB sent...

//---The Codes--\\
MATLAB CODE FOR SERIAL DATA SEND
s=serial('COM1');
set(s,'BaudRate',9600)
fopen(s);
tx=11;
fprintf(s,'%d',tx);
fclose(s)
delete(s)
clear s
disp('SENT');
---
MICROC CODE FOR DATA RECEIVE AND SEND
unsigned int ii;
void main() {
TRISB=0;
PORTB=0xFF;
UART1_Init(9600);
Delay_ms(100);
while (1) {
if (UART1_Data_Ready()) {
ii = UART1_Read();
UART1_Write(ii);
}
}
}
---
The Proteus Design:
(Without MAX232)
Without MAX232.jpg
With MAX232.jpg
COMPIM properties.jpg
get(s)_virtuals_Device Manager.jpg
***
What i have tried before and useles:
use 4 x 1uf for Max232
change PIC code like
unsigned char/ char / int / unsigned int
Change MATLAB code
char / fwrite / odd*even*none parity bits.

Sory For My Bad english:sad:
 
Last edited:

the tx of the serial should go to rx of the pic and vice versa
 
It doesnt work when I switch...
Nothing happens on the Virtual Terminam Windows. By the way I'm using a virtual serial port..
I send the data to COM1 (data will be TX)
The com 1 send the data COM2 (now data is on RX of COM2)
thanks for answer...
 
is it becouse of my computer? my ISIS? MATLAB???
I m tired of working here for 10 hours and still not have an idea...
If someone have a Hex file or C-code (MikroC) can you share it please?
Receive data(PIC) => if it is something (if receivedata=='x') => PORTB=0;
this problem will make me broke my computer...
 

most probably is the code and may be the isis, i have heard bugs on isis due to timing issues
 

Thanks for advice to others have ideas on timing i have to tell stg:
I have change all the BaudRates 2400-9600 nothing happens. stil the same problems.. by the way what is wrong here?
if (UART1_Data_Ready()) {
UART1_Write(902);
}
i write 902 =>/=> i see "x"
???

---------- Post added at 18:03 ---------- Previous post was at 16:22 ----------

The problem has been solved by accidently :grin:
-The UART in Micro C-
The data which have sent by serial must be read by a char.
The true code is here:
unsigned char ii;
void main() {
TRISB=0;
PORTB=0xFF;
UART1_Init(9600);
Delay_ms(100);
while (1) {
if(UART1_Data_Ready()) {
ii=UART1_Read();
if(ii=='g'){
PORTB=0x00;
UART1_Write(ii);
}
}
}
}
or char ii;
i have tried using char before in another computer windows 7 why it didnt work i dont know.
But in another computer (XP) when i tried to get data to a char it works correct. thanks all who try to help...
 

Please,someone help me to confirm if i can use MATLAB to programe and simulate microcontroller and electronics,please i need urgent help.
 

Hey can you send your proteus file.I m working on similar project but i am using 8051. Need to send serial data from PC(matlab) to microcontroller.After uc receives data.It shud perform some task!
 

MATLAB will send data using serial communication. You only have to write code to receive serial data and display it.

You can find codes at saeedsolutions.blogspot.com
https://www.engineersgarage.com/
and in the book "8051 Microcontroller and Embedded Systems Using Assembly and C" by Muhammed Ali Mazidi.
It has both asm and C codes.
 

Hey can you send your proteus file.I m working on similar project but i am using 8051. Need to send serial data from PC(matlab) to microcontroller.After uc receives data.It shud perform some task!

Sory,

I dont have it now... It was 2-3 years ago...
 

I have similar problems like you had.IF i send data 11 through matlab.There will be some different characters displayed in the virtual terminal..what may be problem
 

I have similar problems like you had.IF i send data 11 through matlab.There will be some different characters displayed in the virtual terminal..what may be problem

You must provide exact error mapping.
What character is displayed to what input ?


+++
 

This is the microcontroller code
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;
	}
circuit is eda4.jpg.. Data is sent serially from matlab !!.. Virtual terminal between max232 and COmpim gives correct data.But one connected to microcontroller doesnt show correct data Gives abnormal data like eda5.JPG. Please tell the problem!
 

Are you getting wrong data in VT connected between COMPIN and MAX232. If yes, you have to cross the connections of VT.

Put a pullup resistor on RxD line of VT connected between MCU and MAX232. See if that works.

Zip and post your project and proteus files. I will debug and see.
 

anybody can reply , why COMPIN package is missing from proteus package ,, and how to find the package ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top