0% found this document useful (0 votes)
72 views19 pages

Mca

The document describes three experiments involving writing and executing assembly language programs using an 8051 microcontroller. The first experiment involves performing arithmetic operations like addition, subtraction, multiplication and division on two 8-bit numbers. The second experiment involves sorting an array of 10 8-bit numbers in ascending and descending order using bubble sort. The third experiment involves transferring blocks of data between internal memory, external memory, and within memories using memory pointers. Procedures for creating projects, writing and debugging code, and running programs in Keil μVision5 are also provided.

Uploaded by

Poojan Gala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views19 pages

Mca

The document describes three experiments involving writing and executing assembly language programs using an 8051 microcontroller. The first experiment involves performing arithmetic operations like addition, subtraction, multiplication and division on two 8-bit numbers. The second experiment involves sorting an array of 10 8-bit numbers in ascending and descending order using bubble sort. The third experiment involves transferring blocks of data between internal memory, external memory, and within memories using memory pointers. Procedures for creating projects, writing and debugging code, and running programs in Keil μVision5 are also provided.

Uploaded by

Poojan Gala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 19

exp 1

To Write and execute Assembly Language Program to perform addition, subtraction,


Multiplication and division of two 8 bit numbers using 8051 microcontroller

Objective: The main objective is to study and write the program to perform
addition, subtraction,
Multiplication and division of two 8 bit numbers using 8051 microcontroller
instructions
and to study what and how the instructions are used in writing the program.

Apparatus: Software: Keil µvision 5


Theory: 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 less 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.
There are many versions of microcontrollers 8051, 80528751, AT8951 from
Atmel Corporation and many more. In this manual we will study about the 8051
architecture, 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.
The main features of the 8051 core are:
 Operates with single Power Supply +5V.
 8-bit CPU optimized for control applications.
 16-bit program counter (PC) and 16-bit data pointer (DPTR).
 8-bit program status word (PSW).
 8-bit stack pointer (SP). 4K Bytes of On-Chip Program Memory (Internal ROM or
EPROM).
 128 bytes of On-Chip Data Memory (Internal RAM):
 Four Register Banks, each containing 8 registers (R0 to R7) [Total 32 reg]
 16-bytes of bit addressable memory.
 80 bytes of general-purpose data memory (Scratch Pad Area).
 Special Function Registers (SFR) to configure/operate microcontroller.
 32 bit bi-directional I/O Lines (4 ports P0 to P3).
 Two 16-bit timers/counters (T0 and T1).
 Full duplex UART (Universal Asynchronous Receiver/Transmitter).
 On-Chip oscillator and clock circuitry.

Algorithm: ALGORITHM FOR ADDITION:

1. Load the first 8 bit number to A


2. Load the second 8 bit number to 8bit register R1
3. Clear the contents of R2
4. Add the contents of A with register contents
5. Store the 8bit result in A to mem. location
6. If carry flag is reset, branch to loop1
7. Increment R2
8. Store the contents of R2 in other mem. location
ALGORITHM FOR SUBTRACTION:
1 Load the first 8 bit number to A
2. Load the second 8 bit number to 8bit register R1
3. clear the contents of R2
4. Subtract the contents of A with register contents
5. Store the 8bit result in A to mem. location
6. If carry flag is reset, branch to loop1
7. Increment R2
8. Store the contents of R2 in other mem. location
ALGORITHM FOR MULTIPLICATION:
1. Load the first 8 bit number to A
2. Load the second 8 bit number to temporary register B
3.Multiply the contents of A with register B contents
5. Store the low byte of result in A to mem. Location
6. Store the high byte of result in B to other mem. Location
ALGORITHM FOR DIVISION:
1. Load the first 8 bit number to A
2. Load the second 8 bit number to temporary register B
3.Divide the contents of A by register B contents
5. Store the remainder of result in A to mem. Location
6. Store the quotient of result in B to other mem. Location

Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.
PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

Create a source file (using File->New), type in the assembly or C

PRO4:
program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO5:
Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an
error free, to build go to Debug mode.

