MC Lab-Record Final - Watermark-1
MC Lab-Record Final - Watermark-1
Earlier to Microcontrollers, Microprocessors were greatly used for each and every purpose.
Microprocessors were containing ALU, general purpose register, stack pointer, program counter,
clock counter and so many other features which the today’s Microcontroller also possesses. But the
difference between them exists with respect to the number of instructions, access times, size,
reliability, PCB size and so on. Microprocessor contains large instruction set called as CISC
processor whereas Microcontroller contains a smaller number of instructions and is called as RISC
processor. The access time is less in case of microcontrollers compared to microprocessors and
the PCB size reduces in case of microcontrollers.
The 8051 family was introduced in the early 1980s by Intel. Since its introduction, the 8051
has been one of the most popular microcontrollers and has been second- sourced by many
manufacturers. The 8051 currently has many different versions and some types include on-chip
analogue-to-digital converters, a considerably large size of program and data memories. The two
other members of these 8051 families are-
8052-This microcontroller has 3 timers & 256 bytes of RAM. Additionally, it has all the
features of the traditional 8051 microcontroller. 8051 microcontroller is a subset of 8052
microcontroller.
8031 - This microcontroller is ROM less, other than that it has all the features of a traditional
8051 microcontrollers. For execution an external ROM of size 64K bytes can be added to its
chip.8051 microcontroller brings into play 2 different sorts of memory such as - NV-
RAM, UV - EPROM and Flash. 8051 is the basic microcontroller to learn embedded systems
projects.
There are many versions of microcontrollers 8051, 80528751, AT8951 from Atmel
Corporation and many more. In this manual we will study about the 8051 architectures, its features,
programming and interfacing. MCS 8051 is an 8-bit single chip microcontroller with many built-in
functions and is the core for all MCS-51 devices. It was developed using N-type Metal-Oxide-
Semiconductor (NMOS) technology and later it came to be identified by a letter C in their names
e.g., 80C51 which was developed with Complementary Metal-Oxide-Semiconductor (CMOS)
technology which consumes less power than NMOS and made it better compatible for battery-
powered applications.
Pins 1-8: Port 1 Each of these pins can be configured as an input or an output.
Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most
registers. In other words, the positive voltage on this pin resets the microcontroller. By applying
logic zero to this pin, the program starts execution from the beginning.
Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output. Besides,
all of them have alternative functions:
Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication
output.
Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication
clock output.
Pin 12: INT0 Interrupt 0 inputs.
Pin 13: INT1 Interrupt 1 input.
Pin 14: T0 Counter 0 clock input.
Pin 15: T1 Counter 1 clock input.
Pin 16: WR Write to external (additional) RAM.
Pin 17: RD Read from external RAM.
Pin 18, 19: X2, X1 Internal oscillator input and output. A quartz crystal which specifies operating
frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also
be used for frequency stability. Later versions of microcontrollers operate at a frequency of 0 Hz
up to over 50 Hz.
Pin 20: GND Ground.
Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured
as general inputs/outputs. In case external memory is used, the higher address byte, i.e., addresses
A8-A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which
means that not all eight port bits are used for its addressing, the rest of them are not available as
inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program, then a logic zero (0) appears on it
every time the microcontroller reads a byte from memory.
Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address
byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the
external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and
uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous logic
state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by means
of only one additional (and cheap) integrated circuit. In other words, this port is used for both data
and address transmission.
Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address transmission
with no regard to whether there is internal memory or not. It means that even there is a program
written to the microcontroller, it will not be executed. Instead, the program written to external
ROM will be executed. By applying logic one to the EA pin, the microcontroller will use both
memories, first internal then external (if exists).
Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general
inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven
high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
Pin 40: VCC +5V power supply.
Step 03: Create a new project folder. Right Click on Mouse >>New >> Folder.
Step 05: Open the folder and chose project name and save.
Step 06: Chose Microcontroller as “AT89S51” and click OK. Apopup window will open.
Just click NO
Step 09: Press CTRL + S keys to save the file. A window willopen. Save the file as
ADDITION.ASM/.A/.S/.M
After saving file, the window name will change to given nameand the text will be in colored
format.
Step 12: Double click on “Source Group 1” Folder. A windowwill appear. Select the file
that you saved as .ASM/.A/.S/.S and click Add. Then close the window.
Step 13: Pres F7 Key to build the program. After successfulbuild, you can see the output
window like below.
Step 14: Go to Debug >> Start Stop Debug session. A popupwindow will open. Just
click on OK
Then the debug window will open like below, click “OK”
Step 15: Press F11 key to check the step-by-step register/Memory changes while running
of program
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
The instruction ADD is used to add two operands. The destination operand is always in
register A while the source operand can be a register, immediate data, or in memory. Remember that
memory-to-memory arithmetic operations are never allowed in 8051 Assembly language. The
instruction could change any of the AF, CF, or P bits of the flag register, depending on the operands
involved. The effect of the ADD instruction on the overflow flag is discussed in Section 6.3 since it
is used mainly in signed number operations.
In this group, we have instructions to
i. Add the contents of A with immediate data with or without carry.
i. ADD A, #45H
ii. ADDC A, #OB4H
ii. Add the contents of A with register Rn with or without carry.
i. ADD A, R5
ii. ADDC A, R2
iii. Add the contents of A with contents of memory with or without carry using direct and
indirect addressing
i. ADD A, 51H
ii. ADDC A, 75H
iii. ADD A, @R1
iv. ADDC A, @R0
CY AC and OV flags will be affected by this operation.
Subtraction
In many microprocessors there a^e two different instructions for subtraction: SUB and
SUBB (subtract with borrow). In the 8051 we have only SUBB. If the C Y = 0 after the execution
of SUBB, the result is positive; if C Y = 1, the result is negative and the destination has the 2′s
complement of the result
In the arithmetic group, we have instructions to
i. Subtract the contents of A with immediate data with or without carry.
i. SUBB A, #45H
ii. SUBB A, #OB4H
ii. Subtract the contents of A with register Rn with or without carry.
i. SUBB A, R5
ii. SUBB A, R2
iii. Subtract the contents of A with contents of memory with or without carry using direct
and indirect addressing
i. SUBB A, 51H
ii. SUBB A, 75H
iii. SUBB A, @R1
iv. SUBB A, @R0
Multiplication
In multiplying or dividing two numbers in the 8051, the use of registers A and B is required
since the multiplication and division instructions work only with these two registers.
This instruction multiplies two 8 bit unsigned numbers which are stored in A and B register.
After multiplication the lower byte of the result will be stored in accumulator and higher byte of
result will be stored in B register.
Division
This instruction divides the 8-bit unsigned number which is stored in A by the 8 bit unsigned
number which is stored in B register. After division the result will be stored in accumulator and
remainder will be stored in B register.
INC increments the value of source by 1. If the initial value of register is FFh, incrementing
the value will cause it to reset to 0. The Carry Flag is not set when the value "rolls over" from 255
to 0.
In the case of "INC DPTR", the value two-byte unsigned integer value of DPTR is
incremented. If the initial value of DPTR is FFFF h, incrementing the value will cause it to reset to
0.
Decrement:
DEC decrements the value of source by 1. If the initial value of is 0, decrementing the value
will cause it to reset to FF h. The Carry Flag is not set when the value "rolls over" from 0 to FF h.
PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program.
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
Logical AND
ANL does a bitwise "AND" operation between source and destination, leaving the resulting
value in destination. The value in source is not affected. "AND" instruction logically AND the bits
of source and destination.
Logical OR
ORL does a bitwise "OR" operation between source and destination, leaving the resulting
value in destination. The value in source is not affected. " OR " instruction logically OR the bits of
source and destination.
Logical Ex-OR
XRL destination, source:
XRL does a bitwise "EX-OR" operation between source and destination, leaving the
resulting value in destination. The value in source is not affected. " XRL " instruction logically
EX-OR the bits of source and destination.
CPL complements operand, leaving the result in operand. If operand is a single bit, then the
state of the bit will be reversed. If operand is the Accumulator, then all the bits in the Accumulator
will be reversed.
CPL A CPL C CPL bit address
SWAP Instruction
SWAP A
Swap the upper nibble and lower nibble of A.
PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program.
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
It must be noted that although ASCII is standard in the United States (and many other
countries), BCD numbers are universal. Since the keyboard, printers, and monitors all use ASCII,
data should get converted from ASCII to BCD, and vice versa.
Many systems have what is called a real-time clock (RTC). The RTC provides the time of
day (hour, minute, second) and the date (year, month, day) continuously, regardless of whether the
power is on or off (see Chapter 16). However, this data is provided in packed BCD. For this data to
be displayed on a device such as an LCD, or to be printed by the printer, it must be in ASCII format.
To convert packed BCD to ASCII, it must first be converted to unpacked BCD. Then the
unpacked BCD is tagged with Oil 0000 (30H). The following demonstrates converting from packed
BCD to ASCII.
Instructions Used
RR A
This instruction is rotate right the accumulator. Its operation is illustrated below. Each bit is
shifted one location to the right, with bit 0 going to bit 7.
RL A
Rotate left the accumulator. Each bit is shifted one location to the left, with bit 7 going to bit 0
RRC A
Rotate right through the carry. Each bit is shifted one location to the right, with bit 0 going
into the carry bit in the PSW, while the carry was at goes into bit 7
RLC A
Rotate left through the carry. Each bit is shifted one location to the left, with bit 7 going into
the carry bit in the PSW, while the carry goes into bit 0.
PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running program.
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
Example 2:
PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
If Port 2 is configured as an output port, then for using it as an input port again we write 1 to
all bits of port 2.
Port 3 (Pin No 10-Pin No 17):
Port 3 is also of 8 bits and it can be used as Input/output. This port provides some important
signals.
P3.1 and P3.0 are RxD (Receiver) and TxD (Transmitter) respectively and it is collectively
used for serial communication. P3.3 and P3.2 pins are used as external interrupts. P3.5 and P3.4 are
used as timers T1 and T0 respectively. P3.6 and P3.7 are Write (WR) and Read (RD) pins.
Port 3 table showing an individual pin function:
13 INT 1 P3.3<
PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
Display units are the most important output devices in embedded projects and electronics
products. 16x2 LCD is one of the most used display unit. 16x2 LCD means that there are two rows
in which 16 characters can be displayed per line, and each character takes 5X7 matrix space on LCD.
A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this
LCD each character is displayed in a 5×7-pixel matrix. This LCD has two registers, namely,
Command and Data. The command register stores the command instructions given to the LCD. A
command is an instruction given to LCD to do a predefined task like initializing it, clearing its
screen, setting the cursor position, controlling display, etc. The data register stores the data to be
displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.
The LCD display module requires 3 control lines as well as either 4 or 8 I/O lines for the data bus.
The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. If a 4-
bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for
the data bus). If an 8-bit data bus is used the LCD will require a total of 11 data lines (3 control lines
plus the 8 lines for the data bus).
The three control lines are referred to as EN, RS, and RW.
EN:-The EN line is called “Enable.” This control line is used to tell the LCD that you are sending it
data. To send data to the LCD, your program should make sure this line is low (0) and then set the
other two control lines and/or put data on the data bus. When the other lines are completely ready,
bring EN high (1) and wait for the minimum amount of time required by the LCD datasheet (this
varies from LCD to LCD), and end by bringing it low (0) again.
RS:-The RS line is the “Register Select” line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1),
the data being sent is text data which should be displayed on the screen. For example, to display the
letter “T” on the screen you would set RS high.
RW:-The RW line is the “Read/Write” control line. When RW is low (0), the information on the
data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or
reading) the LCD. Only one instruction (“Get LCD status”) is a read command. All others are write
commands–so RW will almost always be LOW.
DB0 – DB7:- Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation
selected by the user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2,
DB3, DB4, DB5, DB6, and DB7.
There are some preset command instructions in LCD, to prepare the LCD (in lcd_init()
function). Some important command instructions are given below:
PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
3. stage to detect which row it belongs to; otherwise, it goes back into the loop to detect a real
key press.
4. To detect which row the key press belongs to, the microcontroller grounds one row at a time,
reading the columns each time. If it finds that all columns are high, this means that the key
press cannot belong to that row; therefore, it grounds the next row and continues until it finds
the row the key press belongs to. Upon finding the row that the key press belongs to, it sets
up the starting address for the look-up table holding the scan codes (or the ASCII value) for
that row and goes to the next stage to identify the key.
5. To identify the key press, the microcontroller rotates the column bits, one bit at a time, into
the carry flag and checks to see if it is low. Upon finding the zero, it pulls out the ASCII code
for that key from the look-up table; otherwise, it increments the pointer to point to the next
element of the look-up table.
PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
1.Timer Registers
It is a16 bit register and can be accessed as 8 bit registers say Timer High(THx) and Timer
Low (TLx),These registers can be accessed as any other registers like A,B,R0 etc.,
In upper or lower 4 bits, first bit is a GATE bit. Every timer has a means of starting and
stopping. Some timers do this by software, some by hardware, and some have both software and
hardware controls. The hardware way of starting and stopping the timer by an external source is
achieved by making GATE=1 in the TMOD register and if GATE=0 then we do start and stop the
timers by programming.
The second bit is C/T bit and is used to decide whether a timer is used as a time delay
generator or an event counter. If this bit is 0 then it is used as a timer and if it is 1 then it is used as
a counter.
In upper or lower 4 bits, the last bits third and fourth are known as M1 and M0 respectively. These
are used to select the timer mode.
1 = Enable Timer/Counter only when the INT0/INT1 pin is high and TR0/TR1 is set.
1 = Use as Counter
0 = Use as Timer
These are Timer/Counter mode select bit as per the below table
M1 M0 Mode Operation
0 0 0 (13-bit timer mode) 13-bit timer/counter, 8-bit of THx & 5-bit of TLx
TCON Register
TCON is an 8-bit control register and contains a timer and interrupt flags.
MODES OF OPERATION:
Mode 0
Mode 0 is a 13-bit timer mode for which 8-bit of THx and 5-bit of TLx (as Prescaler) are
used. The 13- bit counter can hold values between 0000 to 1FFFH in TH-TL. Therefore, when the
timer reaches its maximum of 1FFH, it rolls over to 0000, and TF is raised. It is mostly used for
interfacing possible with old MCS-48 family microcontrollers.
Steps to program in mode 0
1. Load TMOD register value i.e. TMOD = 0x00 for Timer0/1 mode0 (13-bit timer mode).
2. Load calculated THx value i.e. here TH0 = 0xE3.
3. Load calculated TLx value i.e. here TL0 = 0x14.
4. Start the timer by setting a TRx bit. i.e. here TR0 = 1.
5. Poll TFx flag till it does not get set.
6. Stop the timer by clearing TRx bit. i.e. here TR0 = 0.
7. Clear timer flag TFx bit i.e. here TF0 = 0.
8. Repeat from step 1 to 7 for the delay again.
Mode 1:
It is a 16-bit timer; therefore it allows values from 0000 to FFFFH to be loaded into the
timer’s registers TL and TH .
Steps to program in mode 1:
1. Load the TMOD value register with mode and timer0 or 1.
2. Load registers TLx and THx with initial count corresponding to delay.
3. Start the timer.
4. Continuously monitor the timer flag (TFx) with the “JNB TFx,target” instruction to see
if it is raised, if it is raised (TFx=1) then get out of the loop.
5. Stop the timer.
6. Clear the TFx flag for the next round.
7. Go back to Step 2 to load THx and TLx again.
In 8051 mcu mode 2 is an 8-bit auto-reload timer mode. In this mode, we have to load the
THx-8-bit value only. when the Timer gets started, the THx value gets automatically loaded into the
TLx and TLx starts counting from that value. After the value of TLx overflows from the 0xFF to
0x0, the TFx flag gets set and again value from the THx gets automatically loaded into the TLx
register.
Steps to program in mode 1:
1. Select timer in TMOD register indicating which timer (timer 0 or timer 1) is to be used,
and the timer mode (mode 2) to be selected
2. THx register loaded with initial count value
3. Start timer
4. Continuously monitoring the timer flag (TFx) with the JNB TFx,target instruction to see
whether TFx is ‘1’ (high) . Get out of the loop when TF goes high
5. Clear the TFx flag
6. Go back to Step4, since mode 2 is auto-reload
PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
The main purpose of DC interfacing with 8051 microcontroller is for controlling the speed
of the motor. The DC motor is an electrical machine with a rotating part termed as a rotor which has
to be controlled. Speed or direction of rotation of DC motor can be controlled using programming
techniques which can be achieved by interfacing with 8051 microcontrollers.
Motor Driver
The maximum output current of microcontroller pin is 15mA at 5V. But the power
requirements of most of DC motors is out of reach of the microcontroller and even the back emf
(electro motive force) which is produced by the motor may damage the microcontroller. Hence, it is
not good to interface DC motor directly to the controller. So, we use motor driver circuit in between
a DC motor and the microcontroller.
There are various types of driver ICs among which L293D is typically used for interfacing
DC motor with 8051. L293 is an IC with 16 pins which are represented in the figure below.
This L293 IC is having ratings of 600mA per channel and DC supply voltage in the range of 4.5V
to 36V. These ICs can be protected from inductive spikes by connecting higher speed clamp diodes
internally. This 16 pin L293D IC can be used for controlling the direction of two DC motors. The
IC L293D works based on the H-bridge concept. The voltage can be made to flow in either direction
using this circuit (H-bridge) such that by changing the voltage direction the motor direction can be
changed.
Pin description:
VSS pin is used to provide input voltage to L293D. For 8051 interface, 5v is given to it.
The motor supply is given to VS pin of the L293D. It depends upon motor requirement.
EN1 is used to enable input pair 1 (IN1, IN2, for OUT1, OUT2) and EN2 is used to
enable input pair 2 (IN3, IN4, for OUT3, OUT4). EN is connected to 5V for to enable
any input.
Direction of motor 1 is controlled through input pins logic. IN1 and IN2 control motor
connected output OUT1 and OUT2.
Direction of motor 2 is controlled through input pins logic. IN3 and IN4 control motor
connected output OUT3 and OUT4.
All GND pins should be connected to ground.
CONNECTIONS:
P2 of 8051 microcontroller is used as output port and it gives inputs to the motor driver
IC. Its lower four pins are connected to drive two DC motors.
P0 is used as input port. 2 Buttons are connected to its lower two pins so that whenever
we can manually start and stop the motors.
Motor 1 is connected between OUT1 and OUT2 of L293D. Motor 2 is connected
between OUT3 and OUT4 of L293D.
12V battery is used to give input to the VS for motors.
5V battery is used to give input to VSS for motor driver IC.
PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
Pin
Pin Name Description
Number
Chip select is used if more than 1 ADC module is
1 Chip Select (CS)
used. By default, grounded
Read pin must be grounded to read the Analog
2 Read (RD)
value
Write pin should be pulsed high to start data
3 Write (WR)
conversion
An external clock can be connected here, else
4 CLK IN
RC can be used for accessing the internal clock
5 Interrupt (INTR) Goes high for interrupt request.
Differential Analog input +. Connect to ADC
6 Vin (+)
input
7 Vin (-) Differential Analog input -. Connect to ground
Analog Ground pin connected to the ground of
8 Ground
the circuit
9 Vref/2 Reference voltage for ADC conversion.
Digital Ground pin connected to the ground of
10 Ground
the circuit
Seven output Data bit pins from which output is
11 to 18 Data bit 0 to bit 7
obtained
RC timing resistor input pin for internal clock
19 CLK R
gen
20 Vcc Powers the ADC module, use +5V
Steps for converting the analogue input and reading the output from ADC0804.
Make CS=0 and send a low to high pulse to WR pin to start the conversion.
Now keep checking the INTR pin. INTR will be 1 if conversion is not finished and
INTR will be 0 if conversion is finished.
If conversion is not finished (INTR=1), poll until it is finished.
If conversion is finished (INTR=0), go to the next step.
Make CS=0 and send a high to low pulse to RD pin to read the data from the ADC.
PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
When the phase winding of the stepper motor is provided with a current, corresponding
magnetic flux will be developed in the stator in the direction perpendicular to the direction of the
current flow. When one electromagnet is energized with the help of an external driver circuit or a
microcontroller, the rotor shaft turns in such a way that it aligns itself with the stator in a position
that minimizes the flux opposition. And when the next electromagnet is turned on and the first is
turned off, the gear rotates slightly to align with the next one. From there the process is repeated.
Each of those rotations is called a “step”, with an integer number of steps making a full rotation. In
that way, the motor can be turned by a precise angle.
Coils should be energised in a particular sequence to make the rotator rotate. On the basis of
this “sequence” we can divide the working method of Unipolar stepper motor in three modes: Wave
drive mode, full step drive mode and half step drive mode.
Wave drive mode:
In this mode one coil is energised at a time, all four coils are energised one after another. It
produces less torque in compare with Full step drive mode but power consumption is less. Following
is the table for producing this mode using microcontroller, means we need to give Logic 1 to the
coils in the sequential manner.
Steps A B C D
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
Full Drive mode: In this, two coil are energised at the same time producing high torque.
Power consumption is higher. We need to give Logic 1 to two coils at the same time, then to the
next two coils and so on.
Steps A B C D
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
Steps A B C D
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
7 0 0 0 1
8 1 0 0 1
8051 doesn’t provide enough current to drive the coils so we need to use a current driver IC
that is ULN2003A. ULN2003A is the array of seven NPN Darlington transistor pairs. Darlington
pair is constructed by connecting two bipolar transistors to achieve high current amplification. In
ULN2003A, 7 pins are input pins and 7 pins are output pins, two pins are for Vcc (power supply)
and Ground. Here we are using four input and four output pins. We can also use L293D IC in place
of ULN2003A for current amplification.
PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..
2. Half duplex communication link: In half duplex, the communication link can be used for
either transmission or reception. Data is transmitted in only one direction at a time.
3. Full duplex communication link: If the data is transmitted in both ways at the same time, it
is a full duplex i.e., transmission and reception can proceed simultaneously. This
communication link requires two wires for data, one for transmission and one for reception.
The 8051 supports a full duplex serial port. Three special function registers support serial
communication.
1. SBUF Register: Serial Buffer (SBUF) register is an 8-bit register. It has separate SBUF
registers for data transmission and for data reception. For a byte of data to be transferred via the
TXD line, it must be placed in SBUF register. Similarly, SBUF holds the 8-bit data received by the
RXD pin and read to accept the received data.
2. SCON register: The contents of the Serial Control (SCON) register are shown below.
This register contains mode selection bits, serial port interrupt bit (TI and RI) and also the ninth data
bit for transmission and reception (TB8 and RB8).
Normally mode-1 (SM0 =0, SM1=1) is used with 8 data bits, 1 start bit, and 1 stop bit.
Bit 5 - SM2: for Multiprocessor Communication
This bit enables a multiprocessor communication feature in mode 2 & 3.
Bit 4 - REN: Receive Enable
1 = Receive enable
0 = Receive disable
Bit 3 - TB8: 9th Transmit Bit
This is the 9th bit which is to be transmitted in mode 2 & 3 (9-bit mode)
Bit 2 - RB8: 9th Receive Bit
This is the 9th received bit in mode 2 & 3 (9-bit mode), whereas in mode 1 if SM2
= 0 then RB8 hold the stop bit that received
Bit 1 - TI: Transmit Interrupt Flag
This bit indicates the transmission is complete and gets set after transmitting the
byte from the buffer. Normally TI (Transmit Interrupt Flag) is set by hardware at
the end of the 8th bit in mode 0 and at the beginning of stop bit in other modes.
Bit 0 – RI: Receive Interrupt Flag
This bit indicates reception is complete and gets set after receiving the complete
byte in the buffer. Normally RI (Receive Interrupt Flag) is set by hardware in
receiving mode at the end of the 8th bit in mode 0 and at the stop bit receive time
in other modes.
3. PCON register: The SMOD bit (bit 7) of PCON register controls the baud rate in
asynchronous mode transmission.
SMOD => Double Baud rate when Serial port is used in mode 1,2 or 3.
GF1 => General purpose flag bit.
GF0 => General purpose flag bit.
PD =>Power down. Activates power down operation.
IDL =>Ideal mode. Activates ideal mode operation.
— => Reserved
PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program.
9. Press F5 Key to run the program and view the serial data transfer on “View ”→“Serial
Window” → “UART #1”.
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
FACULTY INCHARGE
…………………………..