Escolar Documentos
Profissional Documentos
Cultura Documentos
BY
MEMBERS
1
CERTIFICATE
SUPERVISOR
ACKNOWLEDGEMENT
2
Bismillahirrahmaanirrahim,
Lastly we thanks to all our friends because of with their help like
teaching us, give borrow their transport to us for buy the component
and equipment, and their morale supported.
3
ABSTRACT
This final report is established to fulfill the Final year Project/Thesis requirement for
Engineering for final semester student, a standard guideline is prepared to standardize
various documentations and this report is done mainly to list down all the important
aspect of the project or the electrical and electronic device that designed.
The project report focuses on the system which is designed by using the Microcontroller
AT89c2051. The infrared receiver have three pins in which two pins are for +5v supply
and ground while the third pin is for data output. The Infrared Receiver is designed for
demodulating the frequency of 30 kHz to 40 kHz, for example, TSOP1738 is designed
for demodulating frequency of 38 kHz which is used in our project.
The IR receiver module receives the data sent by remote handset, amplifies,
demodulates and converts it to MCU compatible voltage format and outputs it on its data
output pin. The microcontroller decodes the infrared signal data and the microcontroller
will sent the infrared Key code to the PC through the Serial port.
We use Microsoft Visual Basic 6.0 to receive the Key code through the Component
called MSCOMM which is a component for the Com port control. Through this
component we get the key code and do the appropriate functions.
After getting this key code of the Remote control the program compare the key code
with the code present in the program and if they are equal then the corresponding
function was done.
CHAPTER 1
4
MICROCONTROLLER BASED PC REMOTE CONTROL
CHAPTER 2
2-1 MICRO-CONTROLLER…………………………………………………….…………18
5
2-1-1 MICRO-CONTROLLER: WHY? WHAT? HOW?.....................................................18
2-2-3 SPEED……………………………………………………………………….………23
2-3 MAX232…………………………………………………………………………….…27
2-3-1 FEATURES…………………………………………………………….……………27
2-4 TSOP1738………………………………………………………………………..……27
CHAPTER 3
6
3-1-1 PRE-REQUEST FOR PROGRAMMING…………………………………………..……30
3-1-2 INTRODUCTION TO ASSEMBLY LANGUAGE…………………………...…………30
3-1-3 ASSEMBLY LANGUAGE AND OTHER COMPUTER LANGUAGES………………30
3-1-4 STRUCTURE OF ASSEMBLY PROGRAMMING……………………………..………31
3-1-5 ASSEMBLY CODE OVERVEIW……………………………………………….………31
3-1-6ARITHEMATIC AND LOGIC INSTRUCTIONS……………………………….………31
3-1-7 ADDRESSING MODES………………………………………………………………….32
3-1-8 ASSEMBLING AND RUNNING AN 8051 PROGRAM:……………………………….32
3-1-9 I/O PORT PROGRAMMING………………………………………………….…………32
3-2-2 SENSORS…………………………………………………………………………………40
3-2-3NTERFACING TO INFRA RED SENSOR………………………………………..……..40
CHAPTER 4
4-10 PROGRAMMING……………………………………………………………….………50
7
CHAPTER 5
5-1-1 FEATURES………………………………………………………………………………57
8
CHAPTER# 1
CHAPTER-1
1-1 INTRODUCTION
This chapter explains about the Microcontroller based Pc remote control ,motivation
to build this project ,a short history of remote control world .Remote control are mostly
infra red which plays a revolutionary vital role in changing our lives. This project
9
contains all about how to make a system to control your Personal computer remotely
with almost any remote controller you can find in your house TV Sets. Along this we
discuss the Remote control and it’s commercially and economically reviews how a
simple remote control works and in the end of the chapter we concluded the future of the
remote controls.
>Control panel
>Computer log off, reboot or shutdown
>Volume Up, down, Mute
>5 User defined Programs
The first TV remote control, called "Lazy Bones," was developed in 1950 by Zenith
Electronics Corporation (then known as Zenith Radio Corporation). Lazy Bones used a
cable that ran from the TV set to the viewer. A motor in the TV set operated the tuner
through the remote control. Although customers liked having remote control of their
10
television, they complained that people tripped over the unsightly cable that meandered
across the living room floor.
The first machines to be operated by remote control were used mainly for military
purposes. Radio-controlled motorboats, developed by the German navy, were used to
ram enemy ships in WW I. Radio controlled bombs and other remote control weapons
were used in WW II. Once the wars were over, United States scientists experimented to
find nonmilitary uses for the remote control.
In the early 1960s, solid-state circuitry (i.e., transistors) began to replace vacuum tubes.
Hand-held, battery-powered control units could now be designed to generate the
inaudible sound electronically. In this modified form, Dr. Adler's ultrasonic remote
control invention lasted through the early 1980s, a quarter century from its inception. By
the early 1980s, the industry moved to infrared, or IR, remote technology. The IR
remote works by using a low frequency light beam, so low that the human eye cannot
see it, but which can be detected by a receiver in the TV. Zenith's development of cable-
compatible tuning and tale text technologies in the 1980s greatly enhanced the
capabilities and uses for infrared TV remotes.
An IR remote control (the transmitter) sends out pulses of infrared light that represent
specific binary codes. These binary codes correspond to commands, such as Power
11
On/Off and Volume Up. The IR receiver in the TV, stereo or other device decodes the
pulses of light into the binary data (ones and zeroes) that the device's microcontroller
can understand. The microcontroller then carries out the corresponding command.
The basic parts involved in sending an IR signal include:
• Buttons
• Integrated circuit
• Button contacts
• Light-emitting diode (LED)
12
The remote signal includes more than the command for "volume up," though. It carries
several chunks of information to the receiving device, including:
• a "start" command
13
.1-5-1 SHORTER DEVELOPMENT TIME
An embedded application not only saves money but also shorten development time since
there is a vast library of soft ware already written for the DOS & Windows platforms.
The fact the windows is a widely used & well understood platform means that
developing our windows based embedded product reduces the cost & shorten the
developing time considerably.
14
Remote controllers are the amazing applications and commercial opportunities in many
industries for example in auto industry they are used to lock and unlock the car doors,
car parking with a remote control .Remote controls are the major part of industries in
any perspectives
1. The serial port cable can be longer than a parallel port cable, as serial port
transmits '1' as voltage from -5 to -12V and '0' as voltage from +5 to +12 V,
while parallel port transmits '1' as voltage of 5 volts and '0' as voltage of 0 volts.
At the same time the receiver of the serial port receives '1' as voltage from -3 to
-25 V and '0' as voltage from +3 to +25 V. Thus serial port can have maximal
swing up to 50 volts, while parallel port has maximal swing of 5 volts. Thus the
losses in the cable when transmitting data using serial port are less substantial
then losses when transmitting data using parallel port.
2. The number of wires needed when transmitting data serially is less than when the
transmission is parallel. Is the external device has to be installed at a great
distance from the computer, the cable with three wires is much cheaper than the
cable with 19 or 25 wires if the transmission is parallel. Still one should
remember that there are interface creation expenses for every
receiver/transmitter.
15
can already control your household appliances, including your computers through the
electrical wiring. Remote brain interfaces that you have no choice over are next. The
opportunities are obvious with more intuitive interaction, but so are the dangers and they
are not being presented truthfully
CHAPTER# 2
16
DEPARTMENT OF ELECTRONIC ENGINEERING
CHAPTER -2
2-1 MICRO-CONTROLLER
Microcontroller is the backbone and the center of activity of our project. First we justify
the importance of using a microcontroller in our project before choosing.
So, why do we use a micro-controller for the soul of our project? It is simply because
micro-controllers are cost effective and small enough to fit into our design. So the next
question is what type of micro-controller should we use?
There are four major 8-bit microcontrollers. There are Motorola’s 6811 Intel’s 8051,
Zilog`s Z8 and PIC 16X from Microchip Technology. There are also 16 bit and 32 bit
microcontrollers made by various chip makers. With all these different microcontrollers
our criteria to consider in choosing one? Three criteria in choosing one are as follows
17
MEETING THE COMPUTING NEEDS OF THE TASK AT HAND EFFICEINTLY AND
COST EFFECTIVE
In analyzing the needs of a microcontroller based project we must see whether an 8 bit,
16bit or 2 bit microcontroller can best handle the computing needs of the task most
effectively. Among other considerations in this category are:
✔ Speed
✔ Packaging
✔ Power consumption
✔ The amount of RAM and ROM on chip
✔ The amount of I/O pins and the timer on the chip
✔ How it is easy to upgrade to higher performance or lower power consumption
versions
✔ Cost per unit
In this broad sense of choosing a microcontroller we chose 8051. We chose the 8051
because of its popularity and cost effectiveness. Moreover there are plenty of public
domain software as well as commercial libraries available in the industry.
2-1-3 HISTORY OF MICRO-CONTROLLER
The 8051 is originally an Intel product, a cousin of the 80X 86 families designed for the
embedded control market in the 80s. As popular standards especially software standards
don’t easily die down, it flourishes for years and becomes one of the most popular 8-bit
micro-controllers worldwide.
18
2-1-4 MICRO-CONTROLLER 8051(AT892051)
Port 1
Port 1 is an 8-bit bidirectional I/O port. Port pins P1.2 to P1.7 provide internal pull-ups.
P1.0 and P1.1 require external pull-ups. P1.0 and P1.1 also serve as the positive input
19
(AIN0) and the negative input (AIN1), respectively, of the on-chip precision analog
comparator.
Port 3
Port 3 pins P3.0 to P3.5, P3.7 are seven bidirectional I/O pins with internal pull-ups.
P3.6 is hard-wired as an input to the output of the on-chip comparator and is not
accessible as a general purpose I/O pin. The Port 3 output buffers can sink 20 mA. When
1s are written to Port 3 pins they are pulled high by the internal pull-ups and can be used
as inputs. As inputs, Port 3 pins that are externally being pulled low will source current
(IIL) because of the pull-ups. Port 3 also serves the functions of various special features
of the AT89C2051 as listed below: Port Pin P3.0 P 3.1 P3.2 P3.3 P3.4 P3.5 Alternate
Functions RXD (serial input port) TXD (serial output port) INT0 (external interrupt 0)
INT1 (external interrupt 1) T0 (timer 0 external input) T1 (timer 1 external input)
RST
Reset input. All I/O pins are reset to 1s as soon as RST goes high. Holding the RST pin
high for two machine cycles while the oscillator is running resets the device. Each
machine cycle takes 12 oscillator or clock cycles.
XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.
XTAL2
Output from the inverting oscillator amplifier.
2-1-6 FUNDAMENTAL OPERATION OF AN 8051 MICRO-
CONTROLLER BASED SYSTEM
Micro-controller system has the following configuration
• The microprocessor is connected to a clock, which determines the operating
frequency of the system
• After the reset switch is depressed, the microprocessor first loads the content of
a startup location from the startup ROM (0000H for 8051).
2-1-7 THE 8051 SYSTEM ARRCHITECTURE
To understand the operation of the 8051 based system, we need to study how
20
data and programs are stored in the system. Here we will examine two memory
storage subsystems:
21
RS232 is a popular communications protocol for connecting modems and data
acquisition devices to computers. RS232 devices can be plugged straight into the
computer's serial port (also known as the COM or Com port). We use RS232 connector
DB-9 male to interface to PC COMM port. We know that 8051 consist of built on serial
port for interfacing to the serial port of a personal computer (PC).
Rs232 can be used to connect between the PC and 8051. RS-232 is the interface that
your computer uses to talk to and exchange data with your.
DCD: - Data Carrier Detect (DCD) indicates that carrier for the transmit data is ON.
RXD: - This pin carries data from the serial device to the computer.
Tad: - This pin carries data from the computer to the serial device.
DTR signals: - DTR is used by the computer to signal that it is ready to communicate
with the serial device like modem. In other words, DTR indicates to the Dataset (i.e., the
modem or DSU/CSU) that the DTE (computer) is ON.
22
Fig 2-4: Serial Port of a typical Personal Computer
DSR: - Similarly to DTR, Data set ready (DSR) is an indication from the Dataset that
itIs ON.
CTS: - This pin is used by the serial device to acknowledge the computer's RTS Signal.
In most situations, RTS and CTS are constantly on throughout the communication
session.
23
RI: - RI stands for Ring Indicator. A modem toggles (keystroke) the state of this line
when an incoming call rings your phone. In other words, this is used by an auto answer
modem to signal the receipt of a telephone ring signal
2-2-3 SPEED
The speed of RS232 communications is expressed in Baud The length of the cable also
plays a part in maximum speed. The longer the cable, the greater the cable's capacitance
and the slower the speed at which you can obtain accurate results.
2-2-4 RS232 SPECIFICATIONS
2-3 MAX232
24
RS232 voltage levels (-10V and +10V) from 5V power supply. It also includes two
receiver and two transmitters and is capable of full-duplex UART/USART
communication. MAX232 IC chips are referred to as “Line Driver”.
2-3-1 FEATURES
2-4 TSOP1738
TSOP1738 is an Infrared (IR) receiver which is widely used in large number of
electronic products for receiving and demodulating infrared signals. The received
demodulated signals can be easily decoded by a microcontroller. It supports RC5, RC6
code, Sony format (SIRCS), NEC code, Sharp code, etc.
25
FIG 2-7: TSOP1738 IC
Pin 1= GND
Pin 2=VCC
Pin 3=OUT
1. Unregulated voltage in
2. Ground
3. Regulated voltage out
26
Fig: 2-8:7804 regulated IC
1 AT89C2051 1
2 RS232 Connector(FEMALE) 1
3 RS232 CABLE 1
4 Capacitor (33pF) 2
5 Capacitor 0.1 uF 2
6 Diode 1N4148 2
7 Capacitor 10 uF 5
9 7805 ic 1
10 Toggle Switch 1
11 TSOP 1738 1
27
CHAPTER# 3
CHAPTER-3
28
issues we are able to design out project circuit using different interfacing techniques of
8051.
29
(Label:) mnemonic (operands) (;comment)
30
(pointer), which is then accessed to provide the data for the instruction (e.g. MOV
[R0],A or MOV @R0,A)
Immediate addressing: the value to be used as data in the instruction is included
directly in the instruction syntax and in the program memory (e.g. MOV R0,#0)
3-1-8 ASSEMBLING AND RUNNING A PROGRAM
1. First we use an editor to type our program such as MS-DOS edit program or Notepad,
the source program has the extension “asm” or “src”.
2. The” asm” source file is fed to an 8051 assembler which converts the instructions into
machine code.
3. Assembler required a third step called linking. The link program takes one or more
object files and produces an absolute file with extension “abs”.
4. ”abs” file is fed into a program called “OH”(object to hex converter) which creates a
file with extension ”hex” that is ready to burn in ROM.
3-1-9 I/O PORT PROGRAMMING
The two 8-bit I/O ports P1and P3 each uses 8 pins. All the ports upon RESET are
configured as input, relay to use as input ports. When the 0 is written to apart ,it
becomes an output port and to configure it as an input ,a 1 must be sent to the port.
To use any of these ports as an input port, it must be programmed.
31
FIG 3-2: Steps to create a program
Port 1:
32
Port 1 is configured as an input port upon Reset. Port 1 is configured first
as an input port by writing 1s to it, then data is received from that port and
saved R7 and. R5.
Port 3:
Port 3 can be used as input or out put and does not need any pull up
resistors .Port 3 is configured as an input port upon reset. It has the
additional function of providing some extremely important signals.
i. External interrupt 0
ii. Timer 0
iii. External interrupt 1
iv. Timer 1
v. Serial Port
While programming the interrupts some points should be remember
33
FIG 3-3: IE Register
We can alter the sequence by assigning a higher priority to any one of the interrupts.
This is done by programming a register IP.
34
FIG 3-5: IP Register
PT1: Timer 1
PT0: Timer 0
35
FIG: 3-6: Microcontroller 8051 interface techniques classification
ends at connector called DB-9/DB25.When connecting the 8051 to the RS232 serial
interface, one major concern is the difference in voltage levels between them. The 8051
uses the TTL voltage levels where a 5V would indicate a high while a 0 indicates a low.
Mean while ,for the RS232 a High is defined as being +3V to +15V while a low is
between -5V to -15V.Because of this the connection between the 8051 and the RS232
have to done through line divers(Max232). Line drivers basically function to convert
between the two different voltage levels so that a high or low as understand by the 8051
also means a high or low to the RS232 and vice versa..
RxD and TxD pins in the 8051
36
The 8051 has two pins that are used specially for transferring and receiving data serially.
These two pins are called TxD and RxD and are the part of the port 3 groups
(P3.0,P3.1).
37
3-2-2 SENSORS
38
Sensors are electronics or electrical devices that change in some significant way in
response to an applied stimulus. Sensors, transducers and electrodes are used to compute
the physical standards by producing voltage signal that represents that parameter or
standard.
3-2-3NTERFACING TO INFRA RED SENSOR
IR Proximity sensor is the major component of the receiver circuit of our project, it has
an IR sensor which act as IR receiver with a built-in 38 KHz demodulator. We choose
TSOP1738 because it compatible to 8051 microcontroller TTL logic level. The
demodulated output signal can be directly decoded by the microcontroller.
39
FIG 3-11: Circuit Diagram of PC Remote Control
40
MICROCONTROLLER 8051 BASED PC
REMOTE CONTROL VIA SERIAL PORT
CHAPTER# 4
CHAPTER # 4
41
SERIAL COMMUNICATION AND
PROGRAMMING THE SERIAL PORT
Computer transfers data in two ways: parallel and serial. In parallel data transfers often 8
or more lines (wire connection) are used to transfer data to a that is only a few feet
away. to transfer to a device located many meters away. The serial method is used. In
serial communication, the data is sent one bit at a time. In this chapter we discuss the
basics of serial communication and its programming
I. Asynchronous
II. Synchronous
The synchronous method transfer a block of data(characters) at a time while the
asynchronous transfers a single byte at a time. It is possible to write software to
use either of the method but the program can be tedious and long. For this
reason, there are special IC chips made by many manufacturers for serial
communication. These chips are commonly referred to as UART(universal
asynchronous receiver-transmitter) and USART (universal synchronous-
asynchronous recover-transmitter).The 8051 chips has a built-in UART
42
transmit registers are both accessed at Special Function Register SBUF. Writing to
SBUF loads the transmit register, and reading SBUF accesses a physically separate
receive register.
43
FIG 4-2: PC Baud rate supported by 486/Pentium IBM PC BIOS
Special Function Register SCON, while the stop bit is ignored. The baud rate is
programmable to either 1/32 or 1/64 the oscillator frequency.
Mode 3:
11 bits are transmitted (through TxD) or received (through RxD): a start bit (0), 8 data
44
bits (LSB first), a programmable 9th data bit, and a stop bit (1). In fact, Mode 3 is the
same as Mode 2 in all respects except baud rate. The baud rate in Mode 3 is variable.
Program in which the 8051 reads data from P1 and writes it to P2 continuously while
giving a copy of it to the serial COM port to be transferred serially. Assume that
XTAL=11.0592. Set the baud rate at 9600.
CODE:
ORG
LJMP 0000H
45
ORG MAIN
LJMP 23H
ORG SERIAL; jump to serial int ISR
MAIN: MOV 30H
MOV P1,#0FFH ;make P1 an input port
MOV TMOD,#20H ;timer 1, auto reload
MOV TH1,#0FDH ;9600 baud rate
MOV SCON,#50H ;8-bit,1 stop, ren enabled
SETB IE,10010000B ;enable serial int.
BACK: MOV TR1;start timer 1
MOV A,P1;read data from port 1
MOV SBUF,A;give a copy to SBUF
SJMP P2,A;send it to P2
BACK;stay in loop indefinitely;-----------------SERIAL PORT ISR
ORG 100H
SERIAL: JB TI,TRANS;jump if TI is high
MOV A,SBUF ;otherwise due to receive
CLR RI;clear RI since CPU doesn’t
RETI;return from ISR
TRANS: CLR TI;clear TI since CPU doesn’t
RETI;return from ISR
END...
1. TMOD register is loaded with the value20H, indicating the use of timer 1 in
mode (8-bit auto-reload) to set baud rate
1. The TH1 is loaded with one of the values to set baud rate for serial data transfer
2. The SCON register is loaded with the value 50H, indicating serial mode 1, where
an 8- bit data is framed with start and stop bits
46
3. TR1 is set to 1 to start timer 1
6. The TI flag bit is monitored with the use of instruction JNB TI,xx to see if the
character has been transferred completely
Write a program for the 8051 to transfer “YES” serially at 9600 baud, 8-bit data, 1
stop bit, do this continuously
CODE:
MOV
TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-3;9600 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1;start timer 1
AGAIN: MOV A,#”Y”;transfer “Y”
ACALL TRANS
47
MOV A,#”E”;transfer “E”
ACALL TRANS
MOV A,#”S”;transfer “S”
ACALL TRANS
SJMP AGAIN;keep doing it
;serial data transfer subroutine
TRANS: MOV SBUF,A;load SBUF
HERE: JNB TI,HERE;wait for the last bit
CLR TI;get ready for next byte
RET
For example, if your program wants to wait for a character to be received and
subsequently read it into the Accumulator, the following code segment may be used:
4-10 PROGRAMMING
This is the code which is burn in the microcontroller 8051 chip. This software is for
Phillips RC-5 remote decoding and controlling your pc with the help of a TV remote.
48
Pin used for reception is P3.3 while .you can use any pin as per your requiremnet.This
program is written for 8051 MCU running at 11.0592MHz.
CODE:
FLAGS: DS 1
CONTROL BIT FLAGS.0 ; toggles with every new keystroke
NEW BIT FLAGS.1 ; Bit set when a new command has been received
;---------==========----------==========---------=========---------
; PROCESSOR INTERRUPT AND RESET VECTORS
;---------==========----------==========---------=========---------
49
ORG 00H ; Reset
JMP MAIN
;---------==========----------==========---------=========---------
; ---------==========----------==========---------=========---------
; Interrupt 0 routine
; ---------==========----------==========---------=========---------
RECEIVE:
CPL P3.4
MOV 2,#235 ; Time Loop (3/4 bit time)
DJNZ 2,$ ; Waste Time to sync second bit
MOV 2,#235 ; Time Loop (3/4 bit time)
Djnz 2,$ ; Waste Time to sync second bit
Mov 2,#134 ; Time Loop (3/4 bit time)
Djnz 2,$ ; Waste Time to sync second bit
clr a
mov r6,#07h
50
djnz r6,pol1
MOV SUBAD,A
mov r6,#06h
pol2:
mov c,Input
rlc a
MOV A,SUBAD
MOV ADDR,A
ANL A,#0FH
MOV SUBAD,A
CJNE A,#03H,ZXC1
MOV A,COMMAND
CPL A
MOV COMMAND,A
AJMP ASZ
ZXC1: MOV A,SUBAD
CJNE A,#00H,ANSS
AJMP ASZ
51
ASZ: MOV A,ADDR
ANL A,#20H
MOV TOGGLE,A
CJNE A,ANS,ANSS
AJMP WAR
ANSS: JMP ANS1
WAR:
MOV TMOD,#20H
MOV TH1,#0FDH
MOV SCON,#50H
SETB TR1
MOV A,COMMAND
MOV P0,A
MOV SBUF,A
JNB TI,$
CLR TI
CLR TR1
MOV ANS,TOGGLE
MOV A,ANS
CPL ACC.5
MOV ANS,A
SETB NEW ; Set flag to indicate the new command
;################################################################
ANS1:
RETI
52
; ---------==========----------==========---------=========---------
; Main routine. Program execution starts here.
; ---------==========----------==========---------=========---------
MAIN:
MOV SP,#60H
CLR NEW
LOO:
JNB NEW,LOO
CLR NEW
AJMP LOO
END
53
MICROCONTROLLER 8051 BASED PC
REMOTE CONTROL VIA SERIAL PORT
CHAPTER# 5
54
DEPARTMENT OF ELECTRONIC ENGINEERING
5-1-1FEATURES
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
55
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.
5-2-1COMMUNICATIONS 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 Comm. component the files MSCOMM16.OCX (16-bit module) or
MSCOMM32.OCX (for a 32-bit module) must be present in the WINDOWS SYSTEM
directory. The class name is MSComm. The communications control provides the
following two ways for handling communications: Event-driven. Event-driven
56
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.
Visual Basic uses the standard Windows drivers for the serial communication ports
(such as serialui.dll and serial.vxd). The communication control is added to the
application for each port. The parameters (such as the bit rate, parity, and so on) can be
changed by selecting Control Panel >System >Device Manager >Ports (COM and
LPT) >Port Settings. The settings of the communications port (the IRQ and the port
address) can be changed by selecting Control Panel >System >Device Manager > Ports
(COM and LPT) > Resources for IRQ and Addresses.
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:
Comport, DTREnable, EOFEnable, Handshaking, InBufferSize, Index, InputLen,
InputMode, Left, Name, NullDiscard, OutBufferSize, ParityReplace, RThreshold,
RTSEnable, Settings, SThreshold, Tag and Top.
Settings
The Settings property sets and returns the RS-232 parameters, such as baud rate,
parity, the number of data bit, and the number of stop bits. Its syntax is:
[form.]MSComm.Settings = setStr[$]
where the strStr is a string which contains the RS-232 settings. This string takes the
form:
"BBBB,P,D,S"
where
BBBBdefines the baud rate,
57
P the parity,
D the number of data bits, and
S the number of stop bits.
The following lists the valid baud rates (default is 9600Baud):
110, 300, 600, 1200, 2400, 9600, 14400, 19200, 38400, 56000, 128000, 256000.
The valid parity values are (default is N): E (Even), M (Mark), N (None), O (Odd),
S(Space).
The valid data bit values are (default is 8): 4, 5, 6, 7 or 8.
The valid stop bit values are (default is 1). 1, 1.5 or 2.
An example of setting a control port to 4800Baud, even parity, 7 data bits and 1 stop bit
is:
Com1.Settings = "4800,E,7,1"
[form.]MSComm.CommPort = portNumber[%]
which defines the portNumber from a value between 1 and 99. A value of 68 is
returnedif the port does not exist.
PortOpen
The PortOpen property sets and returns the state of the communications port. Its syntax
is:
A True setting opens the port, while a False closes the port and clears the receive
andtransmit buffers (this automatically happens when an application is closed).
The following example opens communications port number 1 (COM1:) at 4800 Baud
with even parity, 7 data bits and 1 stop bit:
58
Count and InBufferSize.
Input
The Input property returns and removes a string of characters from the receive buffer. Its
syntax is:
[form.]MSComm.Input
To determine the number of characters in the buffer the InBufferCount property is tested
(to be covered in the next section). Setting InputLen to 0 causes the Input property to
read the entire contents of the receive buffer.
InBufferSize
The InBufferSize property sets and returns the maximum number of characters that can
be received in the receive buffer (by default it is 1024 bytes). Its syntax is:
[form.]MSCommInBufferSize = [numBytes%]
The size of the buffer should be set so that it can store the maximum number of
characters that will be received before the application program can read them from the
buffer.
The InBufferCount property returns the number of characters in the receive buffer. It can
also be used to clear the buffer by setting the number of characters to 0. Its syntax is:
[form.]MSCommInBufferCount= [count%]
59
buffer.The transmit buffer can also be cleared by setting it to 0. Its syntax is:
[form.]MSCommOutBufferCount. = [0]
➢ Step 1
Attach the PC comm. port 1 or 2 with RS232 connector of PC remote control receiver
Circuit.
➢ Step 2
➢ Step 3
60
➢ Step 4
Press any key from the remote handset at that time IR receiver module receives the data
sent by remote handset. The microcontroller decodes the infrared signal data and the
microcontroller will sent the infrared Key code to the PC through the Serial port.
➢ Step 5
The PC remote control software receives the Key code through the Component called
MSCOMM which is a component for the Com port control. Through this component we
get the key code and do the appropriate functions.
➢ Step 6
After getting this key code of the Remote control the program compare the key code
with the code present in the program and if they are equal then the corresponding
function was done.
61
NOTE: If the software gives an error of missing file "MSCOMM32.ocx", the use
the ox file supplied in the zip file and follows the instructions below:
62
References
www.8051projects.info
www.8051projects.net
63