PRO6:
Now user can enter into Debug mode with Debug- Start / Stop
Debug session dialog. Or by clicking in the icon.

PRO7:
The program is run using the Debug-Run command & halted
using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor).

exp 2

To Write and execute Assembly Language Program to sort the 10 8-bit numbers in

ascending and descending order


Objective: The main objective is to study and write the program to sort the 10
numbers in
ascending and descending order using bubble sort algorithm and using 8051
microcontroller instructions.
Apparatus: Software: Keil µvision 5
Theory: 8051 Programming in Assembly Language

An assembly language program is a series of statements, which are either assembly


language instructions such as ADD and MOV, or statements called directives.
An instruction tells the CPU what to do, while a directive (also called pseudo-
instructions)
gives instruction to the assembler. For example, ADD and MOV instructions are
commands which the CPU runs, while ORG and END are assembler directives. The
assembler places the opcode to the memory location 0 when the ORG directive is
used,
while END indicates to the end of the source code. A program language instruction
consists of the following four fields −
[ label: ] mnemonics [ operands ] [;comment ]

8051 Programming in Assembly Language

Assembler Directives:
ORG(origin): This directive indicates the start of the program. This is used to set
the
register address during assembly. For example; ORG 0000h tells the compiler all
subsequent code starting at address 0000h.

END:The END directive is used to indicate the end of the program.

Algorithm: ALGORITHM FOR ASCENDING:

1. Initialize R3 with N-1 (Total array elements-1)


2. Initialize R0 with starting address of the array
3. Copy the contents of R2 to R3 register
4. Load the element pointed by R0 into A and the next element to register B
5. Compare the contents of A with contents of B
6. if A is greater (No Carry) , then exchange the two elements in the memory
7. Increment the pointer and decrement R2 register
8. Check if all the elements have been compared in the array ( i.e. R2=0?)
9. No, go to the step 4
10. Yes, decrement R3; if it is not 0, go to step 2
11. If R3=0, terminate the program
ALGORITHM FOR DESCENDING:
1. Initialize R3 with N-1 (Total array elements-1)
2. Initialize R0 with starting address of the array
3. Copy the contents of R2 to R3 register
4. Load the element pointed by R0 into A and the next element to register B
5. Compare the contents of A with contents of B
6. if A is Smaller ( Carry) , then exchange the two elements in the memory
7. Increment the pointer and decrement R2 register
8. Check if all the elements have been compared in the array ( i.e. R2=0?)
9. No, go to the step 4
10. Yes, decrement R3; if it is not 0, go to step 2
11. If R3=0, terminate the program

Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.
PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

PRO4: Create a source file (using File->New), type in the assembly or C


program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO5:
Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an
error free, to build go to Debug mode.

PRO6:
Now user can enter into Debug mode with Debug- Start / Stop
Debug session dialog. Or by clicking in the icon.

PRO7:
The array elements are given at the corresponding data
memory location as per specified in the program.
The program is run using the Debug-Run command & halted
using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor).

exp 3

Experiment No.-3
Aim: To Write and execute Assembly Language Program to transfer a block of data

i) from external memory to internal memory


ii) within the internal memory and
iii) within the external memory using 8051 microcontroller
Objective: The main objective is to study and write the program transfer a block of
data

i) from external memory to internal memory


ii) within internal memory
iii) within the external memory using 8051 microcontroller instructions and to
study what and how the instructions are used in writing the program. To
understand the concept of memory pointers and their usage in programming
for accessing of block of data.

Apparatus: Software: Keil µvision 5


Theory: Data Memory of 8051:

8051 supports 64K Bytes of external data memory in addition to 128 Bytes of
internal
RAM. The external data memory is accessed using 16-bit address lines and its
address
varies from 0000H to FFFFH. 
The general block diagram of data memory is shown below.

Internal Data Memory Organization:


The 128 bytes of Internal RAM is grouped as follows and is shown in the figure
below:
1. Register Bank
2. Bit addressable Area
3. Scratch Pad Area

