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.

how to receive data in vb through 89c51 through rs232

Status
Not open for further replies.

ronizidane

Newbie level 3
Joined
Aug 9, 2007
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
89c51 rs232

hi , i'm roni .
i need u r assistance guys. i need a code for only receiving data from 89c51 in VB6.
i've used RS232 & i don't know now what to do plz hwlp me.
does anybody know abt that?
i'm running out of time .plz reply within 1-2 days .it's urgent.......

thanks for u r help.
 

transfer data to excel vb6

Hi Roni,

*. First you must create VB program with comm control, then set the serial data (baud, data bit, stop bit, parity) and set proper data type property for the control (binary or char)

*. in 8051 in your code set serial bit mask and serial port setting (same data format with vb)

*. the interrupt will trigger when the 51 receive correct serial data
 

vb6 code for serial data receive

Initialize MSCommunication Control
Code:
 Private Sub Form_Load()

' Fire Rx Event Every single Bytes
   MSComm1.RThreshold = 1

' When Inputting Data, Input 1 Byte at a time
   MSComm1.InputLen = 1

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

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

End Sub
Data Receiving Event
Code:
 Private Sub MSComm1_OnComm()
 Dim Data As String

' If comEvReceive Event then get data and display
    If MSComm1.CommEvent = comEvReceive Then
       Data = MSComm1.Input                'get data
       lbldata.caption = Asc(Data)        'convert to ASCII and display
    End If
End Sub
Finally close the comm port ...
Code:
 Private Sub Form_Unload(Cancel As Integer)
    MSComm1.PortOpen = False        'Close the COMM port
 End Sub
 

to receive data serially vb6

Hi Roni
I am not providing you full source here. i want you too do little home work to get final anticipated results. Not confusing but giving you breakdown structure with Array and Split command to understand easily.

So you got data into string Data
Next you have to process received data at Interface programme. Generally we send data from MC to RS232 in specific format to recognize bits related to each process of MCU with startbits and stopbits. You can do this at Microcontroller level using C or Assembly to reduce code at front end.

In your case you have to process raw data in VB6 and export it to excel file.
We need to format data into specific format before exporting into array or string variable. like 1#0#1#0#1#1#1#1#1
so now it is clear that to further process in your interface application... first bit, second bit, third bit..... to do this

Declare FileData string as Global Variable
Code:
Private Sub MSComm1_OnComm() 
    If MSComm1.CommEvent = comEvReceive Then 
	Data =  MSComm1.Input 
	FileData = FileData + "#" + Asc(Data) ' Here you are accumulating data to Global string with # delimited format
    End If 
End Sub
Now you got your data into string in format for futher process.
Place one command button labeled Export to Excel or what ever you wish.

In Command Export to Excel click event
Code:
Dim McuArry() As Sring  ' Declaring an Array
McuArry = Split(Filedata, "#") split the contents of the FileData variable at the # and store the results in McuArry

   Dim oExcel As Object
   Dim oBook As Object
   Dim oSheet As Object

   'Start a new workbook in Excel
   Set oExcel = CreateObject("Excel.Application")
   Set oBook = oExcel.Workbooks.Add
For example consider you are getting three values from MCU and you want header for those three valued columns and transfer data.
Code:
   'Add headers to the worksheet on row 1 for three columns
   Set oSheet = oBook.Worksheets(1)
   oSheet.Range("A1:C1").Value = Array("Value1", "Value2", "Value3")

   'Transfer the array to the worksheet starting at cell A2
   oSheet.Range("A2").Resize(100, 3).Value = McuArry
Finally Save your work book specific location on your hard disk and release Excel from memory
Code:
  'Save the Workbook and Quit Excel
   oBook.SaveAs "C:\McuBook.xls"
   oExcel.Quit
So you got string array in format.. now got awared about how to split string and store it into array.. just think if it is first time data fetching what to do.. Just create or Append.. Easy to append data to sring array without reinitializing entire application.. It's very easy to Open existing Excel file and append data to last rows..... :D
If i am wrong at any line please let me know.. :idea: Have a nice coding....
With Regards
Pcup
 

excel rs232 vba

u can use the mscomm component to send and receive data
 

89c51 projects visual basic communication

#include <AT89X51.H>

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


void main (void)
{
//int i;
char chr; /* variable to hold characters in */
SCON = 0x50; /* mode 1, 8-bit uart, enable receiver */
TMOD = 0x20; /* timer 1, mode 2, 8-bit reload */
TH1 = 0XFD; /* 9600 */
TR1 = 1;
TI = 1;
while (1)
{
chr = getCharacter ();
//for(i=0;i<3300;i++)
//{};
P1=chr;

}
}

i have leds on port 1 & m using this code but didnt get anything on LEDs can u plz guide me
 

excel comevreceive code

Check out here for microcontroller with VB.
**broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top