2.8086 STRING
MANIPULATION –FIND AND REPLACE A WORD
AIM:
To find and replace a word
from a string.
ALGORITHM:
1. Load the source and
destination index register with starting and the ending address respectively.
2. Initialize the counter with
the total number of words to be copied.
3. Clear the direction flag for
auto incrementing mode of transfer.
4. Use the string manipulation
instruction SCASW with the prefix REP to search a word from string.
5. If a match is found (z=1),
replace the old word with the current word in destination address. Otherwise,
stop.
RESULT:
A word is found and replaced
from a string.
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DW 53H, 15H, 19H, 02H
REPLACE EQU 30H
COUNT EQU 05H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, 15H
MOV SI, OFFSET LIST
MOV CX, COUNT
MOV AX, 00
CLD
REP SCASW
JNZ LOOP
MOV DI, LABEL LIST
MOV [DI], REPLACE
LOOP MOV AH, 4CH
INT 21H
CODE ENDS
END START
INPUT:
LIST: 53H, 15H, 19H, 02H
OUTPUT:
LIST: 53H, 30H, 19H, 02H
3. 8086 STRING MANIPULATION – COPY
A STRING
AIM:
To copy a string of data
words from one location to the other.
ALGORITHM:
- Load the source and destination index register with starting and the ending address respectively.
- Initialize the counter with the total number of words to be copied.
- Clear the direction flag for auto incrementing mode of transfer.
- Use the string manipulation instruction MOVSW with the prefix REP to copy a string from source to destination.
RESULT:
A string of data words is copied from one location to other.
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
SOURCE EQU 2000H
DEST EQU 3000H
COUNT EQU 05H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV SI, SOURCE
MOV DI, DEST
MOV CX, COUNT
CLD
REP MOVSW
MOV AH, 4CH
INT 21H
CODE ENDS
END START
INPUT: OUTPUT:
2000 48 3000 48
2001 84 3001 84
2002 67 3002 67
2003 90 3003 90
2004 21 3004 21
4.8086 STRING MANIPULATION –
SORTING
AIM:
To sort a group of data
bytes.
ALGORITHM:
·
Place all the elements of an array named list
(in the consecutive memory locations).
·
Initialize two counters DX & CX with the
total number of elements in the array.
·
Do the following steps until the counter B
reaches 0.
o
Load the first element in the accumulator
o
Do the following steps until the counter C
reaches 0.
1.
Compare the accumulator content with the next element
present in the next memory location. If the accumulator content is smaller go
to next step; otherwise, swap the content of accumulator with the content of
memory location.
2.
Increment the memory pointer to point to the next
element.
3.
Decrement the counter C by 1.
·
Stop the execution.
RESULT:
A group of data bytes
are arranged in ascending order.
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DW 53H, 25H, 19H, 02H
COUNT EQU 04H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV DX, COUNT-1
LOOP2: MOV CX, DX
MOV SI, OFFSET LIST
AGAIN: MOV AX, [SI]
CMP AX, [SI+2]
JC LOOP1
XCHG [SI +2], AX
XCHG [SI], AX
LOOP1: ADD SI, 02
LOOP AGAIN
DEC DX
JNZ LOOP2
MOV AH, 4CH
INT 21H
CODE ENDS
END START
INPUT:
LIST: 53H, 25H, 19H, 02H
OUTPUT:
LIST: 02H, 19H, 25H, 53H
4.
INTERFACING 8255 WITH 8085
AIM:
To interface
programmable peripheral interface 8255 with 8085 and study its characteristics
in mode0,mode1 and BSR mode.
APPARATUS REQUIRED:
8085 mp kit, 8255Interface
board, DC regulated power supply, VXT parallel bus
I/O MODES:
Control Word:
MODE 0
– SIMPLE I/O MODE:
This mode provides simple I/O operations
for each of the three ports and is suitable for synchronous data transfer. In
this mode all the ports can be configured either as input or output port.
Let us initialize
port A as input port and port B as output port
PROGRAM:
ADDRESS
|
OPCODES
|
LABEL
|
MNEMONICS
|
OPERAND
|
COMMENTS
|
4100
|
|
MVI
|
A, 90
|
Initialize port A as Input and Port B as output.
|
|
4101
|
|
|
|
||
4102
|
|
|
OUT
|
C6
|
Send Mode Control word
|
4103
|
|
|
|
|
|
4104
|
|
|
IN
|
C0
|
Read from Port A
|
4105
|
|
|
|
|
|
4106
|
|
|
OUT
|
C2
|
Display the data in port B
|
4107
|
|
|
|
|
|
4108
|
|
|
STA
|
4200
|
Store the data read from Port A in 4200
|
4109
|
|
|
|
|
|
410A
|
|
|
|
|
|
410B
|
|
|
HLT
|
|
Stop the program.
|
MODE1
STROBED I/O MODE:
In this mode, port A and port B are used as data ports
and port C is used as control signals for strobed I/O data transfer.
Let us initialize port A as input port in mode1
MAIN PROGRAM:
ADDRESS
|
OPCODES
|
LABEL
|
MNEMONICS
|
OPERAND
|
COMMENTS
|
4100
|
|
MVI
|
A, B4
|
Initialize port A as Input
port in mode 1.
|
|
4101
|
|
|
|
||
4102
|
|
|
OUT
|
C6
|
Send Mode Control word
|
4103
|
|
|
|
|
|
4104
|
|
|
MVI
|
A,09
|
Set the PC4 bit for INTE A
|
4105
|
|
|
|
|
|
4106
|
|
|
OUT
|
C6
|
Display the data in port B
|
4107
|
|
|
|
|
|
|
|
|
EI
|
|
|
4108
|
|
|
MVI
|
A,08
|
Enable RST5.5
|
4109
|
|
|
|
|
|
410A
|
|
|
SIM
|
|
|
|
|
|
EI
|
|
|
410B
|
|
|
HLT
|
|
Stop the program.
|
ISR
(Interrupt Service Routine)
ADDRESS
|
OPCODES
|
LABEL
|
MNEMONICS
|
OPERAND
|
COMMENTS
|
4200
|
|
IN
|
C0
|
Read from port A
|
|
4201
|
|
|
|
||
4202
|
|
|
STA
|
4500
|
Store in 4500.
|
4203
|
|
|
|
|
|
4204
|
|
|
|
|
|
4205
|
|
|
HLT
|
|
Stop the program.
|
Sub
program:
ADDRESS
|
OPCODES
|
LABEL
|
MNEMONICS
|
OPERAND
|
COMMENTS
|
405E
|
|
|
JMP
|
4200
|
Go to 4200
|
405F
|
|
|
|
|
|
4060
|
|
|
|
|
BSR
MODE (Bit Set Reset mode)
ADDRESS
|
OPCODES
|
LABEL
|
MNEMONICS
|
OPERAND
|
COMMENTS
|
4100
|
|
MVI
|
A, 01
|
Set PC0
|
|
4101
|
|
|
|
||
4102
|
|
|
OUT
|
C6
|
Send Mode Control word
|
4103
|
|
|
|
|
|
4104
|
|
|
MVI
|
A,07
|
Set PC3
|
4105
|
|
|
|
|
|
4106
|
|
|
OUT
|
C6
|
Send Mode Control word
|
4107
|
|
|
|
|
|
4109
|
|
|
HLT
|
|
Stop the program.
|
RESULT:
Thus 8255 is interfaced and its characteristics in mode0,mode1 and BSR mode is studied.
6. INTERFACING 8253 TIMER WITH
8085
Interfacing 8253 Programmable Interval Timer with 8085 mp
AIM:
To interface 8253 Interface board to 8085 mp and
verify the operation of 8253in six different modes.
APPARATUS REQUIRED:
8085 mp kit, 8253 Interface board, DC regulated power supply,
VXT parallel bus, CRO.
Mode 0 – Interrupt on terminal count:
The output will be initially low after mode set
operations. After loading the counter,
the output will be remaining low while counting and on terminal count; the
output will become high, until reloaded again.
Let us set the channel 0 in mode
0. Connect the CLK 0 to the debounce
circuit by changing the jumper J3 and then execute the following program.
Program:
Address
|
Opcodes
|
Label
|
Mnemonic
|
Operands
|
Comments
|
4100
|
|
MVI
|
A, 30
|
Channel 0 in mode 0
|
|
4102
|
|
|
OUT
|
CE
|
Send Mode Control word
|
4104
|
|
|
MVI
|
A, 05
|
LSB of count
|
4106
|
|
|
OUT
|
C8
|
Write count to register
|
4108
|
|
|
MVI
|
A, 00
|
MSB of count
|
410A
|
|
|
OUT
|
C8
|
Write count to register
|
410C
|
|
|
HLT
|
|
|
It is observed in CRO that the output of Channel 0 is
initially LOW. After giving six clock
pulses, the output goes HIGH.
Mode 1 – Programmable ONE-SHOT:
After loading the counter, the
output will remain low following the rising edge of the gate input. The output will go high on the terminal
count. It is retriggerable; hence the
output will remain low for the full count, after any rising edge of the gate
input.
Example:
The following program initializes
channel 0 of 8253 in Mode 1 and also initiates triggering of Gate 0. OUT 0 goes low, as clock pulse after
triggering the goes back to high level after 5 clock pulses. Execute the program, give clock pulses
through the debounce logic and verify using CRO.
Address
|
Opcodes
|
Label
|
Mnemonic
|
Operands
|
Comments
|
4100
|
|
MVI
|
A, 32
|
Channel 0 in mode 1
|
|
4102
|
|
|
OUT
|
CE
|
Send Mode Control word
|
4104
|
|
|
MVI
|
A, 05
|
LSB of count
|
4106
|
|
|
OUT
|
C8
|
Write count to register
|
4108
|
|
|
MVI
|
A, 00
|
MSB of count
|
410A
|
|
|
OUT
|
C8
|
Write count to register
|
410C
|
|
|
OUT
|
D0
|
Trigger Gate0
|
4100
|
|
|
HLT
|
|
|
Mode 2 – Rate Generator:
It is a simple divide by N counter. The output will be low for one period of the
input clock. The period from one output
pulse to the next equals the number of input counts in the count register. If the count register is reloaded between
output pulses the present period will not be affected but the subsequent period
will reflect the new value.
Example:
Using Mode 2, Let us divide the clock present at
Channel 1 by 10. Connect the CLK1 to
PCLK.
Address
|
Opcodes
|
Label
|
Mnemonic
|
Operands
|
Comments
|
4100
|
3E 74
|
MVI
|
A, 74
|
Channel 1 in mode 2
|
|
4102
|
D3 CE
|
|
OUT
|
CE
|
Send Mode Control word
|
4104
|
3E 0A
|
|
MVI
|
A, 0A
|
LSB of count
|
4106
|
D3 CA
|
|
OUT
|
CA
|
Write count to register
|
4108
|
3E 00
|
|
MVI
|
A, 00
|
MSB of count
|
410A
|
D3 CA
|
|
OUT
|
CA
|
Write count to register
|
410C
|
76
|
|
HLT
|
|
|
In CRO observe simultaneously the input clock to channel 1
and the output at Out1.
Mode 3 Square wave generator:
It is similar to Mode 2 except that the output will
remain high until one half of count and go low for the other half for even
number count. If the count is odd, the
output will be high for (count + 1)/2 counts.
This mode is used of generating Baud rate for 8251A (USART).
Example:
We utilize Mode 0 to generate a
square wave of frequency 150 KHz at channel 0.
Address
|
Opcodes
|
Label
|
Mnemonic
|
Operands
|
Comments
|
4100
|
3E 36
|
MVI
|
A, 36
|
Channel 0 in mode 3
|
|
4102
|
D3 CE
|
|
OUT
|
CE
|
Send Mode Control word
|
4104
|
3E 0A
|
|
MVI
|
A, 0A
|
LSB of count
|
4106
|
D3 C8
|
|
OUT
|
C8
|
Write count to register
|
4108
|
3E 00
|
|
MVI
|
A, 00
|
MSB of count
|
410A
|
D3 C8
|
|
OUT
|
C8
|
Write count to register
|
410C
|
76
|
|
HLT
|
|
|
Set the jumper, so that the clock 0 of 8253 is given a
square wave of frequency 1.5 MHz. This
program divides this PCLK by 10 and thus the output at channel 0 is 150 KHz.
Vary the
frequency by varying the count. Here the
maximum count is FFFF H. So, the square
wave will remain high for 7FFF H counts and remain low for 7FFF H counts. Thus with the input clock frequency of 1.5
MHz, which corresponds to a period of 0.067 microseconds, the resulting square
wave has an ON time of 0.02184 microseconds and an OFF time of 0.02184 microseconds.
To increase
the time period of square wave, set the jumpers such that CLK2 of 8253 is
connected to OUT 0. Using the
above-mentioned program, output a square wave of frequency 150 KHz at channel
0. Now this is the clock to channel
2.
Mode 4: Software Triggered Strobe:
The output
is high after mode is set and also during counting. On terminal count, the output will go low for
one clock period and becomes high again.
This mode can be used for interrupt generation.
The
following program initializes channel 2 of 8253 in mode 4.
Example:
Connect OUT
0 to CLK 2 (jumper J1). Execute the
program and observe the output OUT 2.
Counter 2 will generate a pulse after 1 second.
Address
|
Opcodes
|
Label
|
Mnemonic
|
Operands
|
Comments
|
4100
|
|
MVI
|
A, 36
|
Channel 0 in mode 0
|
|
4102
|
|
|
OUT
|
CE
|
Send Mode Control word
|
4104
|
|
|
MVI
|
A, 0A
|
LSB of count
|
4106
|
|
|
OUT
|
C8
|
Write count to register
|
4108
|
|
|
MVI
|
A, 00
|
MSB of count
|
410A
|
|
|
OUT
|
C8
|
Write count to register
|
410C
|
|
|
MVI
|
A, B8
|
Channel 2 in Mode 4
|
410E
|
|
|
OUT
|
CE
|
Send Mode control Word
|
4110
|
|
|
MVI
|
A, 98
|
LSB of Count
|
4112
|
|
|
OUT
|
CC
|
Write Count to register
|
4114
|
|
|
MVI
|
A, 3A
|
MSB of Count
|
4116
|
|
|
OUT
|
CC
|
Write Count to register
|
4118
|
|
|
HLT
|
|
|
Mode 5 Hardware triggered strobe:
Counter
starts counting after rising edge of trigger input and output goes low for one
clock period when terminal count is reached.
The counter is retriggerable.
Example:
The program that follows initializes channel 0 in mode 5 and
also triggers Gate 0. Connect CLK 0 to
debounce circuit.
Execute the
program. After giving Six clock pulses,
you can see using CRO, the initially HIGH output goes LOW. The output ( OUT 0 pin) goes high on the next
clock pulse.
Address
|
Opcodes
|
Label
|
Mnemonic
|
Operands
|
Comments
|
4100
|
|
MVI
|
A, 1A
|
Channel 0 in mode 5
|
|
4102
|
|
|
OUT
|
CE
|
Send Mode Control word
|
4104
|
|
|
MVI
|
A, 05
|
LSB of count
|
4106
|
|
|
OUT
|
C8
|
Write count to register
|
4108
|
|
|
MVI
|
A, 00
|
MSB of count
|
410A
|
|
|
OUT
|
D0
|
Trigger Gate 0
|
410C
|
|
|
HLT
|
|
|
Result:
Thus
the 8253 has been interfaced to 8085 mp and six different modes
of 8253 have been studied.
7. INTERFACING 8279 WITH 8085
8. INTERFACING 8251 WITH 8085
9. 8051 - SUM OF ELEMENTS IN AN
ARRAY
AIM:
To find the sum of elements
in an array.
ALGORITHM:
1.
Load the array in the consecutive memory location and
initialize the memory pointer with the starting address.
2.
Load the total number of elements in a separate register as a
counter.
3.
Clear the accumulator.
4.
Load the other register with the value of the memory pointer.
5.
Add the register with the accumulator.
6.
Check for carry, if exist, increment the carry register by 1.
otherwise, continue
7.
Decrement the counter and if it reaches 0, stop. Otherwise
increment the memory pointer by 1 and go to step 4.
RESULT:
The sum of elements in an array is
calculated.
PROGRAM:
MOV DPTR, #4200
MOVX A, @DPTR
MOV R0, A
MOV B, #00
MOV R1, B
INC DPTR
LOOP2: CLR
C
MOVX A, @DPTR
ADD A, B
MOV B, A
JNC LOOP
INC R1
LOOP: INC DPTR
DJNZ R0, LOOP2
MOV DPTR, #4500
MOV A, R1
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
HLT: SJMP
HLT
INPUT OUTPUT:
4200 04 4500 0F
4201 05 4501 00
4201 06
4202 03
4203 02
10(A).8051 - HEXADECIMAL TO DECIMAL CONVERSION
AIM:
To
perform hexadecimal to
decimal conversion.
ALGORITHM:
1.
Load the number to be converted into the accumulator.
2.
If the number is less than 100 (64H), go to next step;
otherwise, subtract 100 (64H) repeatedly until the remainder is less than 100
(64H). Have the count(100’s value) in
separate register which is the carry.
3.
If the number is less than 10 (0AH), go to next step;
otherwise, subtract 10 (0AH) repeatedly until the remainder is less than 10
(0AH). Have the count(ten’s value) in
separate register.
4.
The accumulator now has the units.
5.
Multiply the ten’s value by 10 and add it with the
units.
6.
Store the result and carry in the specified memory
location.
RESULT
The given hexadecimal number is converted
into decimal number.
PROGRAM:
MOV DPTR, #4500
MOVX A, @DPTR
MOV B, #64
DIV A, B
MOV DPTR, #4501
MOVX @DPTR, A
MOV A, B
MOV B, #0A
DIV A, B
INC DPTR
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
HLT: SJMP HLT
INPUT OUTPUT:
4500 D7 4501 15
4502 02
10(B).8051 - DECIMAL TO HEXADECIMAL CONVERSION
AIM:
To perform decimal to hexadecimal conversion
ALGORITHM:
1.
Load the number to be converted in the accumulator.
2.
Separate the higher order digit from lower order.
3.
Multiply the higher order digit by 10 and add it with
the lower order digit.
4.
Store the result in the specified memory location.
RESULT:
The
given decimal number is converted to hexadecimal number.
PROGRAM:
MOV DPTR, #4500
MOVX A, @DPTR
MOV B, #0A
MUL A, B
MOV B, A
INC DPTR
MOVX A, @DPTR
ADD A, B
INC DPTR
MOVX @DPTR, A
HLT: SJMP HLT
INPUT OUTPUT
4500 23 4501 17
13. STEPPER MOTOR INTERFACING WITH 8051
AIM:
To interface a stepper motor with
8051 microcontroller and operate it.
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 has 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.
2-PHASE SWITCHING SCHEME:
In this
scheme, any two adjacent stator windings are energized. The switching scheme is
shown in the table given below. This scheme produces more torque.
ANTICLOCKWISE |
CLOCKWISE |
||||||||||
STEP
|
A1
|
A2
|
B1
|
B2
|
DATA
|
STEP
|
A1
|
A2
|
B1
|
B2
|
DATA
|
1
|
1
|
0
|
0
|
1
|
9h
|
1
|
1
|
0
|
1
|
0
|
Ah
|
2
|
0
|
1
|
0
|
1
|
5h
|
2
|
0
|
1
|
1
|
0
|
6h
|
3
|
0
|
1
|
1
|
0
|
6h
|
3
|
0
|
1
|
0
|
1
|
5h
|
4
|
1
|
0
|
1
|
0
|
Ah
|
4
|
1
|
0
|
0
|
1
|
9h
|
ADDRESS DECODING LOGIC:
The 74138 chip is used for
generating the address decoding logic to generate the device select pulses, CS1
& CS2 for selecting the IC 74175.The 74175 latches the data bus to the
stepper motor driving circuitry.
Stepper
Motor requires logic signals of relatively high power. Therefore, the interface
circuitry that generates the driving pulses use silicon darlington pair
transistors. The inputs for the interface circuit are TTL pulses generated
under software control using the Microcontroller Kit. The TTL levels of pulse sequence from the
data bus is translated to high voltage output pulses using a buffer 7407 with
open collector.
PROGRAM :
Address
|
Label
|
|
|
Comments
|
|
|
|
ORG
|
4100h
|
|
|
4100
|
START:
|
MOV
|
DPTR, #TABLE
|
Load the start address of switching scheme data TABLE into
Data Pointer (DPTR)
|
|
4103
|
|
|
MOV
|
R0, #04
|
Load the count in R0
|
4105
|
|
LOOP:
|
MOVX
|
A, @DPTR
|
Load the number in TABLE into A
|
4106
|
|
|
PUSH
|
DPH
|
Push DPTR value to Stack
|
4108
|
|
|
PUSH
|
DPL
|
|
410A
|
|
|
MOV
|
DPTR, #0FFC0h
|
Load the Motor port address into DPTR
|
410D
|
|
|
MOVX
|
@DPTR, A
|
Send the value in A to stepper Motor port address
|
410E
|
|
|
MOV
|
R4, #0FFh
|
Delay loop to cause a specific amount of time delay before
next data item is sent to the Motor
|
4110
|
|
DELAY:
|
MOV
|
R5, #0FFh
|
|
4112
|
|
DELAY1:
|
DJNZ
|
R5, DELAY1
|
|
4114
|
|
|
DJNZ
|
R4, DELAY
|
|
4116
|
|
|
POP
|
DPL
|
POP back DPTR value from Stack
|
4118
|
|
|
POP
|
DPH
|
|
411A
|
|
|
INC
|
DPTR
|
Increment DPTR to point to next item in the table
|
411B
|
|
|
DJNZ
|
R0, LOOP
|
Decrement R0, if not zero repeat the loop
|
411D
|
|
|
SJMP
|
START
|
Short jump to Start of the program to make the motor
rotate continuously
|
411F
|
|
TABLE:
|
DB
|
09 05 06
0Ah
|
Values as per two-phase switching scheme
|
PROCEDURE:
Enter the above program starting
from location 4100.and execute the same. The stepper motor rotates. Varying the
count at R4 and R5 can vary the speed. Entering the data in the look-up TABLE
in the reverse order can vary direction of rotation.
RESULT:
Thus
a stepper motor was interfaced with 8051 and run in forward and reverse
directions at various speeds.
No comments:
Post a Comment