Internal 128Bytes of Internal RAM

The MOVX instruction is used when external memory is to be interfaced. This


performs
data transfer only between external memory and accumulator. In this instruction one
side
accumulator is compulsory. The MOVX instruction performed always in Indirect
addressing mode.

Algorithm: ALGORITHM FOR TRANSFER OF DATA FROM EXTERNAL TO INTERNAL:

1. Initialize DPTR as source pointer register.


2. Initialize R0 as destination pointer register.
3. Set the loop count to 10 to transfer 10 bytes of data.
4. copy the contents of memory location pointed by DPTR to A
5. Store the data in destination location pointed by R0 from A.
6. Increment DPTR and R0 to point to next source and destination location
7. Decrement loop count
8. Continue at step 4 if the loop count is not zero.
ALGORITHM FOR TRANSFER OF DATA WITHIN THE INTERNAL MEMORY:
1. Initialize R0 as source pointer register.
2. Initialize R1 as destination pointer register.
3. Set the loop count to 10 to transfer 10 bytes of data.
4. copy the contents of memory location pointed by R0 to A
5. Store the data in destination location pointed by R1 from A.
6. Increment R0 and R1 to point to next source and destination location
7. Decrement loop count
8. Continue at step 4 if the loop count is not zero.
ALGORITHM FOR TRANSFER OF DATA WITHIN EXTERNAL:
1. Load 00H to R4.

2. Load 50H to R5.


3. Load 00H to R2.
4. Load 60H to R3.
5. Set the loop count to 10 to transfer 10 bytes of data.
6. Copy the contents of R5 and R4 to DPTR.
7. copy the contents of memory location pointed by DPTR to A
8. Copy the contents of R3 and R2 to DPTR.
5. Store the contents of A to destination location pointed by DPTR.
6. Increment R4 and R2 to point to next source and destination location
7. Decrement loop count
8. Continue at step 6 if the loop count is not zero.

Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.
PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

PRO4: Create a source file (using File->New), type in the assembly or C


program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO5:
Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an
error free, to build go to Debug mode.

PRO6:
Now user can enter into Debug mode with Debug- Start / Stop
Debug session dialog. Or by clicking in the icon.

PRO7:
The block of elements are given at the corresponding external
memory location as per specified in the program.
The program is run using the Debug-Run command & halted
using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor).

exp 4 Experiment No.-4


Aim: To Write and Execute Assembly Language Program to generate a delay of 20msecs
using

8051 microcontroller.

Objective: The main objective is to generate software delay and write a software to
create a delay of
20msecs. As well to understand difference between software and hardware delay.

Apparatus: Software: Keil µvision 5


Theory: In an 8051 microcontroller, it requires 12  cycles of the processor clock
for
executing a single instruction cycle.  For an 8051 microcontroller clocked by a
12MHz
crystal, the time taken for executing one instruction cycle is 1µS and it is
according to the
equation,  Time for 1 instruction cycle= 12 /12MHz = 1µS.  The shortest
instructions will
execute in 1µS and other instructions will take 2 or more micro seconds depending
up on
the size of the instruction. Thus a time delay of any magnitude can be generated by
looping suitable instructions a required number of time. Any way, keep one thing in
mind
that software delay is not very accurate because we cannot exactly predict how much
time its takes for executing a single instruction. Generally an instruction will be
executed
 in the theoretical amount of time but some times it may advance or retard due to
other
reasons. Therefore it is better to use  8051 Timer for generating delay in time
critical
applications. How ever software delay routines are very easy to develop  and well
enough
for less critical and simple applications.
Using software delay subroutines square waves over a wide frequency range
(limited by the crystal frequency) can be produced using 8051. The idea is very
simple,
run a  subroutine with delay equal to half the time period of the square wave,
complement any port pin after the delay routine is finished, repeat the delay
subroutine
again, complement the same port pin again and repeat the cycle again and again over
time. This will result in a square wave of the required frequency at the
corresponding port
pin. Circuit diagram for generating square wave using 8051 is shown below. The same
circuit can be used for generating any frequency but the program is different.

