Thesis of Major Project
Thesis of Major Project
A thesis submitted to
BACHELOR OF ENGINEERING
ABHILAV VISHWAKARMA
BACHELOR OF ENGINEERING
2007-2011
1
DECLARATION BY THE CANDIDATE
I the undersigned solemnly declare that the report of the thesis work entitled
Low Budget Trainer kit based on Microcontroller 8051 is based on our own work carried out during the
course of our study under the supervision of Mr. T. V. Dixit.
I assert that the statements made and conclusions drawn are an outcome of my research work. I further
declare that to the best of my knowledge and belief the report does not contain any part of any work
which has been submitted for the award of PhD degree or any other degree/diploma/certificate in this
University or any other University of India or abroad.
Abhilav Vishwakarma
Enrollment No.
Enrollment No.
Enrollment No.
2
CERTIFICATE OF APPROVAL
This is to certify that the project work entitled ‘Development of a low budget trainer kit based on microcontroller
8051’, carried out by Mr. Abhilav Vishwakarma, Mr. Pradeep Kumar Srivastav, Mr. Nikhil Kumar Thakur &
Mr. Krishna Deo Prasad under my guidance and supervision for the award of the degree in Bachelor of
Engineering in the discipline Electrical & Electronics Engineering from Bhilai Institute Of Technology Durg ,
Chhattisgarh Swami Vivekanand Technical University Bhilai (C.G.), India
3
ACKNOWLEDGEMENT
This project is the product of ample amount of inspiration, support, guidance, coordination and facilities that were
extended to us by people at every level. I was Indebted to each one of them.
I wish to acknowledge my profound sense of gratitude to my project guide, Associate Professor Mr. T.V.
Dixit(Electrical and Electronics Engineering), for his remarkable guidance and support during the entire course of
project. It was a matter of great honor and privilege to have him as our project guide.
4
WHY A PROJECT
A technical student in his education period has to perform various experiments and research work on the subjects
which are being taught to him in the course of his studies. The organization of all these efforts with a definite
purpose to deal and stay with the problems longer is called a PROJECT.
The object of project is to involve technical thinking and inducing the students to make an ordinary analysis of
situations to search a definite solution.
By doing a project student displays his spirit of inquiring and developing criticizing ways of problem solving by
understanding the existing situations, independent thinking and ability to understand the basic facts.
5
CONTENT
1. Introduction to the project
2. Microcontroller 8051
4. In system programming
5. Circuit diagram
7.1 Microcontroller IC
7.1.2 Features
7.2.1 Cables
6
7.2.2 2 wire and 5 wire RS 232
7.2.3 Conventions
7.3.2 Features
7.4.2 Connection
7.5.1 Features
7.6.1 Features
7.6.2 Description
7.7.2 Features
7.8.2 Features
7.9.1 Testing
7
7.9.3 The circuit
8. Interfacing
12. Bibliography
8
1. INTRODUCTION TO PROJECT
Microcontroller based low budget trainer kit is a powerful medium for burning and running various programs which are
used to either perform the operation of a system or to have a control mechanism of any equipment which are solely based
on microcontroller.
This project is In System Programmable which means that no chip removal is required for reprogramming of the IC. Thus
we can burn a no. of programs on the chip by allotting specific memory locations to respective programs.
This project would be also helpful for performing various programs in laboratories by the students for the purpose of
understanding the programming skills and getting specialization in programming of microcontrollers.
This trainer kit besides working in ISP (In System Programming) mode also has a 16*2 LCD display and an interfacing
with analog to digital converter, digital to analog converter, keyboard and can also be interfaced with other devices like
stepper motor, Ethernet and can be provided with an additional I2C (inter integrated circuit), serial peripheral interface
and external memory devices.
The microcontroller IC used belongs to Philips family p89v51rd2 which has an on chip flash programmer and hence it can
be worked in the ISP mode and is capable to carry all the features which are required in this eloquent project.
9
2. MICROCONTROLLER 8051
A micro-controller can be compared to a small stand alone computer; it is a very powerful device, which is capable of
executing a series of pre-programmed tasks and interacting with other hardware devices. Being packed in a tiny integrated
circuit (IC) whose size and weight is usually negligible, it is becoming the perfect controller for robots or any machines
requiring some kind of intelligent automation. Any microcontroller contains a memory to store the program to be
executed, and a number of input/output lines that can be used to interact with other devices, like reading the state of a
sensor or controlling a motor.
Nowadays, microcontrollers are so cheap and easily available that it is common to use them instead of simple logic
circuits like counters for the sole purpose of gaining some design flexibility. Most recent microcontrollers are 'In System
Programmable', meaning that you can modify the program being executed, without removing the microcontroller from its
place.
Today, microcontrollers are an indispensable tool for the robotics hobbyist as well as for the engineer.
10
2.2 THE 8051 MICROCONTROLLER ARCHITECTURE
The 8051 is the name of a big family of microcontrollers. The device which we are going to use along this tutorial is the
'P89V51RD2' which is a typical 8051 microcontroller manufactured by Philips. A simpler architecture can be represented
as in the figure.
11
The figure shows the main features and components that the designer can interact with. You can notice that the 89V51 has
12
4 different ports, each one having 8 Input/output lines providing a total of 32 I/O lines. Those ports can be used to output
DATA and orders to other devices, or to read the state of a sensor, or a switch. Most of the ports of the 89V51 have 'dual
function' meaning that they can be used for two different functions: the first one is to perform input/output operations and
the second one is used to implement special features of the microcontroller like counting external pulses, interrupting the
execution of the program according to external events, performing serial data transfer or connecting the chip to a
computer to update the software.
Each port has 8 pins, and will be treated from the software point of view as an 8-bit variable called 'register', each bit
being connected to a different Input/output pin.
• Port 0 can also be used to provide the lower 8 bit address and 8 bit data.
• Port 2 provides the upper 8 bit address and when used with port 0, it provides 16 bit address.
• Each pin of port 3 is assigned a special function besides being used as I/O lines. This port plays a very important
role from communication point of view. It controls transferring and receiving of signals, handle interrupts and
performs read and write operation.
You can also notice two different memory types: RAM and EEPROM. Shortly, RAM is used to store variable during
program execution, while the EEPROM memory is used to store the program itself, that's why it is often referred to as the
'program memory.
It is just important to note that the 89V51 incorporates hardware circuits that can be used to prevent the processor from
executing various repetitive tasks and save processing power for more complex calculations. Those simple tasks can be
counting the number of external pulses on a pin, or generating precise timing sequences.
It is clear that the CPU (Central Processing Unit) is the heart of the microcontrollers; it is the CPU that will Read the
program from the FLASH memory and execute it by interacting with the different peripherals.
13
2.3 PIN DIAGRAM
Figure shows the pin configuration of the 89V51, where the function of each pin is written next to it, and, if it exists, the
dual function is written between brackets. The pins are written in the same order as in the block diagram of figure A,
except for the VCC and GND pins which is usually note at the top and the bottom of any device.
Note that the pin that has dual function can still be used normally as an input/output pin. Unless your program uses their
dual functions, all the 32 I/O pins of the microcontroller are configured as input/output pins.
Pin 31 (External access) always connected to VCC (5 Volts) to enable the micro-controller to use the internal on chip
memory rather than an external one (connecting the pin 31 to ground would indicate to the microcontroller that an
external memory is to be used instead of the internal one).
14
2.4 OSCILLATOR CIRCUIT
The 8051 requires the existence of an external oscillator circuit. The oscillator circuit usually runs around 12MHz,
although the 8051 (depending on which specific model) is capable of running at a maximum of 40MHz. Each machine
cycle in the 8051 is 12 clock cycles, giving an effective cycle rate at 1MHz (for a 12MHz clock) to 3.33MHz (for the
maximum 40MHz clock).
Reset Circuit
RESET is an active High input When RESET is set to High,
8051 goes back to the power on state.
The 8051 is reset by holding the RST high for at least two
machine cycles and then returning it low.
Power-On Reset
Manual reset
15
2.5 TYPES OF MEMORY
The 8051 has three very general types of memory. To effectively program the 8051 it is necessary to have a basic
understanding of these memory types. They are: On-Chip Memory, External Code Memory, and External RAM.
On-Chip Memory refers to any memory (Code, RAM, or other) that physically exists on the microcontroller itself.
External Code Memory is code (or program) memory that resides off-chip. This is often in the form of an external
EPROM.
External RAM is RAM memory that resides off-chip. This is often in the form of standard static RAM or flash RAM.
Code Memory is the memory that holds the actual 8051 program that is to be run. This memory is limited to 64K: Code
memory may be found on-chip, either burned into the microcontroller as ROM or EPROM. Code may also be stored
completely off-chip in an external ROM or, more commonly, an external EPROM. Flash RAM is also another popular
method of storing a program. Various combinations of these memory types may also be used--that is to say, it is possible
to have 4K of code memory on-chip and 64k of code memory off-chip in an EPROM.
When the program is stored on-chip the 64K maximum is often reduced to 4k, 8k, or 16k. This varies depending on the
version of the chip that is being used. Each version offers specific capabilities and one of the distinguishing factors from
chip to chip is how much ROM/EPROM space the chip has.
However, code memory is most commonly implemented as off-chip EPROM. This is especially true in low-cost
development systems and in systems developed by students.
Programming Tip: Since code memory is restricted to 64K, 8051 programs are limited to 64K. Some assemblers and
compilers offer ways to get around this limit when used with specially wired hardware. However, without such special
compilers and hardware, programs are limited to 64K.
External RAM as an obvious opposite of Internal RAM, the 8051 also supports what is called External RAM. As the
name suggests, External RAM is any random access memory which is found off-chip. Since the memory is off-chip it is
not as flexible in terms of accessing, and is also slower. For example, to increment an Internal RAM location by 1 requires
only 1 instruction and 1 instruction cycle. To increment a 1-byte value stored in External RAM requires 4 instructions and
7 instruction cycles. In this case, external memory is 7 times slower!
What External RAM loses in speed and flexibility it gains in quantity, while Internal RAM is limited to 128 bytes (256
bytes with an 8052), the 8051 supports External RAM up to 64KB.
On-Chip Memory
On-chip memory is really one of two types: Internal RAM and Special Function Register (SFR) memory.
The 8051 has a bank of 128 bytes of Internal RAM. This Internal RAM is found on-chip on the 8051 so it is the fastest
RAM available, and it is also the most flexible in terms of reading, writing, and modifying its contents. Internal RAM is
volatile, so when the 8051 is reset this memory is cleared.
The 128 bytes of internal ram is subdivided into 4 register banks. The first 8 bytes (00h - 07h) are "register bank 0". By
manipulating certain SFRs, a program may choose to use register banks 1, 2, or 3. These alternative register banks are
located in internal RAM in addresses 08h through 1Fh. Bit Memory also lives and is part of internal RAM. Bit memory
actually resides in internal RAM, from addresses 20h through 2Fh.
16
The 80 bytes remaining of Internal RAM, from addresses 30h through 7Fh, may be used by user variables that need to be
accessed frequently or at high-speed. This area is also utilized by the microcontroller as a storage area for the operating
stack.
Register Banks
The 8051 uses 8 "R" registers which are used in many of its instructions. These "R" registers are numbered from 0
through 7 (R0, R1, R2, R3, R4, R5, R6, and R7). These registers are generally used to assist in manipulating values and
moving data from one memory location to another. For example, to add the value of R4 to the Accumulator, we would
execute the following instruction:
ADD A,R4
Thus if the Accumulator (A) contained the value 6 and R4 contained the value 3, the Accumulator would contain the
value 9 after this instruction was executed.
Bit Memory
The 8051is a communication oriented microcontroller. It gives the user the ability to access a number of bit variables.
These variables may be either 1 or 0.
There are 128 bit variables available to the user, numbered 00h to7Fh. The user may make use of these variables with
commands such as SETB and CLR.
Special Function Register (SFR) Memory
Special Function Registers (SFRs) are areas of memory that control specific functionality of the 8051 processor. For
example, four SFRs permit access to the 8051s 32 input/output lines. Another SFR allows a program to read or write to
the 8051s serial port. Other SFRs allow the user to set the serial baud rate, control and access timers, and configure the
8051s interrupt system.
17
As you can see, although the address range of 80h to 0FFh offers 128 possible addresses, there are only 21 SFRs in a
standard 8051. All other addresses in the SFR range (80h to 0FFh) are considered invalid. Writing to or reading from
these registers may produce undefined values or behavior.
Programming Tip: It is recommended that you not read or write to SFR addresses that have not been assigned to an SFR.
Doing so may provoke undefined behavior and may cause your program to be incompatible with other 8051-derivatives
that use the given SFR for some other purpose.
SFR Types
As mentioned in the chart itself, the SFRs that have a blue background are SFRs related to the I/O ports. The 8051 has
four I/O ports of 8 bits, for a total of 32 I/O lines. Whether a given I/O line is high or low and the value read from the line
are controlled by the SFRs in green.
The SFRs with yellow backgrounds are SFRs which in some way control the operation or the configuration of some
aspect of the 8051. For example, TCON controls the timers, SCON controls the serial port.
The remaining SFRs, with green backgrounds, are "other SFRs." These SFRs can be thought of as auxillary SFRs in the
sense that they don't directly configure the 8051 but obviously the 8051 cannot operate without them. For example, once
the serial port has been configured using SCON, the program may read or write to the serial port using the SBUF register.
Programming Tip: The SFRs whose names appear in red in the chart above are SFRs that may be accessed via bit
operations (i.e., using the SETB and CLR instructions). The other SFRs cannot be accessed using bit operations. As you
can see, all SFRs that whose addresses are divisible by 8 can be accessed with bit operations.
SFR Descriptions: This section will endeavor to quickly overview each of the standard SFRs found in the above SFR
chart map. This section is to just give you a general idea of what each SFR does.
18
P0 (Port 0, Address 80h, Bit-Addressable): This is input/output port 0. Each bit of this SFR corresponds to one of the
pins on the microcontroller.
Programming Tip: While the 8051 has four I/O port (P0, P1, P2, and P3), if your hardware uses external RAM or
external code memory (i.e., your program is stored in an external ROM or EPROM chip or if you are using external RAM
chips) you may not use P0 or P2. This is because the 8051 uses ports P0 and P2 to address the external memory. Thus if
you are using external RAM or code memory you may only use ports P1 and P3 for your own use.
SP (Stack Pointer, Address 81h): This is the stack pointer of the microcontroller. This SFR indicates where the next
value to be taken from the stack will be read from an Internal RAM. If you push a value onto the stack, the value will be
written to the address of SP + 1. This SFR is modified by all instructions which modify the stack, such as PUSH, POP,
LCALL, RET, RETI, and whenever interrupts are provoked by the microcontroller.
Programming Tip: The SP SFR, on startup, is initialized to 07h. This means the stack will start at 08h and start
expanding upward in internal RAM. Since alternate register banks 1, 2, and 3 as well as the user bit variables occupy
internal RAM from addresses 08h to 2Fh, it is necessary to initialize SP in your program to some other value if you will
be using the alternate register banks and/or bit memory. It's not a bad idea to initialize SP to 2Fh as the first instruction of
every one of your programs unless you are 100% sure you will not be using the register banks and bit variables.
DPL/DPH (Data Pointer Low/High, Addresses 82h/83h): The SFRs DPL and DPH work together to represent a 16-bit
value called the Data Pointer. The data pointer is used in operations regarding external RAM and some instructions
involving code memory.
Programming Tip: DPTR is really DPH and DPL taken together as a 16-bit value. In reality, you almost always have to
deal with DPTR one byte at a time. For example, to push DPTR onto the stack you must first push DPL and then DPH.
You can't simply plush DPTR onto the stack. Additionally, there is an instruction to "increment DPTR." When you
execute this instruction, the two bytes are operated upon as a 16-bit value. However, there is no instruction that
decrements DPTR. If you wish to decrement the value of DPTR, you must write your own code to do so.
PCON (Power Control, Addresses 87h): The Power Control SFR is used to control the 8051's power control modes.
Certain operation modes of the 8051 allow the 8051 to go into a type of "sleep" mode which requires much less power.
These modes of operation are controlled through PCON. Additionally, one of the bits in PCON is used to double the
effective baud rate of the 8051's serial port.
TCON (Timer Control, Addresses 88h, Bit-Addressable): The Timer Control SFR is used to configure and modify the
way in which the 8051's two timers operate. This SFR controls whether each of the two timers is running or stopped and
contains a flag to indicate that each timer has overflowed. Additionally, some non-timer related bits are located in the
TCON SFR. These bits are used to configure the way in which the external interrupts are activated and also contain the
external interrupt flags which are set when an external interrupt has occurred.
TMOD (Timer Mode, Addresses 89h): The Timer Mode SFR is used to configure the mode of operation of each of the
two timers. Using this SFR your program may configure each timer to be a 16-bit timer, an 8-bit auto reload timer, a 13-
bit timer, or two separate timers. Additionally, you may configure the timers to only count when an external pin is
activated or to count "events" that are indicated on an external pin.
19
TL0/TH0 (Timer 0 Low/High, Addresses 8Ah/8Ch): These two SFRs, taken together, represent timer 0. Their exact
behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is
configurable is how and when they increment in value.
TL1/TH1 (Timer 1 Low/High, Addresses 8Bh/8Dh): These two SFRs, taken together, represent timer 1. Their exact
behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is
configurable is how and when they increment in value.
P1 (Port 1, Address 90h, Bit-Addressable): This is input/output port 1. Each bit of this SFR corresponds to one of the
pins on the microcontroller. For example, bit 0 of port 1 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this
SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level.
SCON (Serial Control, Addresses 98h, Bit-Addressable): The Serial Control SFR is used to configure the behavior of
the 8051's on-board serial port. This SFR controls the baud rate of the serial port, whether the serial port is activated to
receive data, and also contains flags that are set when a byte is successfully sent or received.
Programming Tip: To use the 8051's on-board serial port, it is generally necessary to initialize the following SFRs:
SCON, TCON, and TMOD. This is because SCON controls the serial port. However, in most cases the program will wish
to use one of the timers to establish the serial port's baud rate. In this case, it is necessary to configure timer 1 by
initializing TCON and TMOD.
SBUF (Serial Control, Addresses 99h): The Serial Buffer SFR is used to send and receive data via the on-board serial
port. Any value written to SBUF will be sent out the serial port's TXD pin. Likewise, any value which the 8051 receives
via the serial port's RXD pin will be delivered to the user program via SBUF. In other words, SBUF serves as the output
port when written to and as an input port when read from.
P2 (Port 2, Address A0h, Bit-Addressable): This is input/output port 2. Each bit of this SFR corresponds to one of the
pins on the microcontroller. For example, bit 0 of port 2 is pin P2.0, bit 7 is pin P2.7. Writing a value of 1 to a bit of this
SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level.
Programming Tip: While the 8051 has four I/O port (P0, P1, P2, and P3), if your hardware uses external RAM or
external code memory (i.e., your program is stored in an external ROM or EPROM chip or if you are using external RAM
chips) you may not use P0 or P2. This is because the 8051 uses ports P0 and P2 to address the external memory. Thus if
you are using external RAM or code memory you may only use ports P1 and P3 for your own use.
IE (Interrupt Enable, Addresses A8h): The Interrupt Enable SFR is used to enable and disable specific interrupts. The
low 7 bits of the SFR are used to enable/disable the specific interrupts, where as the highest bit is used to enable or disable
ALL interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled regardless of whether an individual interrupt is
enabled by setting a lower bit.
P3 (Port 3, Address B0h, Bit-Addressable): This is input/output port 3. Each bit of this SFR corresponds to one of the
pins on the microcontroller. For example, bit 0 of port 3 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this
SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level.
20
IP (Interrupt Priority, Addresses B8h, Bit-Addressable): The Interrupt Priority SFR is used to specify the relative
priority of each interrupt. On the 8051, an interrupt may either be of low (0) priority or high (1) priority. An interrupt may
only interrupt interrupts of lower priority.
PSW (Program Status Word, Addresses D0h, Bit-Addressable): The Program Status Word is used to store a number
of important bits that are set and cleared by 8051 instructions. The PSW SFR contains the carry flag, the auxiliary carry
flag, the overflow flag, and the parity flag. Additionally, the PSW register contains the register bank select flags which are
used to select which of the "R" register banks are currently selected.
Programming Tip: If you write an interrupt handler routine, it is a very good idea to always save the PSW SFR on the
stack and restore it when your interrupt is complete. Many 8051 instructions modify the bits of PSW. If your interrupt
routine does not guarantee that PSW is the same upon exit as it was upon entry, your program is bound to behave rather
erradically and unpredictably--and it will be tricky to debug since the behavior will tend not to make any sense.
ACC (Accumulator, Addresses E0h, Bit-Addressable): The Accumulator is one of the most-used SFRs on the 8051
since it is involved in so many instructions. The Accumulator resides as an SFR at E0h, which means the instruction
MOV A,#20h is really the same as MOV E0h,#20h. However, it is a good idea to use the first method since it only
requires two bytes whereas the second option requires three bytes.
B (B Register, Addresses F0h, Bit-Addressable): The "B" register is used in two instructions: the multiply and divide
operations. The B register is also commonly used by programmers as an auxiliary register to temporarily store values.
21
3. SERIAL COMMUNICATION IN 8051
When a microprocessor communicates with the outside world, it provides data in byte sized chunks. In some cases, such
as printers, the information is simply grabbed from the 8 bit data bus and presented to the 8 bit data bus of the printer.
This can work only if the cable is not too long, since long cables diminish and even distort signals. Furthermore an 8 bit
data path is expensive. For these reasons, serial communication is used for transferring data between two systems located
at distance of hundreds of feet to millions of miles apart.
The fact that serial communication uses a single data line instead of the 8 bit data line of parallel communication not
only makes it cheaper but also enables two computers located at different cities to communicate over the telephone.
For SERIAL DATA COMMUNICATION to work the byte of data must be converted to parallel in serial out shift
register; then it can be transmitted over a single data line. This allows us to have a serial in parallel out shift register at the
receiving end to pack them into byte.
Serial data communication uses two methods, asynchronous and synchronous. The synchronous method transfers a block
of data (characters) at a time, while the asynchronous method transfers a single byte at a time. It is possible to write
software to use either of these methods, but the method can be tedious and long. For this reason, there are special IC
chips made by many manufacturers for serial communication of data. These chips are commonly referred to as UART
(universal asynchronous receiver transmitter) and USART (universal synchronous- asynchronous receiver transmitter).
One of the 8051s many powerful features is its integrated UART, otherwise known as a serial port. The fact that the 8051
has an integrated serial port means that you may very easily read and write values to the serial port. If it were not for the
integrated serial port, writing a byte to a serial line would be a rather tedious process requiring turning on and off one of
the I/O lines in rapid succession to properly "clock out" each individual bit, including start bits, stop bits, and parity bits.
However, we do not have to do this. Instead, we simply need to configure the serial ports operation mode and baud rate.
Once configured, all we have to do is write to an SFR to write a value to the serial port or read the same SFR to read a
value from the serial port. The 8051 will automatically let us know when it has finished sending the character we wrote
and will also let us know whenever it has received a byte so that we can process it. We do not have to worry about
transmission at the bit level--which saves us quite a bit of coding and processing time.
22
3.1 SETTING THE SERIAL PORT MODE
The first thing we must do when using the 8051s integrated serial port is, obviously, configure it. This lets us tell the 8051
how many data bits we want, the baud rate we will be using, and how the baud rate will be determined. First, let’s present
the "Serial Control" (SCON) SFR and define what each bit of the SFR represents:
Bit Name Bit Address Explanation of Function
7 SM0 9Fh Serial port mode bit 0
6 SM1 9Eh Serial port mode bit 1.
5 SM2 9Dh Multiprocessor Communications Enable (explained later)
4 REN 9Ch Receiver Enable. This bit must be set in order to receive characters.
3 TB8 9Bh Transmit bit 8. The 9th bit to transmit in mode 2 and 3.
2 RB8 9Ah Receive bit 8. The 9th bit received in mode 2 and 3.
1 TI 99h Transmit Flag. Set when a byte has been completely transmitted.
0 RI 98h Receive Flag. Set when a byte has been completely received.
Additionally, it is necessary to define the function of SM0 and SM1 by an additional table:
SM0 SM1 Serial Mode Explanation Baud Rate
0 0 0 8-bit Shift Register Oscillator / 12
0 1 1 8-bit UART Set by Timer 1 (*)
1 0 2 9-bit UART Oscillator / 64 (*)
1 1 3 9-bit UART Set by Timer 1 (*)
(*) Note: The baud rate indicated in this table is doubled if PCON.7 (SMOD) is set.
The SCON SFR allows us to configure the Serial Port. Thus, well go through each bit and review its function.
The first four bits (bits 4 through 7) are configuration bits.
Bits SM0 and SM1 let us set the serial mode to a value between 0 and 3, inclusive. The four modes are defined in the
chart immediately above. As you can see, selecting the Serial Mode selects the mode of operation (8-bit/9-bit, UART or
Shift Register) and also determines how the baud rate will be calculated. In modes 0 and 2 the baud rate is fixed based on
the oscillator’s frequency. In modes 1 and 3 the baud rate is variable based on how often Timer 1 overflows. Well talk
more about the various Serial Modes in a moment.
The next bit, SM2, is a flag for "Multiprocessor communication." Generally, whenever a byte has been received the 8051
will set the "RI" (Receive Interrupt) flag. This lets the program know that a byte has been received and that it needs to be
processed. However, when SM2 is set the "RI" flag will only be triggered if the 9th bit received was a "1". That is to say,
if SM2 is set and a byte is received whose 9th bit is clear, the RI flag will never be set. This can be useful in certain
advanced serial applications. For now it is safe to say that you will almost always want to clear this bit so that the flag is
set upon reception of any character.
The next bit, REN, is "Receiver Enable." This bit is very straightforward: If you want to receive data via the serial port,
set this bit. You will almost always want to set this bit.
The last four bits (bits 0 through 3) are operational bits. They are used when actually sending and receiving data--they are
not used to configure the serial port.
23
The TB8 bit is used in modes 2 and 3. In modes 2 and 3, a total of nine data bits are transmitted. The first 8 data bits are
the 8 bits of the main value, and the ninth bit is taken from TB8. If TB8 is set and a value is written to the serial port, the
datas bits will be written to the serial line followed by a "set" ninth bit. If TB8 is clear the ninth bit will be "clear."
The RB8 also operates in modes 2 and 3 and functions essentially the same way as TB8, but on the reception side. When a
byte is received in modes 2 or 3, a total of nine bits are received. In this case, the first eight bits received are the data of
the serial byte received and the value of the ninth bit received will be placed in RB8.
TI means "Transmit Interrupt." When a program writes a value to the serial port, a certain amount of time will pass before
the individual bits of the byte are "clocked out" the serial port. If the program were to write another byte to the serial port
before the first byte was completely output, the data being sent would be garbled. Thus, the 8051 lets the program know
that it has "clocked out" the last byte by setting the TI bit. When the TI bit is set, the program may assume that the serial
port is "free" and ready to send the next byte.
Finally, the RI bit means "Receive Interrupt." It functions similarly to the "TI" bit, but it indicates that a byte has been
received. That is to say, whenever the 8051 has received a complete byte it will trigger the RI bit to let the program know
that it needs to read the value quickly, before another byte is read.
The rate of data transfer in serial communication is stated in bps (bits per second). Another widely used terminology for
bps is BAUD RATE. However, the baud and bps rates are not necessarily equal. This is due to the fact that baud rate is the
modern terminology and is defined as the number of signal changes per second. In modems a single change of signal,
sometimes transfers several bits of data. As far as conductor wire is concerned, the baud rate and bps are the same.
24
TH1 = 256 - ((Crystal / 192) / Baud)
Here we are able to calculate a nice, even TH1 value. Therefore, to obtain 19,200 baud with an 11.059MHz crystal we
must:
1. Configure Serial Port mode 1 or 3.
2. Configure Timer 1 to timer mode 2 (8-bit auto-reload).
3. Set TH1 to 253 to reflect the correct frequency for 19,200 baud.
4. Set PCON.7 (SMOD) to double the baud rate.
25
3.5 READING THE SERIAL PORT
Reading data received by the serial port is equally easy. To read a byte from the serial port one just needs to read the value
stored in the SBUF (99h) SFR after the 8051 has automatically set the RI flag in SCON.
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:
JNB RI, $; Wait for the 8051 to set the RI flag
MOV A, SBUF; Read the character from the serial port
The first line of the above code segment waits for the 8051 to set the RI flag; again, the 8051 sets the RI flag
automatically when it receives a character via the serial port. So as long as the bit is not set the program repeats the "JNB"
instruction continuously.
Once the RI bit is set upon character reception the above condition automatically fails and program flow falls through to
the "MOV" instruction which reads the value.
Programming Tip: If you write a program that utilizes new SFRs that are specific to a given derivative chip and not
included in the above SFR list, your program will not run properly on a standard 8051 where that SFR does not exist.
Thus, only use non-standard SFRs if you are sure that your program will only have to run on that specific microcontroller.
Likewise, if you write code that uses non-standard SFRs and subsequently share it with a third-party, be sure to let that
party know that your code is using non-standard SFRs to save them the headache of realizing that due to strange behavior
at run-time.
26
3.6 WORKING IN SERIAL COMMUNICATION MODE
When proper connection between PC and microcontroller is established, the following signal transitions takes place
between PC and microcontroller-
Devices undergo POST.
Then PC sets DTR (data terminal ready) while modem sets DSR (data set ready).
For transmitting data pc sends RTS (request to send) high and if modem is free it sends CTS (clear to send).
Then PC starts transmitting bit by bit. At end modem sends DCD (data carrier detects).
27
3.6.2 PINOUTS
The following table lists commonly-used RS-232 signals and pin assignments.
DB-25
Signal Origin
pin
Name Typical purpose Abbreviation DTE DCE
Data Terminal
OOB control signal: Tells DCE that DTE is ready to be connected. DTR ● 20
Ready
Data Carrier OOB control signal: Tells DTE that DCE is connected to telephone
DCD ● 8
Detect line.
OOB control signal: Tells DTE that DCE is ready to receive
Data Set Ready DSR ● 6
commands or data.
OOB control signal: Tells DTE that DCE has detected a ring signal
Ring Indicator RI ● 22
on the telephone line.
OOB control signal: Tells DCE to prepare to accept data from
Request To Send RTS ● 4
DTE.
OOB control signal: Acknowledges RTS and allows DTE to
Clear To Send CTS ● 5
transmit.
Transmitted Data Data signal: Carries data from DTE to DCE. TxD ● 2
Received Data Data signal: Carries data from DCE to DTE. RxD ● 3
Common Ground GND common 7
Protective Ground PG common 1
The signals are named from the standpoint of the DTE. The ground signal is a common return for the other connections.
The DB-25 connector includes a second "protective ground" on pin 1. Connecting this to pin 7 (signal reference ground) is
a common practice but not essential.
3.6.3 UART
A universal asynchronous receiver/transmitter (usually abbreviated UART) is a type of "asynchronous
receiver/transmitter", a piece of computer hardware that translates data between parallel and serial forms. UARTs are
commonly used in conjunction with communication standards such as EIA RS-232, RS-422 or RS-485. The universal
designation indicates that the data format and transmission speeds are configurable and that the actual electric signaling
levels and methods (such as differential signaling etc) typically are handled by a special driver circuit external to the
UART.
A UART is usually an individual (or part of an) integrated circuit used for serial communications over a computer or
peripheral device serial port. UARTs are now commonly included in microcontrollers. A dual UART, or DUART,
combines two UARTs into a single chip. Many modern ICs now come with a UART that can also communicate
synchronously; these devices are called USARTs (universal synchronous/asynchronous receiver/transmitter).
4. IN SYSTEM PROGRAMMING
28
The IC used is a product of Philips p89lv51rd2. Philips P89LV51RD2 microcontroller has an on-chip Flash program
memory with ISP
(In-System Programming), which allows the microcontroller to be programmed without removing the microcontroller
from the board and also the microcontroller, which previously programmed can be reprogrammed without removal from
the board.
The microcontroller must be powered up in a special ’ISP mode’ to perform the ISP operation. The ISP mode allows the
microcontroller to communicate with a host device such as PC through a serial port. The host sends command and data to
the microcontroller. The commands can be erase, read, and write.
After the completion of the ISP operation, the microcontroller is reconfigured and has to be reset or power cycled so the
microcontroller will operate normally.
The ISP programming for the device can be done using Windows application software, which uses an Intel Hex file as
input to program it.
5. CIRCUIT DIAGRAM
29
5 1 M IC R O C O N T R O L L E R K IT R C -R e s e t
P S E N _ IS P
+5V
SW 1
+5V
+5V
+5V P o r t0 S W T A C T -S P S T
8
7
6
5
4
3
2
1
9
8
7
6
5
4
3
2
8
7
6
5
4
3
2
1
0 .1 u F 0 .1 u F 1
R3 2
3
40
U1 R eset
1 39 1K LC D _R S 4
LC D _R S P 1 .0 P 0 .0 /A D 0 R o w 0 /A D C _ D 0 LC D _R W 5
2 38
VC C
LC D _R W P 1 .1 P 0 .1 /A D 1 R o w 1 /A D C _ D 1 LC D _EN 6
3 37
LC D _EN P 1 .2 P 0 .2 /A D 2 R o w 2 /A D C _ D 2 LC D _D 0 7
4 36
EEPRO M_SCL P 1 .3 P 0 .3 /A D 3 R o w 3 /A D C _ D 3 LC D _D 1 8
5 35
E E PR O M _D A TA P 1 .4 P 0 .4 /A D 4 C o lo m n 4 / A D C _ D 4 LC D _D 2 9
6 34
L E n b 2 /T e m p _ C lk P 1 .5 P 0 .5 /A D 5 C o lo m n 3 / A D C _ D 5 LC D _D 3 10
7 33
Tem p_D at P 1 .6 P 0 .6 /A D 6 C o lo m n 2 / A D C _ D 6 LC D _D 4 11
8 32
LEnb1 P 1 .7 P 0 .7 /A D 7 C o lo m n 1 / A D C _ D 7 LC D _D 5 12
LC D _D 6 13
9 31 R 18 +5V
R eset RST E A /V P P 3 0 LC D _D 7 14
10
R XD /P 3 .0 A L E /P R O G 2 9 15
89C51
R TC _C LK 11 10K
R TC _D A TA T X D /P 3 .1 PSEN P S E N _ IS P 16
12
R TC _R ST 13 IN T 0 /P 3 .2 28
A D C _ IN TR IN T 1 /P 3 .3 P 2 .7 /A 1 5 D0
14 27
AD C _C S T 0 /P 3 .4 P 2 .6 /A 1 4 D1
15 26
AD C _R D T 1 /P 3 .5 P 2 .5 /A 1 3 D2
16 25
AD C _W R W R /P 3 .6 P 2 .4 /A 1 2 D3
A D C _ IN T R
17
R D /P 3 .7 P 2 .3 /A 1 1
24
23
D4 T e m p a r a tu r e S e n s o r
R XD P 2 .2 /A 1 0 D5
18 22
TXD XTA L2 P 2 .1 /A 9 D6 +5V J4
21
P 2 .0 /A 8 D7
+5V 19 1
XTA L1 D0
SMD_Pack 2
GND
Y1 D1
U6 3
2
3
4
5
6
7
8
9
D2
1 +5V 8 1 4
1
2
3
4
5
6
7
8
Tem p_D at D3
7 VDD SDA 2 5
20
L E n b 2 / T e m p _ C lk
Po rt2
D4
4K7 C1 22.11MHz C2 C20 6 A0 SCL 3 6
D5
C3 S IL 2 5 A1 Tout 4 7
2
3
4
5
6
7
8
9
J13 A2 GND D6
P o r t3 0 .1 u F
22pf 22pf 1 0 .1 u F 8
D7
D S 1631
S IL 4 4K7 8 B it D a t a L in e s
C7
M ic r o C o n tr o lle r 0 .1 u F
+5V
B T1 D1 D2
2 1
1N 4007
3 . 6 V o lt s N iM h B a t R 4 1N 4007
C12
100E 0 .1 u F J5
VC C _12V
C9 1
C10 0 .1 u F 2
+5V +5V
22pf U2 R16 7805 U 10
Y2 1 8 1 3 1 J6
2 NC Vcc 7 I/P O /P 2
GND
R TC _C LK
3 X1 SC LK 6
R TC _R ST
C 11 4 X2 I/O 5 C 24 1k
Vss /R e s t R TC _D A TA
0 .1 u F R 17
2
22pf 1k + 1
H T1380 C27 2 J7
R5
J8
20
32.768KHZ U9 -
Crystal Oscillator 18 6 2 D5 1 0 0 u F /2 5 V
S e r ia l R T C R o w 0 /A D C _ D 0
17 DB0 V I+ 1 +
VC C
R o w 1 /A D C _ D 1 DB1
10 K
16 IN 4 0 0 7 C 28
R o w 2 /A D C _ D 2 DB2 -
15 7 J9
R o w 3 /A D C _ D 3 DB3 V I-
14 1 LED 9
C o lo m n 4 / A D C _ D 4 DB4
13 19 1 0 0 u F /2 5 V
C o lo m n 3 / A D C _ D 5 DB5 C LKR
12 2 Power LED
C o lo m n 2 / A D C _ D 6 DB6 D6
A D C 0804
11 10K R 6 C 26
C o lo m n 1 / A D C _ D 7 DB7
+5V 4
1 CLK 0 .1 u F
AD C _C S
2 CS 9
AD C _R D
3 RD VREF IN 4 0 0 7
AD C _W R
5 WR 8 +5V
GN D
A D C _ IN T R IN TR AGND
C13
0 .1 u F
U3
10
20
3 2 10K R 15
D0 D1 Q1 LC D _D 0
4 5 C 25
VC C
D1 D2 Q2 LC D _D 1
7 6 0 .1 u F
D2 D3 Q3 LC D _D 2
8 9
D3 D4 Q4 LC D _D 3
13 12
D4 D5 Q5 LC D _D 4
14 15
D5
17 D6 Q6 16
LC D _D 5 4 x 4 M a tr ix K e y P a d
D6 D7 Q7 LC D _D 6
18 19
D7 D8 Q8 LC D _D 7
11
LEnb1
1 C LK
GND
OE
Row 1
+5V Row 2
J10 +5V
2
1 C14 C15
+5V Row 3
0 .1 u F 0 .1 u F +5V
U4 C16 1 u F /6 3 v +5V
20
1 u F /6 3 v
U5 C 18
16
3 2 R7 330E L E1 D 1 2
D0 D1 Q1
4 5 R8 330E L E1 D 2 2 1 2 C21
VC C
D1 D2 Q2
7 6 R9 330E L E1 D 3 2 3 C1+ V+ 0 .1 u f C 22
VC C
D2 D3 Q3 C1-
Co lo m n 4
Co lo m n 3
Co lo m n 2
Co lo m n 1
8 9 R10 330E L E1 D 4 2 6 0 .1 u F
D3 D4 Q4 V-
13 12 R11 330E L E1 D 5 2 C 1 7 1 u F /6 3 v 4 C19 J11 C23
D4 D5 Q5
14 15 R12 330E L E1 D 6 2 5 C2+ 1 u F /6 3 v 1 EE P R O M 4 K -0 1 EEP R O M 4K -02 0 .1 u F
D5 D6 Q6 C2-
17 16 R13 330E L E1 D 7 2 6
D6 D7 Q7
18 19 R14 330E L E1 D 8 2 11 14 2 1 8 8 1
D7 D8 Q8 TXD 1 0 T1 IN T1O U T 7 7 2 A0 Vcc 7 7 Vcc A0 2
11 T2 IN T2O U T 3 3 A1 U7 WP 6 6 WP U8 A1 3
1 C LK 12 13 8 4 A2 SCL 5 5 SCL A2 4
GND
R S232
S iz e D ocum ent N um ber R ev 30
15
E E P R O M _D A TA EEPR O M _SC L
DB 9 S C <D oc> <R ev C ode>
D a te : F r id a y , N o v e m b e r 0 3 , 2 0 0 6 Sheet 1 of 1
6. LIST OF IC’s AND COMPONENTS USED
S. No. COMPONENTS
1. Microcontroller IC p89v51rd2
2. Max 232 driver/ RS 232 device
3. Supply Voltage – 7805, 7812 (78XX)
4. DM74LS125A quad 3 state buffer
5. L293D motor driver
6. ULN 2803- 8 darlington array
7. ADC 0804- 1 bit A/D converter
8. LM35 Precision Centigrade temperature Sensor
9. 16*2 LCD display and Keyboard
10. USB to DB 9 Converter
The P89V51RD2 is an 80C51 microcontroller with 64 kB Flash and 1024 bytes of data RAM. A key feature of the
P89LV51RD2 is its X2 mode option. The design engineer can choose to run the application with the conventional 80C51
clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per machine cycle) to achieve twice the
throughput at the same clock frequency. Another way to benefit from this feature is to keep the same performance by
reducing the clock frequency by half, thus dramatically reducing the EMI.
The Flash program memory supports both parallel programming and in serial In-System Programming (ISP). Parallel
programming mode offers gang-programming at high speed, reducing programming costs and time to market. ISP allows
a device to be reprogrammed in the end product under software control. The capability to field/update the application
firmware makes a wide range of applications possible.
The P89LV51RD2 is also In-Application Programmable (IAP), allowing the Flash program memory to be reconfigured
even while the application is running.
31
7.1.2 FEATURES
RS-232 devices may be classified as Data Terminal Equipment (DTE) or Data Communication Equipment (DCE); this
defines at each device which wires will be sending and receiving each signal. The standard recommended but did not
make mandatory the D-subminiature 25 pin connector. In general and according to the standard, terminals and computers
have male connectors with DTE pin functions, and modems have female connectors with DCE pin functions. Other
devices may have any combination of connector gender and pin definitions. Many terminals were manufactured with
female terminals but were sold with a cable with male connectors at each end; the terminal with its cable satisfied the
recommendations in the standard.
Presence of a 25 pin D-sub connector does not necessarily indicate an RS-232-C compliant interface. For example, on the
original IBM PC, a male D-sub was an RS-232-C DTE port (with a non-standard current loop interface on reserved pins),
32
but the female D-sub connector was used for a parallel Centronics printer port. Some personal computers put non-standard
voltages or signals on some pins of their serial ports.
The standard specifies 20 different signal connections. Since most devices use only a few signals, smaller connectors can
often be used.
The following table lists commonly-used RS-232 signals and pin assignments. [7] For variations see Serial port.
DB-25
Signal Origin
pin
Name Typical purpose Abbreviation DTE DCE
Data Terminal
OOB control signal: Tells DCE that DTE is ready to be connected. DTR ● 20
Ready
Data Carrier OOB control signal: Tells DTE that DCE is connected to telephone
DCD ● 8
Detect line.
OOB control signal: Tells DTE that DCE is ready to receive
Data Set Ready DSR ● 6
commands or data.
OOB control signal: Tells DTE that DCE has detected a ring signal
Ring Indicator RI ● 22
on the telephone line.
OOB control signal: Tells DCE to prepare to accept data from
Request To Send RTS ● 4
DTE.
OOB control signal: Acknowledges RTS and allows DTE to
Clear To Send CTS ● 5
transmit.
Transmitted Data Data signal: Carries data from DTE to DCE. TxD ● 2
Received Data Data signal: Carries data from DCE to DTE. RxD ● 3
Common Ground GND common 7
Protective Ground PG common 1
The signals are named from the standpoint of the DTE. The ground signal is a common return for the other connections.
The DB-25 connector includes a second "protective ground" on pin 1. Connecting this to pin 7 (signal reference ground) is
a common practice but not essential.
Data can be sent over a secondary channel (when implemented by the DTE and DCE devices), which is equivalent to the
primary channel. Pin assignments are described in following table:
Signal Pin
Common Ground 7
Secondary Transmitted Data (STD) 14
Secondary Received Data (SRD) 16
Secondary Request To Send (SRTS) 19
Secondary Clear To Send (SCTS) 13
Secondary Carrier Detect (SDCD) 12
7.2.1 CABLES
The standard does not define a maximum cable length but instead defines the maximum capacitance that a compliant
drive circuit must tolerate. A widely-used rule-of-thumb indicates that cables more than 50 feet (15 meters) long will have
33
too much capacitance, unless special cables are used. By using low-capacitance cables, full speed communication can be
maintained over larger distances up to about 1,000 feet. For longer distances, other signal standards are better suited to
maintain high speed.
Since the standard definitions are not always correctly applied, it is often necessary to consult documentation, test
connections with a breakout box, or use trial and error to find a cable that works when interconnecting two devices.
Connecting a fully-standard-compliant DCE device and DTE device would use a cable that connects identical pin
numbers in each connector (a so-called "straight cable"). "Gender changers" are available to solve gender mismatches
between cables and connectors. Connecting devices with different types of connectors requires a cable that connects the
corresponding pins according to the table above. Cables with 9 pins on one end and 25 on the other are common.
Manufacturers of equipment with 8P8C connectors usually provide a cable with either a DB-25 or DE-9 connector (or
sometimes interchangeable connectors so they can work with multiple devices). Poor-quality cables can cause false
signals by crosstalk between data and control lines (such as Ring Indicator). If a given cable will not allow a data
connection, especially if a Gender changer is in use, a Null modem may be necessary.
7.2.2 3 WIRE AND 5 WIRE RS 232
A minimal “3-wire” RS-232 connection consisting only of transmits data, receives data and ground, and is commonly
used when the full facilities of RS-232 are not required. Even a two-wire connection (data and ground) can be used if the
data flow is one way (for example, a digital postal scale that periodically sends a weight reading, or a GPS receiver that
periodically sends position, if no configuration via RS-232 is necessary). When only hardware flow control is required in
addition to two-way data, the RTS and CTS lines are added in a 5-wire version.
7.2.3 CONVENTIONS
For functional communication through a serial port interface, conventions of bit rate, character framing, communications
protocol, character encoding, data compression, and error detection, not defined in RS 232, must be agreed to by both
sending and receiving equipment. This implementation used an 8250 UART using asynchronous start-stop character
formatting with 7 or 8 data bits per frame, usually ASCII character coding, and data rates programmable between 75 bits
per second and 115,200 bits per second. Data rates above 20,000 bits per second are out of the scope of the standard,
although higher data rates are sometimes used by commercially manufactured equipment.
34
7.2.4 DEVELOPMENT TOOLS – MAX 232
The LM78XX series of three terminal regulators is available with several fixed output voltages making them useful in a
wide range of applications. One of these is local on card regulation, eliminating the distribution problems associated with
single point regulation. The voltages available allow these regulators to be used in logic systems, instrumentation, Hi Fi,
and other solid state electronic equipment. Although designed primarily as fixed voltage regulators these devices can be
used with external components to obtain adjustable
voltages and currents. The LM78XX series is available in an aluminum To-3 package which will allow over 1.0A load
current if adequate heat
sinking is provided. Current limiting is included to limit the peak output current to a safe value. Safe area protection for
the output transistor is provided to limit internal power dissipation. If internal power dissipation becomes too high for the
heat sinking provided, the thermal shutdown circuit takes over preventing the IC from overheating. Considerable effort
was expanded to make the LM78XX series of regulators easy to use and minimize the number of external components. It
is not necessary to bypass the output, although this does improve transient response. Input bypassing is needed only if the
regulator is located far from the
filter capacitor of the power supply.
For output voltage other than 5V, 12V and 15V the LM117 series provides an output voltage range from 1.2V to 57V.
35
7.3.2 FEATURES
LM7805C 5V
LM7812C 12V
This device contains four independent gates each of which performs a non-inverting buffer function. The outputs have the
3-STATE feature. When enabled, the outputs exhibit the low impedance characteristics of a standard LS output with
additional drive capability to permit the driving of bus lines without external resistors. When disabled, both the output
transistors are turned off presenting a high-impedance state to the bus line. Thus the output will act neither as a significant
load nor as a driver. To minimize the possibility that two outputs will attempt to take a common bus to opposite logic
levels, the disable time is shorter than the
enable time of the outputs.
36
7.4.2 CONNECTION
37
The 1k resistor (brown / black /red / gold) is inserted in about the only position it can fit into - position ‘R1’. Snug it up
close to the circuit board, bend the leads over, and solder it into place from the other side. When done, clip off the excess
leads.
Your kit comes with a set of five (5, for those who can’t read “five”) conductor ribbon cable. You’ll have to split the ends
apart, and strip off about 1.5mm (1/16”) from each end. Try to arrange your ribbon cable like the one below, as splaying
them apart will make it easier to solder each end to the driver board. For easier soldering, pre-tin the ends of each wire.
Starting with the red wire on the side nearest the pad marked ‘ ’, start soldering them into place, one per pad. We’ll be
using the wire colors for different functions. If possible, solder the wires down on top of the pad – not through. The metal
motor case underneath can (and will!) short out leads that poke through the PCB. If you have to use the holes, When done,
drop the wired PCB into the servo, on top of the motor tabs. Solder the motor tabs to the PCB, and you’re ready to close it
up! trim the excess lead off flush with the bottom of the PCB. If you want to use your motor driver on a breadboard, skip
ahead to “Option 3”.
When done, drop the wired PCB into the servo, on top of the motor tabs. Solder the motor tabs to the PCB, and you’re
ready to close it up!
Step 5: Closing it up
No rocket science here - simply put the servo bottom plate back in place, insert the corner screws, and tighten them down.
Be careful to fold over a few of the edge ribbon wires, as it’ll be too wide to fit the slot that originally fit three. Or hey - be
a rebel and use a knife (or other favourite tool of destruction) and widen the slot so all five wires lay flat.
38
7.5.1 FEATURES
L293D motor driver- for applications where space is tight, and power needs are great! Sneak this module inside a servo
for more power and flexibility for your robot designs.
It’s Powerful: Configured with LED direction indicators, able to deliver 1.2 A of current (2.4A surge) and 36 volts supply
power, this module has more than enough ability to turn your ‘hobby’ servo or gear motor into a real workhorse!
It’s Breadboard Friendly: And if a stealthy install doesn’t interest you, add seven pins to the option pads, and you have a
power driver module you can use on a breadboard. The ‘Secret’ L293D motor driver is a perfect match for the Solarbotics
GM4 gear motor. With the transparent motor case, you can monitor the driver’s indicator LEDs!
7.6 ULN2803
7.6.1 FEATURES
7.6.2DESCRIPTION
The ULN2801A-ULN2805A each contain eight darlington transistors with common emitters and integral suppression
diodes for inductive loads. Each darlington features a peak load current rating of 600mA (500mA continuous) and can
withstand at least 50V in the off state. Outputs may be paralleled for higher current capability. Five versions are available
to simplify interfacing to standard logic families: the ULN2801A is designed for general purpose applications with a
current limit resistor ; the ULN2802A has a 10.5kW input resistor and zener for 14-25V PMOS ; the ULN2803A has a
2.7kW input resistor for 5V TTL and CMOS ; the ULN2804A has a 10.5kW input resistor for 6-15V CMOS and the
ULN2805A is designed to sink a minimum of 350mA for standard and Schottky TTL where higher output current is
required. All types are supplied in a 18-lead plastic DIP with a copper lead from and feature the convenient input
opposite- output pin out to simplify board layout.
39
7.6.3 PIN DIAGRAM
Analog to digital converters find huge application as an intermediate device to convert the signals from analog to digital
form. These digital signals are used for further processing by the digital processors. Various sensors like temperature,
pressure, force etc. convert the physical characteristics into electrical signals that are analog in nature.
ADC0804 is a very commonly used 8-bit analog to digital convertor. It is a single channel IC, i.e., it can take only one
analog signal as input. The digital outputs vary from 0 to a maximum of 255. The step size can be adjusted by setting the
reference voltage at pin9. When this pin is not connected, the default reference voltage is the operating voltage, i.e., Vcc.
The step size at 5V is 19.53mV (5V/255), i.e., for every 19.53mV rise in the analog input, the output varies by 1 unit. To
set a particular voltage level as the reference value, this pin is connected to half the voltage. For example, to set a
reference of 4V (Vref), pin9 is connected to 2V (Vref/2), thereby reducing the step size to 15.62mV (4V/255).
ADC0804 needs a clock to operate. The time taken to convert the analog value to digital value is dependent on this clock
source. An external clock can be given at the Clock IN pin. ADC 0804 also has an inbuilt clock which can be used in
40
absence of external clock. A suitable RC circuit is connected between the Clock IN and Clock R pins to use the internal
clock.
7.7.2 FEATURES
Compatible with 8080 µP derivatives-no interfacing logic needed - access time - 135 ns
Easy interface to all microprocessors, or operates "stand alone"
Differential analog voltage inputs
Logic inputs and outputs meet both MOS and TTL voltage level specifications
Works with 2.5V (LM336) voltage reference
On-chip clock generator
0V to 5V analog input voltage range with single 5V supply
No zero adjust required
0.3[Prime] standard width 20-pin DIP package
20-pin molded chip carrier or small outline package
Operates ratiometrically or with 5 VDC, 2.5 VDC, or analog span adjusted voltage reference
7.7.3 KEY SPECIFICATION
Key Specification
Resolution 8 bits
Total error ±¼ LSB, ±½ LSB and ±1 LSB
Conversion time 100 µs
41
7.7.4 BLOCK DIAGRAM AND PIN CONNECTIONS.
The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the
Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin,
as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The
LM35 does not require any external calibration or trimming to provide typical accuracies of ±¼°C at room temperature
and ±¾°C over a full -55 to +150°C temperature range. Low cost is assured by trimming and calibration at the wafer
level. The LM35's low output impedance, linear output, and precise inherent calibration make interfacing to readout or
42
control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws
only 60 µA from its supply, it has very low self-heating, less than 0.1°C in still air. The LM35 is rated to operate over a
-55° to +150°C temperature range, while the LM35C is rated for a -40° to +110°C range (-10° with improved accuracy).
The LM35 series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and LM35D
are also available in the plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface mount small
outline package and a plastic TO-220 package.
7.8.2 FEATURES
7.8.3 PIN
43
7.9 16*2 LCD DISPLAY
An LCD is a small low cost display. It is easy to interface with a micro-controller because of an embedded controller (the
black blob on the back of the board).
This controller is standard across many displays (HD 44780) which means many micro-controllers (including the
Arduino) have libraries that make displaying messages as easy as a single line of code.
7.9.1 TESTING
Testing your LCD with an Arduino is really simple. Wire up your display using the schematic or breadboard layout sheet.
Then open the Arduino IDE and open the example program.
File > Sketchbook > Examples > Library-LiquidCrystal > HelloWorld
Upload to your board and watch as "hello, world!" is shown on your display. If no message is displayed the contrast may
need to be adjusted. To do this turn the potentiometer.
Liquid Crystal(rs, rw, enable, d4, d5, d6, d7) - create a new
Liquid Crystal object using a 4 bit data bus
Liquid Crystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) - create
a new Liquid Crystal object using an 8 bit data bus
clear() - Clears the display and moves the cursor to upper left corner
home() - Moves the cursor to the upper left corner
set Cursor (col, row) - moves the cursor to column and row write (data) - writes the char data to the display
print (data) - prints a string to the display
44
7.9.3 THE CIRCUIT
45
8 INTERFACING
1. Digital
2. Analog
Digital Inputs/Outputs
On/OFF control and monitoring.
Digital Input Example: Reading the status of buttons or switches (Keypad Interface)
123A
4 Advantages * 0 # D
46
· Simplest interface.
· Lowest-cost to implement (built into the microcontroller).
· High speed.
· Low programming overhead.
Disadvantages
· Only on/off control/monitoring.
· Short distance, few feet maximum.
· Single device control/monitoring.
The key board here we are interfacing is a matrix keyboard. This key board is designed with a particular rows and
columns. These rows and columns are connected to the microcontroller through its ports of the micro controller 8051. We
normally use 8*8 matrix key board. So only two ports of 8051 can be easily connected to the rows and columns of the key
board.
Whenever a key is pressed, a row and a column gets shorted through that pressed key and all the other keys are left
open. When a key is pressed only a bit in the port goes high. Which indicates microcontroller that the key is pressed. By
this high on the bit key in the corresponding column is identified.
Once we are sure that one of key in the key board is pressed next our aim is to identify that key. To do this we
firstly check for particular row and then we check the corresponding column the key board.
To check the row of the pressed key in the keyboard, one of the row is made high by making one of bit in the output
port of 8051 high . This is done until the row is found out. Once we get the row next out job is to find out the column of
the pressed key. The column is detected by contents in the input ports with the help of a counter. The content of the input
port is rotated with carry until the carry bit is set.
The contents of the counter is then compared and displayed in the display. This display is designed using a seven
segment display and a BCD to seven segment decoder IC 7447.
The BCD equivalent number of counter is sent through output part of 8051 displays the number of pressed key.
47
INTERFACING OF KEY BOARD TO 8051.
Keyboard is organized in a matrix of rows and columns as shown in the figure. The microcontroller accesses both rows
and columns through the port.
1. The 8051 has 4 I/O ports P0 to P3 each with 8 I/O pins, P0.0 to P0.7,P1.0 to P1.7, P2.0 to P2.7, P3.0 to
P3.7. The one of the port P1 (it understood that P1 means P1.0 to P1.7) as an I/P port for microcontroller
8051, port P0 as an O/P port of microcontroller 8051 and port P2 is used for displaying the number of
pressed key.
2. Make all rows of port P0 high so that it gives high signal when key is pressed.
3. See if any key is pressed by scanning the port P1 by checking all columns for non zero condition.
4. If any key is pressed, to identify which key is pressed make one row high at a time.
5. Initiate a counter to hold the count so that each key is counted.
6. Check port P1 for nonzero condition. If any nonzero number is there in [accumulator], start column
scanning by following step 9.
7. Otherwise make next row high in port P1.
8. Add a count of 08h to the counter to move to the next row by repeating steps from step 6.
9. If any key pressed is found, the [accumulator] content is rotated right through the carry until carry bit
sets, while doing this increment the count in the counter till carry is found.
10. Move the content in the counter to display in data field or to memory location
11. To repeat the procedures go to step 2.
Program to interface matrix keyboard to microcontroller 8051
Start of main program:
to check that whether any key is pressed
start: mov a,#00h
mov p1,a ;making all rows of port p1 zero
mov a,#0fh
mov p1,a ;making all rows of port p1 high
48
press: mov a,p2
jz press ;check until any key is pressed
after making sure that any key is pressed
mov a,#01h ;make one row high at a time
mov r4,a
mov r3,#00h ;initiating counter
next: mov a,r4
mov p1,a ;making one row high at a time
mov a,p2 ;taking input from port A
jnz colscan ;after getting the row jump to check
column
mov a,r4
rl a ;rotate left to check next row
mov r4,a
mov a,r3
add a,#08h ;increment counter by 08 count
mov r3,a
sjmp next ;jump to check next row
after identifying the row to check the colomn following steps are followed
colscan: mov r5,#00h
in: rrc a ;rotate right with carry until get the carry
jc out ;jump on getting carry
inc r3 ;increment one count
jmp in
out: mov a,r3
da a ;decimal adjust the contents of counter
before display
mov p2,a
jmp start ;repeat for check next key.
49
8.1.2 LED INTERFACING (Digital Output Interfacing)
When learning microcontroller the first program that everyone tries is Turning ON a LED or Flashing a LED.
Here I will be explaining how to interface a LED to a Microcontroller & a sample code for LED flashing.
The adjoining figure shows how to interface the LED to 8051 microcontroller. As you can see the Anode is connected
through a resistor to Vcc & the Cathode is connected to the Microcontroller pin. So when the Port Pin is HIGH the LED is
OFF & when the Port Pin is LOW the LED is turned ON.
You may ask why we can’t connect Anode to the Port Pin and cathode to the Ground. The answer is simple,
8051 has an internal pull-up resistor of 10kΩ. So now when the port Pin is HIGH the Anode is positive with respect to the
Cathode so the LED should turn ON right? But the internal pull-up resistor comes in series with the resistor thus limiting
the current flowing through the LED. This current is not sufficient enough to Turn ON the LED.
Flashing LED ALGORITHM
1. Start.
2. Turn ON LED.
3. Turn OFF LED.
4. GO TO 2.
We now want to flash a LED. It works by turning ON a LED & then turning it OFF & then looping back to START.
However the operating speed of microcontroller is very high so the flashing frequency will also be very fast to be detected
by human eye.
Modified Flashing LED ALGORITHM
1. Start.
2. Turn ON LED.
50
3. Wait for some time (delay).
4. Turn OFF LED.
5. Wait for some time (delay).
6. Go To 2.
You can see in the modified algorithm that after turning ON the LED the controller waits for the delay period & then turns
OFF the led & again waits for the delay period & then goes back to the start.
PROGRAM 1
1. ORG 0000h
2. loop:
3. CLR P2.0 //Turn ON LED
4. CALL DELAY
5. SETB P2.0 //Turn OFF LED
6. CALL DELAY
7. JMP loop
In the above program LED is connected to P2.0. The above program can also be written as follows.
PROGRAM 2
1. ORG 0000h
2. loop:
3. CPL P2.0 //Compliment Port Pin
4. CALL DELAY
5. JMP loop
The only drawback of the second program is that the LED's ON time will be equal to LED's OFF time. Whereas in the
first program if different delay routines are called the LED's ON time can be different than that of LED's OFF time.
8.1.3 INTERFACING ANALOG TO DIGITAL CONVERTERS (ADC 0804)
51
As shown in the typica circuit, ADC0804 can be interfaced with any microcontroller. You need a minimum of 11 pins to
interface ADC0804, eight for data pins and 3 for control pins. As shown in the typical circuit the chip select pin can be
made low if you are not using the microcontroller port for any other peripheral (multiplexing).
There is a universal rule to find out how to use an IC. All you need is the datasheet of the IC you are working with and
take a look at the timing diagram of the IC which shows how to send the data, which signal to assert and at what time the
signal should be made high or low etc.
Note: Keep this in mind that whenever you are working with an IC and you want to know how to communicate with that
IC, then simply look into the timing diagram of that IC from its datasheet. It gives you complete information that you need
regarding the communication of IC.
52
The above timing diagrams are from ADC0804 datasheet. The first diagram (FIGURE 10A) shows how to start a
conversion. Also you can see which signals are to be asserted and at what time to start a conversion. So looking into the
timingdiagram FIGURE 10A. We note down the steps or say the order in which signals are to be asserted to start a
conversion of ADC. As we have decided to make Chipselect pin as low so we need not to bother about the CS signal in
the timing diagram. Below steps are for starting an ADC conversion. I am also including CS signal to give you a clear
picture. While programming we will not use this signal.
1. Make chip select (CS) signal low.
2. Make write (WR) signal low.
3. Make chip select (CS) high.
4. Wait for INTR pin to go low (means conversion ends).
Once the conversion in ADC is done, the data is available in the output latch of the ADC. Looking at the FIGURE 10B
which shows the timing diagram of how to read the converted value from the output latch of the ADC. Data of the new
conversion is only available for reading after ADC0804 made INTR pin low or say when the conversion is over. Below
are the steps to read output from the ADC0804.
1. Make chip select (CS) pin low.
2. Make read (RD) signal low.
3. Read the data from port where ADC is connected.
4. Make read (RD) signal high.
5. Make chip select (CS) high.
8051 Assembly Programming for ADC 0804
rd equ P1.0 ;Read signal P1.0
wr equ P1.1 ;Write signal P1.1
cs equ P1.2 ;Chip Select P1.2
intr equ P1.3 ;INTR signal P1.3
org 0H
start: ;Start of Program
acall conv ;Start ADC conversion
acall read ;Read converted value
53
mov P3,adc_val ;Move the value to Port 3
sjmp start ;Do it again
54
8.1.4 INTERFACING LM35 AND DISPLAY THE RESULT USING 7
SEGMENT DISPLAY
Convert ADC value to temperature
Display temperature into 7 segment display
;==================================================
====================
; Global variables
;======================================================================
SEVENSEGMENT EQU P0
K1 EQU P1.0
K2 EQU P1.1
INCSWITCH EQU P1.2
DECSWITCH EQU P1.3
BUZZER EQU P1.4
ADC_RD EQU P3.0
ADC_WR EQU P3.1
ADC_INTR EQU P3.2
FAN EQU P3.3
DisplayTemp:
mov DPTR,#Tens ;use lookup table to show tens
MOv A,R3 ;get value from ADC
Movc A,@A+DPTR ;compare value in lookup table
mov R4,A ;collect data for checkspeed
Mov DPTR,#Decoder7Segment ;use lookup table
Movc A,@A+DPTR ;compare value in lookup table
mov SEVENSEGMENT, #0 ;clear seven segment display
clr K1 ;select display 1
setb K2
Mov SEVENSEGMENT,A ;send data to seven segment display
55
mov SEVENSEGMENT, #0 ;clear seven segment display
setb K1 ;select display 2
clr K2
Mov SEVENSEGMENT,A ;7seg
ret
;======================================================================
; Lookup Table
; Decoder to Seven Segment
;======================================================================
Decoder7Segment:
DB 00111111b,00000110b,01011011b,01001111b,01100110b
DB 01101101b,01111101b,00000111b,01111111b,01101111b
;======================================================================
; Lookup Table
; Temperature = DataADC*100/255
;======================================================================
Ones:
db 0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8,9,9
db 0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8,9
db 9,0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8
db 9,9,0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8
db 8,9,9,0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8,9,9,0
Tens:
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
db 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
db 3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
db 5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
db 7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,0
end
56
8.1.5 INTERFACING OF 16*2 LCD DISPLAY
Description.
This is the first interfacing example for the Parallel Port. We will start with something simple. This
example doesn't use the Bi-directional feature found on newer ports, thus it should work with most, if no
all Parallel Ports. It however doesn't show the use of the Status Port as an input. So what are we
interfacing? A 16 Character x 2 Line LCD Module to the Parallel Port. These LCD Modules are very
common these days, and are quite simple to work with, as all the logic required to run them is on board.
Schematic
Circuit Description
Above is the quite simple schematic. The LCD panel's Enable and Register Select is connected to the
Control Port. The Control Port is an open collector / open drain output. While most Parallel Ports have
internal pull-up resistors, there are a few which don't. Therefore by incorporating the two 10K external
pull up resistors, the circuit is more portable for a wider range of computers, some of which may have no
internal pull up resistors.
We make no effort to place the Data bus into reverse direction. Therefore we hard wire the R/W line of
the LCD panel, into write mode. This will cause no bus conflicts on the data lines. As a result we cannot
read back the LCD's internal Busy Flag which tells us if the LCD has accepted and finished processing
the last instruction. This problem is overcome by inserting known delays into our program.
57
The 10k Potentiometer controls the contrast of the LCD panel. Nothing fancy here. As with all the
examples, I've left the power supply out. You can use a bench power supply set to 5v or use a onboard +5
regulator. Remember a few de-coupling capacitors, especially if you have trouble with the circuit working
properly.
The 2 line x 16 character LCD modules are available from a
wide range of manufacturers and should all be compatible
with the HD44780. The one I used to test this circuit was a
Powertip PC-1602F and an old Philips LTN211F-10 which
was extracted from a Poker Machine! The diagram to the
right, shows the pin numbers for these devices. When
viewed from the front, the left pin is pin 14 and the right pin
is pin 1.
58
/* 17th May 1997 */
/* Copyright 1997 Craig Peacock */
/* WWW - http://www.senet.com.au/~cpeacock */
/* Email - [email protected] */
/* */
/* Register Select must be connected to Select Printer (PIN 17) */
/* Enable must be connected to Strobe (PIN1) */
/* DATA 0:7 Connected to DATA 0:7 */
#include <dos.h>
#include <string.h>
void main(void)
{
char string[] = {"Testing 1,2,3 "
"It' Works ! "};
char init[10];
int count;
int len;
init[0] = 0x0F; /* Init Display */
init[1] = 0x01; /* Clear Display */
init[2] = 0x38; /* Dual Line / 8 Bits */
outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port - Make sure Forward
Direction */
59
outportb(DATA, init[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe (Enable)*/
delay(20); /* Larger Delay for INIT */
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe (Enable)*/
delay(20); /* Larger Delay for INIT */
}
len = strlen(string);
60
After we initialize the LCD Module, we want to send text to it. Characters are sent to the LCD's Data
Port, thus we want to clear bit 3. Once again we must only change the one bit, thus we use
outportb(CONTROL, inportb(CONTROL) & 0xF7);. Then we set up another for loop to read a byte from
the string and send it to the LCD panel. This is repeated for the length of the string.
The delays should be suitable for most machines. If the LCD panel is not initializing properly, you can try
increasing the delays. Likewise if the panel is skipping characters, e.g. Tst ,2. On the other hand, If the
LCD module is repeating characters e.g. TTTeessttiinngg then you may have a faulting Enable
connection. Check your Enable to Strobe connection.
8.1.6 INTERFACING OF MAX 232
Several devices collect data from sensors and need to send it to another unit, like a computer, for further processing. Data
transfer/communication is generally done in two ways: parallel and serial. In the parallel mode, data transfer is fast and
uses more number of lines. This mode is good for short range data transfer.
Serial communication on the other hand, uses only one or two data lines to transfer data and is generally used for long
distance communication. In serial communication the data is sent as one bit at a time. This article describes the interfacing
of 8051 microcontroller (AT89C51) with a computer via serial port, RS232. Serial communication is commonly used in
61
applications such as industrial automation systems, scientific analysis and certain consumer products.
62
8.1.7 1 WIRE INTERFACE
Originated by Dallas Semiconductor ( now part of MAXIM ) to address a variety of peripherals, sensors, and memory
chips from a single wire interface ( DATA and Ground ). One signal wire carries both operating power and signal.
Usually the network is built using a wire pair where one wire carries the signal and power and the other wire is ground.
The system is sensitive to the right timing to operate well.
Relays are devices which allow low power circuits to switch a relatively high Current/Voltage ON/OFF. For a relay to
operate a suitable pull-in & holding current should be passed through its coil. Generally relay coils are designed to
operate from a particular voltage often its 5V or 12V.
The function of relay driver circuit is to provide the necessary current (typically 25 to 70ma) to energize the relay coil.
63
dissipated through the diode & the internal resistance of the relay coil. Normally 1N4148 can be used as it is fast
switching diode with a maximum forward current of 300ma. This diode is also called as free-wheeling diode.
The LED is used to indicate that the RELAY has been turned ON. The resistor R1 defines the current flowing through the
LED thereby defining the LED’s intensity.
Resistor R2 is used as a Series Base Resistor to set the base current. When working with 8051 controllers I have noted that
it’s not compulsory to use this resistor as the controller has internal 10k resistor which acts as a base resistor.
Microcontrollers have internal pull up resistors hence when a port pin is HIGH the output current flows through this
internal pull up resistor. 8051 microcontrollers have an internal pull up of 10KΩ. Hence the maximum output current will
be 5v/10k = 0.5ma. This current is not sufficient to drive the transistor into saturation and turn ON the relay. Hence an
external pull up resistor R3 is used. Let us now calculate the value of R3. Normally a relay requires a pull in current of
70ma to be turned ON. So our BC547 transistor will require enough base current to make sure it remains saturated and
provide the necessary collector current i.e. 70ma. The gain (h fe) of BC547 is 100 so we need to provide at least 70ma/100
= 0.7ma of base current. In practice you require roughly double the value of this current so we will calculate for 1.4ma of
base current.
Base Current(1.4ma) =o/p current of controller (0.5ma) + 5v/R3
65
8.2 ANALOG INTERFACING
ADVANTAGES
· Simple interface
· Low cost for low-resolutions
· High speed
· Low programming overhead
DISADVANTAGES
· High cost for higher resolutions
· Not all microcontrollers have analog inputs/outputs built-in
· Complicates the circuit design when external ADC or DAC are needed.
· Short distance, few feet maxim.
66
9 PRINTED CIRCUIT BOARD
It is an important process in fabrication of electronic equipment. The design of the PCB’s (Printed Circuit Boards)
depends uponcircuit requirements like noise immunity, working frequency and voltage levels etc. high power PCB’s
requires a special design strategy.
The detailed circuit diagram is very important for the layout designer but he must also be familiar with the design concept
as well as from the philosophy behind the equipment.
The single sided PCB’s are mostly used in entertainment electronics where manufacturing costs have to be kept at
minimum. However in industrial electronics cost factors cannot be neglected and single sided boards should be used
wherever a particular circuit can be accommodated on such boards.
9.2.2 DOUBLE SIDED BOARDS
Double sided PCB’s can be made with or without plating through holes. The production of boards with plating through
holes is fairly expensive. Therefore plated through holes are only chosen where the circuit complexities and density of
components is large.
67
Actual size PCB layout for the circuit shown is drawn on the copper board. The board is then immersed in FeCl3 solution
for 12 hours. In this process only the exposed copper surface is etched out by the solution. Now the petrol washes out the
paint and copper layout of copper on PCB is rubbed with a smooth sand paper slowly and lightly such that only the oxide
layers over the Cu are removed. Now the holes are drilled at the respective places according to components layout.
2. DRILLING
Drilling is one those operations that call for great care. For most purposes a 0.5 mm drill is required. Drill all holes with
this size first and hose which needs a larger drill can be drill again with the appropriate size.
3. LAYOUT DESIGN
When designing the layout one should observe the minimum size (component body, length and weight). Before
starting to design the layout we need all the required components in hand so that accurate assessment of space can
be made. other space considerations might also be included from case to case of mounted components over the the
printed circuit board or to access path of present components.
It might be necessary to turn some components around to a different angular position so that terminals are closer
to the connections of the components. The scale can be checked by positioning the components on the squared
paper. If any connection crosses, then one can reroute to avoid such condition.
All common or earth line should ideally be connected to common line routed around the perimeter of the layout.
This will act as the ground plane. If possibly try to route either the outer supply line to the ground plane or at the
opposite edge of the layout through the centre. The first set is tearing the circuit to eliminate the crossover without
altering the circuit detail in any way.
Plan the layout looking at topside of this board. First this should be translated inversely; later for the etching
pattern large areas are recommended minimum dimensions and allowance must be made for increased width
where termination holes are needed. From this aspect, it become little tricky to negotiate the route to connect
small transistors.
There are basically two ways of copper interconnection patterns underside the board. The first is the removal of
only the amount of copper necessary to isolate the junctions of the components to one another. The second is to
make the interconnection pattern looking more like conventional point writing by routing uniform width of copper
from component to component.
4. ETCHING PROCESS
Etching process requires the use of chemicals. Acid resistant dishes and running water supply. Ferric chloride is
mostly used solution but other etching materials such as ammonium per sulphate can be used. Nitric acid can be
but in general it is not used due to poisonous fumes.
The pattern prepared is glued to the the copper surface of the board using the latex type of adhesive that can be
cubed after use. The pattern is laid firmly on the copper using a very sharp knife to cut around the pattern areas.
Then apply the resistant solution, which can be a kind of ink solution for the purpose of maintaining smooth
clean outlines as far as possible. While the board is drying, test all the components. Before going to the next
68
stage , check the whole pattern and cross check with the circuit diagram. Check for any free metal on the copper.
The etching bath should be in a glass or enamel disc. If using crystal of ferric chloride these should be
thoroughly dissolved in water to the proportion suggested. There should be 0.5 lt. of water for 125 gm of crystal.
To prevent particles of copper hindering further etching, agitate the solutions carefully by gently twisting or
rocking the tray.
The board should not be left in the bath a moment longer than is needed to remove just the right amount of
copper. In spite of there being a resistive coating there is no protection against etching away through exposed
copper edges. This leads to over etching. have running water ready so that etched board can removed properly
and rinsed. This will halt etching immediately.
5. COMPONENT ASSEMBLY
From the greatest variety of electronic component available, which runs into thousands of different types it, is
often a perplexing task to know which is right for a given job.
There could be damage such as hairline crack on PCB. If there are, then they can be repaired by soldering a short
link of bare copper wire over the affected part.
The most popular method of holding all the items is to bring the wires far apart after they have been inserted in
the appropriate holes. This will hold the components in positions ready for soldering. Some components will be
considerably larger. So it is best to start mounting the smallest and then progressing through to the largest. Before
starting be certain that no further drilling is likely to be necessary because access may be impossible later.
Next will probably be the resistor, small signal diodes or other similar size components. Some capacitors are also
very small and it would be best to fit them afterwards. When fitting each group of components mark off each one
on the circuit as it is fitted so that if we have to leave the job we know where to recommence.
Although transistors and integrated circuits are small items there are good reasons for leaving the soldering of
these until the last step. The main point is that these components are very sensitive to heat if subjected to
prolonged application of the soldering iron, they could be internally damaged.
All the components before mounting are rubbed with sand paper so that oxide layer is removed from the tips.
Now they are mounted according o the component layout.
6. SOLDERING
This is the operation of joining the components with PCB after this operation the circuit will be ready to use to avoid any
damage or fault during this operation following care must be taken.
A longer duration contact between soldering iron bi & components lead can exceed the temperature ratting of
device & cause partial or total damage of the device. Hence before soldering we must carefully read the maximum
soldering temperature & soldering time for device.
The wattage of soldering iron should be selected as minimum as permissible for that soldering place.
To protect the devices by leakage current of iron its bit should be earthed properly.
We should select the soldering wire with proper ratio of Pb and Tn to provide the suitable melting point.
Proper amount of good quality flux must be applied on the soldering point to avoid dry soldering.
69
9.4 PCB LAYOUT OF OUR PROJECT
70
10. SOFTWARE DESCRIPTION
The programming of the demo board can be done by writing firmware code requires the following software.
• Raisonance is one of the embedded system vendors that provide the development tools for the 8051 microcontroller.
The software compiles the firmware code and generates an ’Intel Hex’ file. The Raisonance free
evaluation development kit can be downloaded from
http://www.raisonance.com.
• Flash Magic is a free Windows application software that allows easy
programming of Philips Flash Microcontrollers. The software loads the
’Intel Hex’ file to the microcontroller by using its in-system
programming mode communicating through serial port. The software can be downloaded from
http://www.esacademy.com/software/flashmagic.
FIRMWARE DESCRIPTION
The firmware code for the evaluation board is written in C language. It can be compiled by using an embedded C
compiler.
The firmware code consists of three major blocks: Main Loop, Interrupt Service Routine, and UART layer. Each are
described below.
The function of the Main Loop is to reset and initialize the UART by writing a character (an 8-bit data) to the UART
register. Inside the Main Loop, the microcontroller can select one of the two methods for communicating to the UART.
The two methods are polling the UART regularly and using an interrupt handler in the interrupt service routine. If using
the interrupt handler, the microcontroller and the UART interrupt bits must be enabled. The other function is to keep
checking the event flags and pass to the appropriate subroutine for further processing.
The microcontroller uses the interrupt service routine to handle an interrupt generated by the UART. As soon as the
UART generates an interrupt, the ISR checks the interrupt status of the UART to determine the interrupt type and sets up
proper event flags to inform the Main Loop program for processing the interrupt.
71
10.3 UART LAYER
The UART layer handles the bus interface between the microcontroller and the UART. The three functions in the UART
layer are:
UART_Reset — The microcontroller resets the UART device.
UART_Read — The UART places a character on the data bus for the microcontroller to read and the microcontroller
stores the character.
UART_Write — The microcontroller places a character on the data bus for the UART to read.
72
11. FUTURE EXPANSION
As we have seen that this project besides being used for burning the programs can also be interfaced with ADC , Relays ,
Stepper motor, LM35 and can give the respective output for which it is being used.
The following are some extensions of the projects which can be included in the project-
73
5. Ethernet Interfacing
74
12. BIBLIOGRAPHY
The 8051 Microcontroller and Embedded Systems in Assembly and C, By Muhammad Ali Mazidi, Janice
Gillispie Mazidi, Rolin D. McKinlay.
The 8051/8052 Microcontroller: Architecture, Assembly Language, and Hardware Interfacing By Craig Steiner.
The microcontroller idea book: circuits, programs, & applications By Jan Alexan.
Microcontrollers fundamentals for engineers and scientists By Steven Frank Barrett, Daniel J. Pack – 2006
Microcontroller-based temperature monitoring and control By Dogan Ibrahim – 2002
www.ikalogic.com
www.wikipedia.org
www.keil.com
www.8051.com
www.8052.com
Engineers garage.com
75