serial communication between PC and microcontroller

A

Thread Starter

Anonymous

hi there, hope someone can help me here!!!

i'm doing a new project involving serial interface between PC and 8051 microcontroller using RS232. My question here is how can i use visual basic codes to read and retrieve the data stored in the microcontroller and how can i display it on the PC? please if anyone can help me, send me the codes or any information.

your help is much appreciated!!!

thanks
my mail add: [email protected]
 
H
Hi,

Use the mscomm module(ocx)
In visual basic:
Project -> components -> microsoft comm control

It's the most simple way to use the rs232 port.

Good luck,
 
J
<p>Here was my plan to realize the communication between PC and AT89C52, Both of them are set to 2400 (baud rate), N, 8, 1.

<p<1. I have shortened pin 2 and pin 3 of RS-232 attached to PC. When my pc was sending out DATA, at the same time it can receive this DATA. After doing this, I found my PC can correctly receive the DATA just sent out.

<p>2. The following is my C51 code. After receiving the incoming data, I want to show that data by LED connected to P1 port.

<p>I thought my C51 code should be wrong, but I really have no idea! Please help me!

<p>Sincere Thanks in advance.
<pre>
unsigned char ISRIN;
unsigned char ISROUT;
unsigned char SERIALISRIN;
void DELAY ();
void INI_SERIAL();
unsigned char RECE_SERIAL ();

void main ()
{
unsigned char DATD;
P1 = 0xff;
INI_SERIAL();
While(1) {
if (ISRIN ) {
ISRIN = 0;
DATD = RECE_SERIAL ();
}
}
}

void SERIAL_ISR ( ) interrupt 4 using 1 (
if ( TI ) {
TI = 0 ;
ISROUT = 1;
}
if ( RI ) {
RI = 0;
ISRIN = 1;
}
}

void INI_SERIAL() {
EA = 0;
T2CON = 0x34;
RCAP2L = 0x64;
RCAP2H = 0xff;
TL2 = 0x64;
TH2 = 0xff;
SCON= 0x50;
TI = 0;
RI = 0;
TR2 = 1;
ES= 1;
EA =1;
}
unsigned char RECE_SERIAL () {
unsigned char DAT;

P1 = SBUF;
DAT = P1;
DELAY ();
P1 = 0xff;
return DAT;
}

<p>By the way,how to select AT89C52 Timer 2 Serial Clock Divisor? right now, I am sure my MCU is working correctly for receiving and sending out the data (I did this under a friend's suggestion). So I thought the Serial Clock Divisor of AT89C52 is wrong.

<p>Would you help me to check it?

<p>Thank you.
 
<p>Hi,

<p>I was trying to send data from 89c2015 to pc using Vb.I wrote a code for th mcu as given below
<pre>
org 0
baudnum equ 0f3h
anl pcon,#7fh
anl tmod,#30h
orl tmod,#20h
mov th1,#baudnum
setb tr1
mov scon,#40h
xmit:
MOV sbuf,#"B"
wait:
JBC ti,xmit
SJMP wait
end
</pre>
<p>here i am sending 'B' to the serial port constantly.
Now on the vb side i wrote this
<pre>
Private Sub Command1_Click() 'this is a button
MSComm1.PortOpen = False
Unload Form1

End Sub

Private Sub Form_Load()
MSComm1.RThreshold = 2
MSComm1.InputLen = 2

' 2400 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = "2400,N,8,1"
' Disable DTR
MSComm1.DTREnable = False

' Open COM1
MSComm1.CommPort = 1
MSComm1.PortOpen = True
End Sub

Private Sub MSComm1_OnComm()

' If comEvReceive Event then get data and display
If MSComm1.CommEvent = comEvReceive Then
Text1.Text = MSComm1.Input

End If
End Sub
</pre>
<p>when i run this program i get some different character in textbox. I should get 'B' in it bcos i sent 'B' from the mcu. What is the problem? Can anyone help?
 
Top