Square wave generation using 8051

Algorithm: 1. Load the count value in a register for outer loop


2. Load the count value in an another register for inner loop
3. decrement inner count
4. check whether the inner count is zero or not
5. if not go to step 3
6. yes, decrement outer count
7. check whether the outer count is zero or not
8. if not go to step 2
9. yes, terminate the program
The amount of delay depends on count value loaded.

CALCULATI
ON
For Delay

Assume clock frequency= 12MHz


Oscillator period = 1/12 MHz
1 machine cycle = (1/12 MHz)*12 = 1µs (because each machine cycle has 12 oscillator
periods)
Total Delay = 1 µs * ( no of machine cycles required to execute delay program
instructions)
Here we will create an inner loop of 1ms. This will be inside an outer loop which
will
repeat 20 times. Hence we get a delay of 20x 1msec= 20msecs.
Notice that in larger delay routines, the delay time is “approximate” as we ignore
the
delay caused due to the first and last instructions of the loop.
Delay program can be single loop /nested loop configuration. To increase the delay

nested loop configuration is used. By knowing the execution time for each
instruction,
delay programs to generate different delays can be created.
MOV R1,#255 ; 1 MACHINE CYCLE
LOOP1: NOP ;1 MACHINE CYLCE
DJNZ R1,LOOP1 ;2 MACHINE CYCLES

Max delay= 1us[3*255+1]=765us=0.765ms


0.765ms* P= 20ms
P=26 (i.e. Outer loop count value)
Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.
PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

PRO4: Create a source file (using File->New), type in the assembly or C


program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO5:
Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an
error free, to build go to Debug mode.

PRO6:
Now user can enter into Debug mode with Debug- Start / Stop
Debug session dialog. Or by clicking in the icon.

PRO7:
The program is run using the Debug-Run command & halted
using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor). Waveform is seen using a Logic analyser in Keil.

Flowchart: Students will draw the Flowchart on left side the sheet.
Result and
Discussion:

20ms
20ms

Conclusion:

Related
discussion
questions

1. Differentiate between software delay and hardware delay


2. What is maximum delay we can create with 8 bit value loaded in register?
3. Find the maximum delay that can be obtained with this considering 12MHz
crystal frequency.
MOV R1,#255
HERE: NOP
NOP
NOP
NOP
DJNZ R1,HERE
END
4. Assume A= 25H before the execution of instructions
Find the contents of A after the execution of the following instructions.
1) ORL A, #75H
2) XRL A, #0F5H
3) ANL A, #23H

exp5

Aim: To Write and Execute an Assembly language program for 8051to transmit data

“MORNING” serially at the baud rate of 9600

Objective: The main objective is to understand the serial communication facility


that the 8051

provides and how we can use it.


To learn Baud rate setting and serial communication operation to transmit as well
as
receive the data bit by bit using serial communication pins

Apparatus: Software: Keil µvision 5


Theory: 8051 has built in UART with RXD (serial data receive pin) and TXD (serial
data transmit

pin) on PORT3.0 and PORT3.1 respectively.


Asynchronous serial communication is widely used for byte oriented transmission.
Frame structure in Asynchronous communication:
 START bit: It is a bit with which serial communication start and it is always
low.
 Data bits packet: Data bits can be 5 to 9 bits packet. Normally we use 8 data bit
packet, which is always sent after START bit.
 STOP bit: This is one or two bits. It is sent after data bits packet to indicate
end of
frame. Stop bit is always logic high.
In asynchronous serial communication frame, first START bit followed by data byte
and at
last STOP bit, forms a 10-bit frame. Sometimes last bit is also used as parity bit.
8051 Serial Frame Structure:

Data transmission rate:


Data transmission rate is measured in bits per second (bps). In binary system it is
also
called as baud rate (number of signal changes per second). Standard baud rates
supported are 1200, 2400, 4800, 19200, 38400, 57600, and 115200. Normally most of
the
time 9600 bps is used when speed is not a big issue.
Serial communication Registers
SBUF: Serial Buffer Register
This is the serial communication data register used to transmit or receive data
through it.

