Professional Documents
Culture Documents
Labmanual PDF
Labmanual PDF
Labmanual PDF
Prepared by
S.Sreedhar Babu Assoc.prof[ece],
(COURSE COORDINATOR)
KONERU LAKSHMAIAH
UNIVERSITY
2012-13.
List of Experiments
Cycle - I: The following Programs/Experiments are to be written for the assembler
Using TASM software.
1. Programs on Data Transfer in forward and reverse direction using 8086.
2. Programs on Arithmetic Instructions with 16-bit data using 8086.
3. Programs on logical Instructions using 8086.
4. Programs on String manipulation using 8086.
5. Programs on Sorting and searching an array using 8086.
6. Programs on Procedures and Macros for BCD to Binary conversion, factorial
using 8086.
7. Programs on Interrupts for using 8086.
Cycle – II: Interfaced with 8051 using Machine language program and some
Programs/Experiments are to be written for the assembler using TOP VIEW SIMULATOR
software for the interfacing.
8. Programs on Arithmetic, Logic& Bit manipulation Instructions 8051.
9. Interfacing 7-Segment Display 8051.
10. LCD Interfacing to 8051.
11. Interfacing of Binary Counters 8051.
12. Interfacing Stepper Motor 8051.
13. Interfacing A/D & D/A to 8051
14. Keyboard Interface 8051.
15. Data Transfer between two PCs using RS.232 C Serial Port.
ASSEMBLER
An assembler program is used to translate the assembly language mnemonics for instructions to the
corresponding binary codes. When you run the assembler, it reads the source file of your Program the disk,
where you saved it after editing on the first pass thro ugh the source program the assembler determines the
displacement of named data items, the offset of labels and pails this information in a symbol table. On the
second pass through the source program, the assembler produces the binary code for each instruction and
inserts the offset etc that is calculated during the first pass. The assembler generates two files on floppy or
hard disk. The first file called the object file is given the extension. OBJ. The object file contains the binary
codes for the instructions and information about the addresses of the instructions. The second file generated
by the assembler is called assembler list file. The list file contains your assembly language statements, the
binary codes for each instructions and the offset for each instruction. In TASM assembler, TASM source file
name ASM is used to assemble the file. Edit source file name LST is used to view the list file, which is
generated, when you assemble the file.
LINKER
A linker is a program used to join several object files into one large object file and convert to an exe file.
The linker produces a link file, which contains the binary codes for all the combined modules. The linker
however doesn’t assign absolute addresses to the program, it assigns is said to be relocatable because it can
be put anywhere in memory to be run. In TASM, TLINK source filename is used to link the file.
DEBUGGER
A debugger is a program which allows you to load your object code program into system memory, execute
the program and troubleshoot are debug it the debugger allows you to look at the contents of registers and
memory locations after your program runs. It allows you to change the contents of register and memory
locations after your program runs. It allows you to change the contents of register and memory locations and
return the program. A debugger also allows you to set break point at any point in the program. If you inset a
breakpoint the debugger will run the program upto the instruction where the breakpoint is set and stop
execution. You can then examine register and memory contents to see whether the results are correct at that
point. In TASM, td filename is issued to debug the file.
DEBUGGER FUNCTIONS
1. Debugger allows to look at the contents of registers and memory locations.
2. We can extend 8-bit register to 16-bit register which the help of extended register option.
3. Debugger allows to set breakpoints at any point with the program.
4. The debugger will run the program upto the instruction where the breakpoint is set and then stop
execution of program. At this point, we can examine registry and memory contents at that point.
5. With the help of dump we can view register contents.
6. We can trace the program step by step with the help of F7.
7. We can execute the program completely at a time using F8.
DEBUGGER COMMANDS
ASSEMBLE:
To write assembly language program from the given address.
A starting address <cr>
Eg: a 1000H <cr>
Starts program at an offset of 1000H.
DUMP:
To see the specified memory contents
D memory location first address last address
(While displays the set of values stored in the specified range, which is given above)
Eg: d 0100 0105 <cr>
Display the contents of memory locations from 100 to 105(including).
ENTER:
To enter data into the specified memory locations(s).
E memory location data data data data data …<cr>
Eg: e 1200 10 20 30 40 ….
Enters the above values starting from memory locations 1200 to 1203, by loading 10 into
1200, 20 into 1201 and soon.
GO:
To execute the program
G: one instruction executes (address specified by IP)
G address <cr>: executes from current IP to the address specified
G first address last addresses <cr>: executes a set of instructions specified between the given address.
MOVE:
Moves a set of data from source location to destination location
M first address last address destination address
Eg: m100 104 200
Transfers block of data (from 100 to 104) to destination address 200.
QUIT:
To exit from the debugger.
Q <cr>
REGISTER:
Shows the contents of Registers
R register name
Eg: r ax
Shows the contents of register.
TRACE:
To trace the program instruction by instruction.
T = 0100 <cr>: traces only the current instruction. (Instruction specified by IP)
T = 0100 02 <cr>: Traces instructions from 100 to 101, here the second argument spec ifies the number of
instructions to be traced.
UNASSEMBLE:
To unassembled the program. Shows the opcodes along with the assembly language program.
U 100 <cr>: unassembled 32 instructions starting from 100th location.
U 0100 0109 <cr>: unassembles the lines from 100 to 104.
Using Turbo – Assembler – Linker – Debugger
(TASM, TLINK, TD)
Program:
RESULT: AL: 09
b) AIM : Subtraction of two 8-bit numbers using immediate addressing mode.
Program:
RESULT: AL: 01
(c) AIM : Multiplication of two 8-bit numbers using immediate addressing mode.
RESULT : AL
d) AIM : Division of two 8-bit numbers using immediate addressing mode.
Program:
RESULT : AX=
Input:-
Location Data
1700 88
1701 00
1702 44
1703 00
f) AIM : Subtraction of two 16-bit numbers using direct addressing mode.
Program:
RESULT : AX=
Input:-
Location Data Out put :
1700 88
1701 00
1702 44
1703 00
Program:
Input:-
Location Data
1700 04
1701 04
Output :-
1800 08
RESULT :
Input:-
Location Data
1700 09
1701 04
Output :-
1800 05
Ex.No.1 DATA TRANSFER Date:
Aim:
A. Write an ALP to transfer the data stored in consecutive memory locations, in the forward direction.
B. Write an ALP to transfer the data stored in consecutive memory locations, in the reverse direction.
C. Write an ALP to transfer the data stored in consecutive memory locations, in the forward direction
overlapping.
Software Used:
Computer system with TASM.
PROGRAM:
A. Forward Direction
DATA SEGMENT
ORG 2000H
ARR1 DB 0H,1H,2H,3H,4H,5H,6H,7H,8H,9H
ORG 3000H
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
MOV [DI], AH
INC SI
INC DI
LOOP BACK
INT21H
CODE ENDS
END START
B.Reverse Direction
DATA SEGMENT
ORG 2000H
ARR1 DB 0H,1H,2H,3H,4H,5H,6H,7H,8H,9H
ORG 3000H
DATA ENDS
CODE SEGMENT
MOV DS, AX
MOV [DI], AH
INC SI
DEC DI
LOOP BACK
MOV AH, 4CH
INT21H
CODE ENDS
END START
DATA SEGMENT
ORG 2000H
ARR1 DB 0H,1H,2H,3H,4H,5H,6H,7H,8H,9H
ORG 3000H
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
MOV [DI], AH
INC SI
INC DI
LOOP NXTP
MOV [DI], AH
INC SI
INC DI
LOOP AGAIN
INT21H
CODE ENDS
END START
Result: Data stored in consecutive memory locations is transferred from 2000h memory
location to 3000h memory location (a) in the forward direction (i.e. in the same order), (b) in
the reverse direction and (c) with overlapping in the forward direction.
Ex.No.2 ARITHMETIC OPERATIONS Date:
Aim:
A. Write an ALP to perform addition on 16-bit data stored in consecutive memory
locations and store the result from the next location onwards.
B. Write an ALP to perform subtraction on 16-bit data stored in consecutive memory
locations and store the result from the next location onwards.
C. Write an ALP to perform multiplication on 16-bit data stored in consecutive memory
locations and store the result from the next locations onwards.
D. Write an ALP to perform division on 16-bit data stored in consecutive memory
locations and store the result from the next location onwards.
Software Used:
Computer system with TASM.
PROGRAM:
A. Addition
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
ADDEND DW 8765H
ADDER DW 9876H
SUM DW 0H
CARRY DB 0H
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV AX, ADDEND
ADD AX, ADDER
JNC SKIP
INC CARRY
SKIP: MOV SUM, AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
B. Subtraction
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
SUBTRAHEND DW 8765H
SUBTRACTOR DW 9876H
DIFFERENCE DW 0H
BARROW DB 0H
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
MOV AX,SUBTRAHEND
INC BARROW
INT 21H
CODE ENDS
END START
C.Multiplication
CODE ENDS
END START
D.Division
DATA SEGMENT
ORG 2000H
DIVIDEND DW 8765H
DIVISOR DW 1234H
QUOTIENT DW 0H
REMAINDER DW 0H
DATA ENDS
CODE SEGMENT
MOV DS, AX
DIV BX
MOV QUOTIENT, AX
MOV REMAINDER, DX
CODE ENDS
END STAR T
Result:- An ALP is written to perform a) addition, (b) subtraction, (c) multiplication and (d)
division operations using arithmetic instructions and the same is verified.
Ex.No.3 LOGICAL OPERATIONS Date:
Aim:
A. Write an ALP to find number of 1’s in a given word.
B. Write an ALP to find the number of even and odd numbers in the given array.
C. Write an ALP to find the number of elements in the array having “1” in their 5th bit position.
Software Used:
Computer system with TASM.
PROGRAM:
A. Number of 1’s in a word
DATA SEGMENT
ORG 2000H
NUM DW 5464
BITCOUNT DB 0H
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
JNC GO
INC BITCOUNT
GO: DEC CL
JNZ NXTP
CODE ENDS
END START
DATA SEGMENT
ORG 2000H
SERIES DW 3456H,4533H,1234H,1567H,0FFFFH,145AH,56D7,4E34H,3421H,
89C5H
ODDCOUNT DB 00H
EVENCOUNT DB 00H
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
JC ODD
INC EVENCOUNT
JMP OTHER
OTHER: INC SI
DEC CL
JNZ NXTP
CODE ENDS
END START
DATA SEGMENT
ORG 2000H
SERIES DB 21H,54H,05H,34H,32H,14H,18H,17H,53H,58H
BITCOUNT DB 00H
DATA ENDA
CODE SEGMENT
ORG 1000H
MOV DS, AX
JZ GO
INC BITCOUNT
GO: INC SI
DEC CL
JNZ NXTP
INT 21H
CODE ENDS
END START, Result: Logical operations such as Shift, rotate and test are used to find the a) no. of
1’s in the given byte, b) no. of even and add numbers, c)no. of positive and negative numbers and d)
no. of elements having 1’s in their 5th bit position.
Aim:
A. Write an ALP to transfer the data in forward direction using string instructions.
B. Write an ALP to transfer the data in reverse direction using string instructions.
Software Used:
Computer system with TASM.
PROGRAM:
A. Forward Direction using String Instructions
ASSUME DS: DATA, CS: CODE, ES: EXTRA
DATA SEGMENT
ORG 2000H
STRING1 DB 'MICROPROCESSOR'
DATA ENDS
EXTRA SEGMENT
ORG 3000H
EXTRA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
MOV ES, AX
REP MOVSB
MOV AH, 4CH
INT 21H
CODE ENDS
END START
DATA SEGMENT
ORG 2000H
STRING1 DB 'MICROPROCESSOR'
LENGTH_STRING DW $-STRING1
DATA ENDS
EXTRA SEGMENT
ORG 3000H
EXTRA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
MOV ES, AX
ADD DI, CX
DEC DI
BACK: MOVSB
SUB DI, 02H
LOOP BACK
INT 21H
CODE ENDS
END START
Aim:
A. Write an ALP to sort the given array in signed ascending order.
B. Write an ALP to sort the given array in unsigned descending order.
C. Write an ALP to find the maximum and the minimum element in the given array.
Software Used:
Computer system with TASM.
PROGRAM:
A. Signed ascending order
ASSUME DS: DATA, CS: CODE
DATA SEGMENT
ORG 3000H
ARRAY DB 03H,07H,05H,01H,09H,04H,06H,02H,08H
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
DEC DX
CMP AL,[SI+01]
JNZ SKIP
SKIP: INC SI
LOOP BACK
DEC DX
JNZ BEGIN
INT 21H
CODE ENDS
END START
DATA SEGMENT
ORG 3000H
ARRAY DB 03H,07H,05H,01H,09H,04H,06H,02H,08H
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
DEC DX
CMP AL,[SI+01]
JNB SKIP
SKIP: INC SI
LOOP BACK
DEC DX
JNZ BEGIN
INT 21H
CODE ENDS
END START
DATA SEGMENT
ORG 2000H
MAX_NO DW 0H
MIN_NO DW 0H
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
MOV BX, AX
BACK: INC SI
INC SI
JMP NEXT
JC NEXT
MOV BX, [SI]
MOV MAX_NO,AX
MOV MIN_NO, BX
INT 21H
CODE ENDS
END START
Result: Sorting the array in a) signed ascending order, b) unsigned descending order and c)
searching for the maximum and minimum elements in the unsigned array, are implemented.
Ex.No.6 PROCEDURE AND MACROS Date:
Aim:
A. Write an ALP to convert Hexadecimal numbers to BCD numbers.
B. Write an ALP to find the factorial of given number.
Software Used:
Computer system with TASM.
Flow Chart:
PROGRAM
A. Hexadecimal to BCD conversion
ASSUME DS: DATA, CS: CODE
DATA SEGMENT
ORG 2000H
COUNT EQU 04
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
MOV [DI], AL
INC DI
MOV AL, AH
XOR AH, AH
DIV BH
MOV [DI], AL
INC DI
MOV [DI], AH
INC SI
INC DI
LOOP BACK
CALL UP2P
INT 21H
MOV CH,COUNT
FACTORIAL MACRO
XOR CX, CX
XOR AX, AX
INC AX
CMP CL, 0
JE GO
REPEAT: MUL CX
LOOP REPEAT
ENDM
DATA SEGMENT
ORG 2000H
NUMBER DB 08H
FACT DW 0
DATA ENDS
CODE SEGMENT
MOV DS, AX
FACTORIAL
INT 21H
CODE ENDS
END START
Result: Programs on a) Procedure for converting Hexadecimal numbers to packed BCD and b)
Macro for finding the factorial of a given number are implemented.
Ex.No.7 INTERRUP TS Date:
Aim:
A. Write an ALP to find whether the given string is a palindrome or not.
B. Write an ALP to enter the string through keyboard and display it.
Software Used:
Computer system with TASM.
PROGRAM:
A. String is palindrome or not
DATA SEGMENT
ORG 2000H
STRING DB 'RADAR'
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV DS, AX
MOV DI, SI
SHR CX, 1
BACK: MOV AL, [SI]
JNZ NEXT
INC SI
DEC DI
LOOP BACK
INT 21H
INT 21H
CODE ENDS
END START
DATA SEGMENT
ORG 2000H
INPUT DB “ENTER THE STRING”, 0DH, 0AH, “$”
OUTPUT DB “THE ENTERED STRING IS:” 0DH, 0AH, “$”
S_LENTH DB 0
BUFFER DB 80 DUP (0)
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
XOR CL, CL
LEA DX, INPUT
MOV AH, 09H
INT 21H
LEA BX, BUFFER
REPEAT: MOV AH, 01H
INT 21H
CMP AL, 0DH
JZ EXIT
INC CL
MOV [BX], AL
INC BX
JMP REPEAT
EXIT: MOV S_LENTH, CL
LEA BX, BUFFER
ADD BL, CL
MOV AL,’$’
MOV [BX], AL
LEA DX, OUTPUT
MOV AH, 09H
INT 21H
LEA DX, BUFFER
MOV AH, 09H
INT 21H
CODE ENDS
ENDF START
Result: Interrupts on a) whether the given string is a palindrome or not and b) entering the string through
keyboard and displaying the same, are verified.
8051 INTRODUCTION AND
INTERFACING WITH
PERIPHERALDEVICES
USING TOP VIEWIMULATOR
Ex.No.8 Arithmetic, Logic and Bit manipulation Instructions Date:
ORG 0000H
MOVX A,@DPTR
MOV B, A
DEC DPL
MOV A,@DPTR
ADD A, B
INC DPTR
INC DPTR
MOVX @DPTR, A
CLR A
ADDC A, #00H
INC DPTR
MOVX @DPTR, A
STOP: SJMP STOP
END
B.SUBTRACTION
$MOD51
ORG 0000H
MOVX A,@DPTR
MOV B, A
DEC DPL
MOVX @DPTR, A
CLR C
SUBB A,B
INC DPTR
INC DPTR
MOVX @DPTR, A
CLR A
ADDC A, #00H
INC DPTR.
MOVX @DPTR,A
END
C.MULTIPLICATION
$MOD51
ORG 0000H
MOVX A,@DPTR
MOV B, A
DEC DPL
MOVX A, @DPTR
MUL A B
INC DPTR
INC DPTR
MOVX @DPTR, A
MOV A, B
INC DPTR
MOVX @DPTR, A
END
D.DIVISION
$MOD51
ORG 0000H
MOV X A,@DPTR
MOV B, A
DEC DPL
MOVX A, @DPTR
DIV AB
INC DPTR
INC DPTR
MOVX @DPTR, A
MOV A, B
INC DPTR
MOVX @DPTR, A
END
D.SWAP
$MOD51
ORG 0000H
MOVX A, @ DPTR
SWAP A
INC DPTR
MOVX @ DPTR, A
END
E.RESET
$MOD51
ORG 0000H
CLR C
MOV A, ODOH
MOVX @ DPTR, A
END
F.SET
$MOD51
ORG 0000H
SETB C
MOV A,0D0H
MOVX @ DPTR, A
G.BIT
$MOD51
ORG 0000H
MOV A, ODOH
MOVX @ DPTR, A
CPL C
MOV A, ODOH
INC DPTR
MOVX @DPTR, A
END
H.BYTE
$MOD51
ORG 0000H
MOVX A @ DPTR
CPL A
INC DPTR
MOVX @ DPTR, A
END
I.COMPLIMENT
$MOD51
ORG 0000H
MOV DPTR,#0101H
MOVX A,@DPTR
CPL A
INC DPTR
MOVX @DPTR,A
END
Result: All the Arithmetic and special instruction operations are performed by using 8051.
Ex. No 9 Interfacing of 7 – Segment Displays Date:
Problem statement:
Select control lines and port lines as shown in the below table.
Digit2 A P1.0
Digit2 B P1.1
Digit2 C P1.2
Digit2 D P1.3
Digit2 Dp GND
Digit1 A P1.4
Digit1 B P1.5
Digit1 C P1.6
Digit1 D P1.7
Digit1 Dp GND
Circuit:
Digit2
P1.0 A 7
P1.4 A A
BCD to 7 7
P1.5 BB SEG SEG
P1.6 C C
P1.7 D
PROGRAM
$MOD51
ORG 0000H
SJMP MAIN
ORG 0030H
MAIN:MOV A,#00H
AG AIN:MOV P1,A
LCALL DELAY
ADD A,#01
DA A
SJMP AGAIN
ORG 0040H
DELAY:MOV R2,0FFH
UP1:MOV R1,0FFH
UP2:NOP
NOP
NOP
DJNZ R1,UP2
DJNZ R2,UP1
RET
END
Simulated output:
Open LCD module settings to configure the LCD connections.( File-> External
modules settings-> LCD) Check with the summary window for correct
connections.
P2.0 RS
P2.1 RW
P2.2 E
Circuit:
P1.0 D0
LCD
controller
P1.7 D7
RS RW E
8051
P2.0
P2.1
P2.2
Flow Chart:
PROGRAM
$MOD51
RS EQU P3.1
EN EQU P3.2
RW EQU P3.3
ORG 0000H
MOV A,#38H
LCALL LCD_COMD
MOV A,#0EH
LCALL LCD_COMD
MOV A,#06H
LCALL LCD_COMD
MOV A,#01H
LCALL LCD_COMD
MOV A,#'E'
LCALL LCD_TEXT
MOV A,#'C'
LCALL LCD_TEXT
MOV A,#'E'
LCALL LCD_TEXT
LOOP:SJMP LOOP
LCD_COMD:CLR C
LCALL WRITE
RET
LCD_TEXT:SETB C
LCALL WRITE
RET
WRITE:SETB EN
CLR RW
MOV RS,C
MOV P1,A
CLR EN
LCALL DELAY
RET
DELAY:MOV R0,#60
LOOP2:MOV R1,#255
LOOP1:DJNZ R1,LOOP1
DJNZ R0,LOOP2
RET
END
Simulator Output:
Result:
Problem statement:
Flow Chart:
PROGRAM
$MOD51
CLR A
REPEAT:MOV P1,A
LCALL DELAY
INC A
SJMP REPEAT
DELAY:MOV R2,#0FFH
BACK:MOV R1,#0FFH
UP1:NOP
NOP
DJNZ R1,UP1
DJNZ R2,BACK
RET
END
Simulator Output:
Aim: Interface the stepper motor to 8051 target system and write program to operate in
different speeds both clock wise and anti clock wise directions.
CIRCUIT DESCRIPTION
The four winding of the motor is connected with PA0 to PA3 through buffer and driving
circuit. So, the Port A of 8255 will have to initializes in output mode.
HARDWARE INSTALLATION
1. Connect Stepper Motor interfacing module to 8255 – I of 8051 / 8085 Trainer Kit
through 26 pin FRC Cable.
2. Be sure about the direction of the cable i.e. Pin No.1 of module should be
connected to Pin No.1 of 8255 connector.
3. Connect +5V, GND from the trainer kit (+5V & GND signals are available in the
25 & 26 pin of FRC 8255 – I Connector).
4. Connect Motor Supply to +12V from the Trainer Kit.
Port A – FF00H
Port B –FF01H
Port C – FF02H
Procedure:
2. Assemble the source file using ASM51 cross Assembler and create LST & HEX files.
3.Configure the windows hyper terminal with a baud rate 9600 , 8 data bits, no parity, 1
stop bit and flow control XON / XOFF.
4. Establish a serial communication link between Host and Target system using hyper
terminal.
5. Down load the HEX file from the host to the target system.
6. Connect stepper motor interface module to the target system and run the program.
Program:
This program will move the motor in Clock wise direction. For Anti Clock wise
direction change F9, F5, F6, FA in place of FA, F6, F5, F9.
2011 11 1F ACALL
DELAY
2024 00 NOP
2025 00 NOP
202A 22 RET
Result:
The Stepper Motor is interfaced to 8051 and operated with different speeds and
directions.
8051 INTERFACING WITH
PERIPHERAL DEVICES
USING ASSEMBLY LANGUAGE
PROGRAM
BINARY COUNTER INTERFACING WITH 8051
AIM:
To interface Binary Counter 8051 parallel port to demonstrate the generation of convert a binary number to
a decimal.
APPARATUS REQUIRED;
LED’S
THEORY:
Before starting with counters there is some vital information that needs to be understood. The most
important is the fact that since the outputs of a digital chip can only be in one of two states, it must use a
different counting system than you are accustomed to. Normally we use a decimal counting system; meaning
each digit in a number is represented by one of 10 characters (0-9). In a binary system, there can only be two
characters, 0 and 1.
A computer does not recognize 0 or 1. It only works o n voltage changes. What we call logic 0 to a
computer is zero volts. What we call logic 1 is +5 volts. When a logic state changes from a zero to a one the
voltage at the pin in question goes from zero volts to +5 volts. Likewise, when a logic state changes from a
one to a zero the voltage is changing from +5 volts to zero volts.
When counting up in a decimal system, we start with the first digit. When that digit ‘overflows’, i.e. gets
above 9, we set it to 0 and add one to the next digit over. The same goes for a binary system. When the
count goes above 1 we add one to the next digit over and set the first digit to 0. Here is an example
0 0
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
9 1001
BINARY COUNTING
To convert a binary number to a decimal, we use a simple system. Each digit or ‘bit’ of the binary
number represents a power of two. All you need to do to convert from binary to decimal is add up the
applicable powers of 2. In the example below, we find that the binary number 10110111 is equal to 183. The
diagram also shows that eight bits make up what is called a byte. Nibbles are the upper or lower four bits of
that byte. Referring to nibbles and bytes are useful when dealing with other number systems such as
hexadecimal, which is base 16.
fig1. Interfacing
PROGRAM:
MOVX @DPTR, A
MOV A, #00H
INC A
MOVX @DPTR, A
LCALL DELAY
CJNE A, #FFH, START
XX: SJMP XX
DJNZ R1, CC
RET
Result:
Seven Segment Display Interfacing With 8051
AIM:
To interface Seven Segment Display to 8051 to generate a digit from 0 to 9 using common anode and
APPARATUS REQUIRED
8051 TRAINER
INTRODUCTION
For the seven segment display you can use the LT-541 or LSD5061-11 chip. Each of the segments of the
display is connected to a pin on the 8051 (the schematic shows how to do this). In order to light up a
segment on the the pin must be set to 0V. To turn a segment off the corresponding pin must be set to 5V.
This is simply done by setting the pins on the 8051 to '1' or '0'.
7-SEG Display is available in two types -1. Common anode & 2. Common cathode, but command anode
display is most suitable for interfacing with 8051 since 8051 port pins can sink current better than sourcing
it.
CREATING DIGIT PATTERN
For displaying Digit say 7 we need to light segments -a ,b, c. Since we are using Common anode display , to
do so we have to to provide Logic -0 (0 v) at anode of these segments.so need to clear pins- P1.0
,P1.1,P1.2. that is 1 1 1 1 1 0 0 0 -->F8h .
Segment Seg.
8051 pin number Digit Seg. h Seg. g Seg. f Seg. e Seg. d Seg. c Seg. a HEX
number b
a P1.0 0 1 1 0 0 0 0 0 0 C0
b P1.1 1 0 0 0 0 0 1 1 0 06
c P1.2 2 1 0 1 0 0 1 0 0 A4
d P1.3 3 1 0 1 1 0 0 0 0 B0
e P1.4 4 1 0 0 1 1 0 0 1 99
f P1.5
h(dp) P1.7
Segment Seg.
8051 pin number Digit Seg. h Seg. g Seg. f Seg. e Seg. d Seg. c Seg. a HEX
number b
a P1.0 0 0 0 1 1 1 1 1 1 3f
b P1.1 1 0 0 0 0 0 1 1 0 06
c P1.2 2 0 1 0 1 1 0 1 1 5b
d P1.3 3 0 1 0 0 1 1 1 1 4f
e P1.4 4 0 1 1 0 0 1 1 0 66
f P1.5
g p1.6
h(dp) P1.7 COMMON CATHODE
You can also do this for some characters like A, E. But not for D or B because it will be same
as that of 0 & 8 . So this is one of limitation of 7-seg display.
Since we can enable only one 7-seg display at a time, we need to scan these display at fast rate .The
scanning frequency should be high enough to be flicker- free. At least 30HZ .Therefore – time one digit is
ON is 1/30 seconds
INTERFACING
Note that I am using Common Anode display. So the common Anode pin is tied to 5v .The cathode pins are
connected to port 1 through 330 Ohm resistance (current limiting).
SOURCE CODE:
MOV A, # 80;
MOVX @DPTR, A; select I/O mode in 8255, out at Control register of 8255
MOV A, R0;
MOVC A, @A+DPTR;
MOVX @DPTR, A;
LCALL DELAY
INC R0
CJMP R0, # 00FH, XX;
YY: SJMP YY
MOV R3, # FF
DJNZ R1, CC
RET
LOOK UP TABLE
RESULT: To generate digits from 0 to 9 using common anode and common cathode technique.
INTERFACING DAC WITH 8051
AIM:
To interface DAC with 8051 parallel port to demonstrate the generation of square, saw tooth and
Triangular wave.
APPARATUS REQUIRED;
THEORY:
DAC 0809 is an 8 – bit DAC and the output voltage variation is between – 5V and +5V.The output voltage
varies in steps of 10/256 = 0.04 (appx.). The digital data input and the corresponding output voltages are
presented in the Table below
00 -5.00
01 -4.96
02 -4.92
7F 00
FD 4.92
FE 4.96
FF 5.00
Table 1.
Referring to Table1, with 00 H as input to DAC, the a nalog output is – 5V. Similarly, With FF H as input,
the output is +5V. Outputting digital data 00 and FF at regular intervals, to DAC, results in different wave
forms namely square, triangular, etc,
Two methods of creating a DAC : binary weighted and R/2R ladder. The vast majority of integrated
circuit DACs, including the MC1408 (DAC 0809) used in this section use the R/2R method since it can
achieve a much higher degree of precision. The first criterion for judging a DAC is its resolution, which is a
function of the number of binary inputs. The common ones are 8, 10, and 12 bits. The number of data bit
inputs decides the resolution of the DAC since the number of analog output levels is equal to 2 n , where n is
the number of data bit inputs. Therefore, an 8-input DAC.
Such as the DAC 0809 provides 256 discrete voltage (or current) levels of output.
Similarly, the 12-bit DAC provides 4096 discrete voltage levels. There are also
16-bit DACs, but they are more expensive.
Figure 1. 8051Connection to DAC 0809
ALGORITHM:
MOVX @DPTR, A
MOVX @DPTR, A
LCALL DELAY
MOV A, #FFH
MOVX @DPTR, A
LCALL DELAY
SJMP START
RET
INC A
CJNE A, #FFH, GO
SJMP START
MOVX @DPTR, A
INC A
CJNE A, #FFH, GO
DEC A
SJMP START
Result : Thus the square, triangular and saw tooth wave form were generated by interfacing DAC with
8051 trainer kit.
ADC 0808/0809 INTERFACING WITH 8051
AIM:
To interface ADC with 8051 to generate digital output by giving an analog input voltage.
APPARATUS REQUIRED;
THEORY:
One of the most commonly used ADC is ADC0808/0809. ADC 0808/0809 is a Successive
approximation type with 8 channels i.e. it can directly access 8 single ended analog signals.
I/O Pins
ADDRESS LINE A, B, and C: The device contains 8-channels. A particular channel is selected by using the
address decoder line. The TABLE 1 shows the input states for address lines to select any channel.
Address Latch Enable ALE: The address is latched on the Low – High transition of ALE.
START: The ADC’s Successive Approximation Register (SAR) is reset on the positive edge i.e. Low- High
of the Start Conversion pulse. Whereas the conversion is begun on the falling edge i.e. high – Low of the
pulse.
Output Enable: Whenever data has to be read from the ADC, Output Enable pin has to be pulled high thus
enabling the TRI-STATE outputs, allowing data to be read from the data pins D0-D7.
End of Conversion (EOC): This Pin becomes high when the conversion has ended, so the controller comes
to know that the data can now be read from the data pins.
Clock: External clock pulses are to be given to the ADC; this can be given either from LM 555 in Astable
mode or the controller can also be used to give the pulses.
ALGORITHM:
1. Start. 2. Select the channel. 3. A Low – High transition on ALE to latch in the address. 4. A Low –
High transition on Start to reset the ADC’s SAR. 5. A High – Low transition on ALE. 6. A High – Low
transition on start to start the conversion. 7. Wait for End of cycle (EOC) pin to become high. 8. Make
Output Enable pin High. 9. Take Data from the ADC’s output 10. Make Output Enable pin Low. 11.
Stop
I.e. total 12 lines. You can directly connect the OE pin to Vcc. Moreover instead of polling for EOC just put
some delay so instead of 12 lines you will require 10 lines. We Can also provide the clock through the
controller thus eliminating the need of external circuit for clock.
ADC 0808 is an 8 bit ADC i.e. it divides the voltage applied at Vref+ & Vref- into 28 i.e. 256 steps.
Suppose Vref+ is connected to Vcc i.e. 5V & Vref- is connected to the Gnd then the step size will be
Calculating D out.
The data we get at the D0 - D7 depends upon the step size & the Input voltage i.e. Vin.
If you want to interface sensors like LM35 which has output 10mv/°C then I would suggest that you set the
Vref+ to 2.56v so that the step size will be
So now whatever reading that you get from the ADC will be equal to the actual temperature.
Here is a program for interfacing the ADC to microcontroller, as stated above have assumed that the
OE pin is connected to Vcc & the clock is given by the controller.
This program selects channel 0 as input channel reads from it & saves in the accumulator.
NOTE: In the LAB, ADC is interfaced with 8051 Microcontroller through 8255 PPI.
Port 2 of 8051 is connected to Port C of 8255, Port 1 of 8051 is connected to Port A of 8255,
Port C is for interfacing signals and Port A is for Reading data from ADC.
Fig.1 interfacing circu it
PROGRAM:
MOVX @DPTR, A
MOV A, #00
MOVX @DPTR, A
MOVX @DPTR, A
MOVX @DPTR, A
LCALL DELAY
MOV A, #0EH
MOVX @DPTR, A
MOV A, #0CH
MOVX @DPTR, A
MOV DPTR, #2020
JB 0E7, BACK
ANL A, #80H
MOV A, #0DH
MOVX @DPTR, A
MOVX A,@DPTR
MOV DPTR, #9000H; Read the digital output from this address
MOVX @DPTR, A
SJMP BEGIN
BACK: NOP
NOP
RET
RESULT: Given input voltage varying from 5v to 0v at Channel 0 and observe the digital output value at
the address at 9000h, which is given in code.
STEPPER MOTOR INTERFACING WITH 8051
AIM:
APPARATUS:
8051
THEORY:
A motor in which the rotor is able to assume only discrete stationary angular position is a stepper
motor. The rotary motion occurs in a step-wise manner from one equilibrium position to the next. Stepper
Motors are used very wisely in position control systems like printers, disk drives, process control machine
tools, etc.
The basic two-phase stepper motor consists of two pairs of stator poles. Each of the four poles ha s its
own winding. The excitation of any one winding generates a North Pole. A South Pole gets induced at the
diametrically opposite side. The rotor magnetic system has two end faces. It is a permanent magnet with one
face as South Pole and the other as North Pole.
The Stepper Motor windings A1, A2, B1, B2 are cyclically excited with a DC current to run the
motor in clockwise direction. By reversing the phase sequence as A1, B2, A2, B1, anticlockwise stepping
can be obtained.
1 1 0 0 1
2 1 1 0 0
3 0 1 1 0
4 0 0 1 1
Going from step 1 to 4 we rotate motor clockwise, going from step 4 to 1 we rotate motor counter clockwise. The
stepper motor discussed here has total 6 leads. 4 leads representing 4 windings and 2 commons for centre tapped leads.
Here we have used 2 phase 4 step sequence. It must also be noted we can start from any step. Be it step 1, 2, 3 or 4.
But we must continue in proper order for proper rotation.
In programs on blog I have mostly begun from step 3. Other step sequences are as below
1 1 0 0 1
2 1 0 0 0
3 1 1 0 0
4 0 1 0 0
5 0 1 1 0
6 0 0 1 0
7 0 0 1 1
8 0 0 0 1
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
The Movement is associated with a step angle:
.72 500
1.8 200
2 180
2.5 144
5 72
7.5 48
15 24
4 Pins Of Stepper Motor Controlled By 4 Bits Of 8051 P1.0 - P1.3; It Is Interfaced Using Darlington
Arrays Such As Uln2003 As; 8051 Lacks Current To Run The Motor. So Uln2003 Is Used For
Energizing Stator.; Program Below Shows Just Rotating The Motor Step Wise; But Step Width Is
Unknown
Knowing stepper motor's step angle helps you calibrate the rotation of motor also to helps you move the motor
to correct angular position.
; This Other Program Code How In Same Interfacing To Rotate A Stepper Motor
; 64 Degrees In Clockwise Direction Using 4 Step Sequence
; It Takes Some Calculations
; Consider A Motor With Step Angle 2 Degree
; So Steps Per Revolution = 180
; No Of Rotor Teeth = 45
; Movement Per 4 Step Sequence is 8 Degrees
; For 64 Degree Movement We Need To Send 8 Consecutive 4 Step Sequence
; That Is It Will Cover 32 Steps
ORG 0000H
MOV A, #66H
MOV R1, #32H ; 32 Steps To Be Taken
BACK :RR A ; Rotate Clockwise
MOV P1, A ;
ACALL DELAY ;
DJNZ R0, BACK ;
END