Friday, 21 September 2012

Tishitu RS-232 Communication with Keil, Proteus, Virtual serial Port & Visual Basic 6.0



Visual Basic was designed to be easy to learn and use. The language not only allows programmers to easily create simple GUI applications, but also has the flexibility to develop fairly complex applications as well. Programming in VB is a combination of visually arranging components or controls on a form, specifying attributes and actions of those components, and writing additional lines of code for more functionality. Since default attributes and actions are defined for the components, a simple program can be created without the programmer having to write many lines of code. Performance problems were experienced by earlier versions, but with faster computers and native code compilation this has become less of an issue.

Although programs can be compiled into native code executables from version 5 onwards, they still require the presence of runtime libraries of approximately 2 MB in size. This runtime is included by default in Windows 2000 and later, but for earlier versions of Windows it must be distributed together with the executable.

Forms are created using drag and drop techniques. A tool is used to place controls (e.g., text boxes, buttons, etc.) on the form (window). Controls have attributes and event handlers associated with them. Default values are provided when the control is created, but may be changed by the programmer. Many attribute values can be modified during run time based on user actions or changes in the environment, providing a dynamic application. For example, code can be inserted into the form resize event handler to reposition a control so that it remains centered on the form, expands to fill up the form, etc. By inserting code into the event handler for a keypress in a text box, the program can automatically translate the case of the text being entered, or even prevent certain characters from being inserted.

Visual Basic can create executables (EXE files), ActiveX controls, DLL files, but is primarily used to develop Windows applications and to interface web database systems. Dialog boxes with less functionality (e.g., no maximize/minimize control) can be used to provide pop-up capabilities. Controls provide the basic functionality of the application, while programmers can insert additional logic within the appropriate event handlers. For example, a drop-down combination box will automatically display its list and allow the user to select any element. An event handler is called when an item is selected, which can then execute additional code created by the programmer to perform some action based on which element was selected, such as populating a related list.



Visual Basic can be used to access serial communication functions. Windows hides much of the complexity of serial communications and automatically puts any received characters in a receive buffer and characters sent into a transmission buffer. The receive buffer can be read by the program whenever it has time and the transmit buffer is emptied when it is free to send characters.

Communications control
Visual Basic allows many additional components to be added to the toolbox. The Microsoft Comm component is used to add a serial communication facility.
In order to use the Comms component the files MSCOMM16.OCX (for a 16-bit module) or MSCOMM32.OCX (for a 32-bit module) must be present in the WINDOWSSYSTEM directory. The class name is MSComm. The communications control provides the following two ways for handling communications:

Event-driven. Event-driven communications is the best method of handling serial communication as it frees the computer to do other things. The event can be defined as the reception of a character, a change in CD (carrier detect) or a change in RTS (request to send). The OnComm event can be used to capture these events. and also to detect communications errors.
Polling. CommEvent properties can be tested to determine if an event or an error has occurred. For example, the program can loop waiting for a character to be received. Once it is the character is read from the receive buffer. This method is normally used when the program has time to poll the communications receiver or that a known response is imminent.
simulation Circuit for RS 232 communication 

Visual Basic Screen Shots 

Communication port configure window from control panel 

Properties of Communication Port Control
The Comm component is added to a form whenever serial communications are required. By default, the first created object is named MSComm1 (the second is named MSComm2, and so on). It can be seen that the main properties of the object are: CommPort, DTREnable, EOFEnable, Handshaking, InBufferSize, Index, InputLen, InputMode, Left, Name, NullDiscard, OutBufferSize, ParityReplace, RThreshold, RTSEnable, Settings, SThreshold, Tag and Top.

Code For Keil compiler or Embedded 'C'
###############################################################################

#include<reg51.h>
sbit cmd=P1^0;
sbit led=P1^1;
void ISR_sc(void) interrupt 4
{
unsigned char v;
if(RI==1)
{
v = SBUF;
if(v==0x30)
{led=0;}
if(v==0X31)
{led=1;}
RI=0;
return;
}
}
void main()
{
TMOD=0X20;
SCON=0X50;
IE=0X90;
TH1=0XFD;
TR1=1;
led=0;
while(1)
{
 if (cmd==0)
 {

SBUF=0x31;
TI=0;
while(TI==0);
//led=1;
while(cmd==0);
 }
 if (cmd==1)
{
SBUF=0x30;
TI=0;
while(TI==0);
//led=0;
while(cmd==1);
}
}
}
#############################################################################
Hex Code for Firmware Burn or IC burning
#############################################################################

:03000000020054A7
:0C005400787FE4F6D8FD758107020026D5
:03002300020003D5
:07000300C0D075D000C0075A
:10000A0030980EAF99BF3002C291BF3102D291C26D
:01001A00984D
:05001B00D007D0D03237
:1000260075892075985075A890758DFDD28EC291F0
:1000360020900B759931C2993099FD3090FD309022
:0E004600EF759930C2993099FD3090E480FB3F
:00000001FF
#############################################################################
Code of Visual Basic 6.0 Forms
#############################################################################
Full Code Visual of Basic ... Request author ... Email- tishitu@gmail.com 
################################################################################