SCON: Serial Control Register


Serial control register SCON is used to set serial communication operation modes.
Also it
is used to control transmit and receive operations.
 
Bit 7:6 - SM0:SM1: Serial Mode Specifier
Mode SM0 SM1 Mode
0 0 0 1/12 of Osc frequency shift register mode fixed baud rate
1 0 1 8-bit UART with timer 1 determined baud rate
2 1 0 9-bit UART with 1/32 of Osc fixed baud rate
3 1 1 9-bit UART with timer 1 determined baud rate

Algorithm: 1) Configure Timer 1 in mode 2 for generating the baud rate clock

2) Configure the SCON register for mode1


3) load the initial count value in TH1
4) Move the databyte in SBUF
5) Start timer T1
6) Monitor the TI flag bit to verify if transmission is over
7) The data will be sent out through TxD pin at the rate decided by the baud
8) Clear TI
9) If another Byte is to be transmitted, go to step 5

CALCULATI
ON
For Baud
rate

Baud Rate =

Baud Rate =
SMOD= Baud Rate Doubler bit available in PCON reg
F CLK = Oscillator Frequency
TH1= Timer1 Auto-reload Value
Baud Rate for SMOD:

Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.
PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

PRO4: Create a source file (using File->New), type in the assembly or C


program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO5:
Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an
error free, to build go to Debug mode.

PRO6:
Now user can enter into Debug mode with Debug- Start / Stop
Debug session dialog. Or by clicking in the icon.

PRO7:
The program is run using the Debug-Run command & halted
using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor).
Transmission of text ”HAPPY” can be seen on serial window.

exp 6 Experiment No.-6


Aim: Interfacing of LED and Write an assembly level program in 8051 to generate
square wave

of particular frequency or the LED blinking program using built in Timers.

Objective: The main objective is to study timers to generate delays and learn the
LED interfacing to
8051 and write a software to create square wave of particular frequency using built
in
Timer0/Timer1.
To learn 8051 instructions used and understand the use of them in writing the
program .

Apparatus: Software: Keil µvision 5, Proteus 8


Theory: Light Emitting Diodes or LEDs are the mostly commonly used components in
many
applications. They are made of semiconducting material. ommonly, used LEDs will
have
voltage drop of 1.7v and current of 10mA to glow at full intensity. This is applied
through
the output pin of the micro controller.
There are two ways which we can interface LED to the Microcontroller 8051. But the
connections and programming techniques will be different. 

The resistor is important in LED interfacing to limit the flowing current and avoid
damaging the LED and/or MCU.
 Interface 1 will glow LED, only if the PIN value of the MC is HIGH as current
flows
towards the ground.
 Interface 2 will glow LED, only if the PIN value of the MC is LOW as current
flows
towards PIN due to its lower potential.
Algorithm: 1. Load the mode control word in the TMOD register
2. Load the initial value of count in timer register
3. Enable the Timer to operate
4. Wait for the overflow until the Timer flag is set (keep on checking status timer
flag bit)
5. Stop the Timer operation
6. if this sequence is to be repeated, clear timer flag bit ,reload the timer
register and go
to step 3
7. Repeat the process

CALCULATI
ON for
DELAY

Assume clock frq= 12MHz


Since C/T = 0, the clock source to Timer 1 = oscillator freq/12 = 12MHz/ 12 = 1 MHz
Clock period = 1/ clock frq to Timer section = 1µs
Square wave freq= 2KHz
Period of Square wave to be generated = 1/ square wave freq = 1/2KHz = 500 µs
Duration of High / Low portion of the pulse= period of square wave/2 = 250 µs
Delay to be generated = Duration of High/ Low of square wave = 250µs
For a particular delay for example 250µs,

1 µs= 1 count
250 µs= 250 counts

No. of Counts = 250µs/clock period = 250µs/1µs = 250


Timer register value (TH1 and TL1)= 65536- 250= 65286d= FF06h to create a square
wave
of 2 KHz Freq

Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.
PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

PRO4: Create a source file (using File->New), type in the assembly or C


program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO 5:

PRO6:
Go to Flash -> Configure Flash tools. There select output
window. In that click on Create HEX file so that Hex file will be
created while build the project which would be useful in
downloading the program file into 8051 program memory. We
can do the whole circuit implementation using Proteus 8
software.
Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an

error free, to build go to Debug mode.

PRO7:
Now user can enter into Debug mode with Debug- Start / Stop
Debug session dialog. Or by clicking in the icon.

PRO8:
The program is run using the Debug-Run command & halted
using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor). Simulation of LED blinking can be seen on Parallel
Port2 window.
The better simulation results can be obtained by designing
whole circuitry in Proteus 8.11.

exp 7

Experiment No.-7
Aim: Interfacing of 7-Segment display and Write an assembly level program in 8051
for decimal

up counter from 0 to 9

Objective: The main objective is to study 7-segment display device and learn the 7-
segment

interfacing to 8051 and write a software to display up counter.


To learn 8051 instructions used for accessing lookup table and understand the use
of
them in writing the program.
Apparatus: Software: Keil µvision 5, Proteus 8
Theory: A seven segment display consists of seven LEDs arranged in the form of a
squarish ‘8’ slightly inclined to the right and a single LED as the dot character.
Different
characters can be displayed by selectively glowing the required LED segments. Seven
segment displays are of two types, common cathode and common anode. In common
cathode type , the cathode of all LEDs are tied together to a single terminal which
is
usually labeled as ‘com‘   and the anode of all LEDs are left alone as individual
pins labeled
as a, b, c, d, e, f, g &  h (or dot) . In common anode type, the anode of all
LEDs are tied
together as a single terminal and cathodes are left alone as individual pins. The
pin out
scheme and picture of a typical 7 segment LED display is shown in the image below.

7-segment display

Digit drive pattern: Digit drive pattern of a seven segment LED display is simply
the
different logic combinations of  its  terminals ‘a’ to ‘h‘ in order to display
different digits
and characters. The common digit drive patterns (0 to 9) of a common cathode seven
segment display are shown in the table below.

DIGIT Dot g f e d c b a HEX


VALUE
0 0 0 1 1 1 1 1 1 0x3f
1 0 0 0 0 0 1 1 0 0x06
2 0 1 0 1 1 0 1 1 0x5b
3 0 1 0 0 1 1 1 1 0x4f
4 0 1 1 0 0 1 1 0 0x66
5 0 1 1 0 1 1 0 1 0x6d
6 0 1 1 1 1 1 0 1 0x7d
7 0 0 0 0 0 1 1 1 0x07
8 0 1 1 1 1 1 1 1 0x7f
9 0 1 1 0 0 1 1 1 0x67

Algorithm: The software part must do the following tasks.


 Initialize the accumulator
 Initialize the counter for 0 to 9 display with a predetermined delay (around 1/2
second here).
 Access the Look Up Table to get corresponding digital drive pattern by converting
the current count into digit drive pattern
 Put the current digit drive pattern into a port for displaying.
 Call delay after the display of each decimal no.
 If Acc=0? If yes jump to the initial state of counter i.e. display of 0
 If not, display the next digit.

Circuit
Diagram:

Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.
PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

PRO4: Create a source file (using File->New), type in the assembly or C


program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO 5:

PRO6:
Go to Flash -> Configure Flash tools. There select output
window. In that click on Create HEX file so that Hex file will be
created while build the project which would be useful in
downloading the program file into 8051 program memory.
Whole circuit is implemented using Proteus 8 software.
Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an
error free, to build go to Debug mode.

PRO7: Now user can enter into Debug mode with Debug- Start / Stop
Debug session dialog. Or by clicking in the icon.

PRO8:

PRO9:

The program is run using the Debug-Run command & halted


using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor). Simulation of 7Seg display can be seen on Parallel
Port1 window.
Open Proteus 8. Pick the components required and design the
whole circuitry. Open the Hex File and download it onto the
microcontroller. Run the simulation.

Flowchart: Students will draw the Flowchart on left side the sheet.
Result and
Discussion:

Conclusion:

exp 8

Experiment No.-8
Aim: Interfacing of LCD and Write an assembly level program in 8051 to display a
word “ELEX”

on LCD

Objective: The main objective is to study LCD module and its pin functions. Learn
the LCD interfacing

to 8051 and write a software to display a word “ELEX” on LCD.


To learn 8051 instructions used and understand the use of them in writing the
program.

Apparatus: Software: Keil µvision 5, Proteus 8


Theory: 16×2 LCD module is a very common type of LCD module that is used in 8051
based
embedded projects. It consists of 16 rows and 2 columns of 5×7 or 5×8 LCD dot
matrices.
The module were are talking about here is type number JHD162A which is a very
popular
one . It is available in a 16 pin package with back light ,contrast adjustment
function and
each dot matrix has 5×7 dot resolution.
The JHD162A has two built in registers namely data register and command register.
Data
register is for placing the data to be displayed , and the command register is to
place the
commands. The 16×2 LCD module has a set of commands each meant for doing a
particular job with the display.

VEE pin is meant for adjusting the contrast of the LCD display and the contrast can
be
adjusted by varying the voltage at this pin. 
R/W pin is meant for selecting between read and write modes. High level at this pin
enables read mode and low level at this pin enables write mode.
E pin is for enabling the module. A high to low transition at this pin will enable
the
module.
DB0 to DB7 are the data pins. The data to be displayed and the command
instructions are
 placed on these pins.
LED+ is the anode of the back light LED and this pin must be connected to Vcc
through a
suitable series current limiting resistor. LED- is the cathode of the back light
LED and this
pin must be connected to ground.
High logic at the RS pin will select the data register and  Low logic at the RS pin
will select
the command register. If we make the RS pin high and the put a data in the 8 bit
data line
(DB0 to DB7) , the LCD module will recognize it as a data to be displayed .  If we
make RS
pin low and put a data on the data line, the module will recognize it as a command.
An LCD module can be interfaced with a microcontroller either in 8 bit mode (as
seen
above) or in 4 bit mode. 8 bit mode is the conventional mode which uses 8 data
lines and

RS, R/W, E pins for functioning. However 4 bit mode uses only 4 data lines along
with the
control pins. This will saves the number of GPIO pins needed for other purpose. 

Algorithm: LCD initialization.

The steps that has to be done for initializing the LCD display is given below and
these
steps are common for almost all applications.
 Send 38H to the 8 bit data line for initialization
 Send 0EH for making LCD ON, cursor ON and cursor blinking ON.
 Send 06H for incrementing cursor position.
 Send 01H for clearing the display and return the cursor.
 Send 80H to force cursor at the beginning of 1 st Line.
Sending data to the LCD.
The steps for sending data to the LCD module is given below. The LCD module has
pins
namely RS, R/W and E. It is the logic state of these pins that make the module to
determine whether a given data input  is a command or data to be displayed.
 Make R/W low.
 Make RS=0 if data byte is a command and make RS=1 if the data byte is a data to
be displayed.
 Place data byte on the data register.
 Pulse E from high to low.
 Repeat above steps for sending another data.

Circuit
Diagram:

Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.

PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

PRO4: Create a source file (using File->New), type in the assembly or C


program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO 5: Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an
error free, to build go to Debug mode.

PRO6: Now user can enter into Debug mode with Debug- Start / Stop
Debug session dialog. Or by clicking in the icon.

PRO7:

PRO8:
The program is run using the Debug-Run command & halted
using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor). Simulation of LCD display can be seen on parallel
port P1.
Open Proteus 8. Pick the components required and design the
whole circuitry. Open the Hex File and download it onto the
microcontroller. Run the simulation.

exp 9

Experiment No.-9
Aim: To write and execute an Assembly Language Program to generate two square
waveforms
of particular frequency simultaneously on P3.0 and P3.1 as well third activity i.e.
taking
the data from two ports P0 and P1 continuously, comparing them and setting the pin
P2.5
if they are not equal or clearing them if they are equal using 8051
microcontroller.
Objective: The main objective is to study 8051 Interrupts and use them to generate
two square
waveforms of frequency simultaneously on port pins as well as performing third
activity
by processor.
To learn 8051 instructions used and understand the use of them in writing the
program

Apparatus: Software: Keil µvision 5


Theory: In Timer section Polling method was used to check the timer flag bit
status. In the
interrupt driven method, when the timer flag is set, an interrupt is also
activated, that is
control goes to the interrupt vector of the timer and the ISR written therein is
run.
The ISR is very small-it is just one instruction to complement P2.0/P2.1. So, it is
written in
the interrupt vector area itself. If it had been bigger, a jump instruction to
another
location would have been necessary.
In the main program which is at ROM location 0040H, the Timer and Interrupt
initialization instructions are written. Once timer starts, no other activity is
done by the
processor. It simply waits in a loop using the instruction
HERE: SJMP HERE

In course of this waiting, the timer flags get set and then waiting is exited and
the
instructions in the ISR’s are executed. The last instruction in the ISR is RETI
which takes
control back to the main program instruction SJMP HERE.
Instead of simply waiting, the processor can be made to do something else. A Port
based
program can be made run along with the running of the both the Timers. This is the
charm of using Interrupts. The processor is not stuck with doing just one program.
A
number of tasks can be doen simultaneously if separate hardware is available for
each of
them, Here the CPU does the Port program, while both timers are kept running by
virtue
of it having specific hardware for that job.
Note: In Interrupt Mode, both timers can work independently. In polled mode this is
difficult as the CPU is in a loop, polling the flag of one timer.

Algorithm: 1. Configure TMOD for T1 and T0 in mode 2


3. Write IE register with the appropriate control word
4. Write the count in Timer registers THO and TH1
5. Start the Timer1 and Time2
6. When TF0 is set, interrupt occurs and program control jumps to the vector
address
000BH
7. When TF1 is set, interrupt occurs and program control jumps to the vector
address
001BH
8. The ISR therein is executed. That is complement the port pins P2.0/P2.1. The
last

instruction in the ISR is RETI and then control returns to the main program
9. Once the control branches to the interrupt vector, TF0/TF1 is automatically
cleared.
10. That is how it generates two square waves on P2.0 and P2.1 using interrupt
mode.
11. Meanwhile processor will be busy in performing third activity as follows.
1. Set the Ports P1 and P0 as input ports
2. Read the data from P1 and P0
3. Compare both the data and if they are not equal set the pin P2.5 or clear the
pin P2.5 if
they are equal.

Procedure:

PRO1: Double Click on the  icon on the desktop.


PRO2: Close any previous projects that were opened using – Project ->
Close.
PRO3: Start Project – New Project, and select the CPU from the device
database (Database-Atmel- AT89C51 or AT89S51 as per the
board).On clicking ‘OK’, the following option is displayed.
Choose ‘No’.

PRO4: Create a source file (using File->New), type in the assembly or C


program and save this (filename.asm/filename.c) and add this
source file to the project using either one of the following two
methods. (i) Project->Manage->Components, Environment
Books->addfiles-> browse to the required file ->OK
“OR” ii) right click on the Source Group in the Project Window
and the Add Files to Group option.

PRO 5: Build the project; using Project -> Build Project. Keil µvision
translates all the user application and links. Any errors in the
code are indicated by – “Target not created” in the Build
window, along with the error line. Debug the errors. After an
error free, to build go to Debug mode.

Now user can enter into Debug mode with Debug- Start / Stop

PRO6:
Debug session dialog. Or by clicking in the icon.

PRO7:
The program is run using the Debug-Run command & halted
using Debug-Stop Running. Also the (reset, run, halt) icons can
be used. Additional icons are (step, step over, and step into, run
till cursor). Simulation of two waveforms generation can be
seen on Logic Analyzer.

You might also like