MPMC Lab Final Jntuk
MPMC Lab Final Jntuk
MPMC Lab Final Jntuk
To Create Source File: An editor is a program which allows you to create a file containing
the assembly language statements for your program. This file is called a source file.
Command to create a source file
The next step is to process the source file with an assembler. When you run the
assembler, it reads the source file of your program. On the first pass through the source
program, the assembler determines the displacement of named data items, the offset labels,
etc. and puts 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 offsets,
etc. that it calculated during first pass.
1. The first file (X) 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.
2. The second file (Y) generated by the assembler is called the assembler list file and is given
the extension .LST. The list file contains your assembly language statements, the binary
codes for each instruction and the offset for each instruction.
1
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
3. The third file (Z) generated by this assembler is called the cross-reference file and is given
the extension .CRF. The cross-reference file lists all labels and pertinent information required
for cross – referencing
NOTE : The Assembler only finds syntax errors : It will not tell you whether program does
what it is supposed to do. To determine whether your program works, you have to run the
program and test it.
NOTE : On IBM PC – type Computers, You must run the LINK program on your .OBJ file
even if it contains only one assembly module. The linker produces a link file with the .EXE
extension (an execution file)
The linker produces a link file with the .EXE extension (an execution file)
2
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 55H, 66H, 77H
N2 DB 11H, 22H, 33H
RESULT DB 3H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV SI, OFFSET N1
MOV DI, OFFSET N2
MOV BX, OFFSET RESULT
CLC
MOV CX, 0003H
MOV AX, 0000H
BACK: MOV AL, [SI]
MOV DL, [DI]
ADC AL, DL
MOV [BX], AL
INC SI
INC DI
INC BX
DEC CX
JNZ BACK
MOV AH, 4CH
INT 21H
INT 3H
3
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
CODE ENDS
END START
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
DATA SEGMENT
N1 DB 55H, 66H, 77H, 88H
N2 DB 11H, 22H, 33H, 44H
RESULT DB 4H DUP(00)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
4
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
CODE ENDS
END START
***************************************************************************
***************************************************************************
DATA SEGMENT
N1 DB 05H, 04H, 02H
N2 DB 01H, 02H, 03H
RESULT DB 4H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
5
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
CODE ENDS
END START
6
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
MOV SI, OFFSET N1
MOV DI, OFFSET N2
MOV BX, OFFSET RESULT
MOV CL, 03H
MOV AX, 0000H
MOV DX, 0000H
BACK: MOV AL, [SI]
MOV CH, [DI]
DIV CH
MOV [BX], AL
INC SI
INC DI
INC BX
LOOP BACK
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
7
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
***************************************************************************
***************************************************************************
DATA SEGMENT
N1 DB 09H
N2 DB 02H
N3 DB 02H DUP(00)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
SUB AX, AX
MOV AL, N1
MOV CH, N2
MOV BX, OFFSET N3
IMUL CH
MOV [BX], AL
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
8
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
RESULT: 09H
02H
18H
***************************************************************************
***************************************************************************
Program No: 3(b) SIGNED DIVISION
DATA SEGMENT
N1 DB 40H
N2 DB 20H
N3 DB 02H DUP (00H)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV AL, N1
CBW
MOV CH, N2
MOV BX, OFFSET N3
IDIV CH
MOV [BX], AL
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT: 40H
20H
800H
9
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 14H
N2 DB 04H
N3 DB 2H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV AL, N1
MOV CL, N2
MOV BX, OFFSET N3
ADD AL, CL
AAA
MOV [BX], AL
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
***************************************************************************
***************************************************************************
10
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 04H
N2 DB 02H
N3 DB 02H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV AL, N1
MOV BX, OFFSET N3
SUB AL, N2
AAS
MOV [DL], AL
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
***************************************************************************
***************************************************************************
11
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 04H
N2 DB 03H
N3 DB 02H DUP(00)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV AL, N1
MOV BX, OFFSET N3
MUL N2
AAM
MOV [BL], AL
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
***************************************************************************
***************************************************************************
12
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 06H
N2 DB 04H
N3 DB 02H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV AL, N1
MOV BX, N3
AAD
DIV N2
MOV [BX], AL
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
***************************************************************************
***************************************************************************
13
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 56H, 49H, 33H
N2 DB 06H DUP(00)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV SI, OFFSET N1
MOV DI, OFFSET N2
MOV CX, 0003H
BACK: MOV AL, [SI]
MOV BL, AL
AND AL, 0F0H
MOV CL, 04H
ROR BL, CL
AND BL, 0FH
MOV [DI], AL
INC DI
MOV [DI], BL
INC SI
INC DI
DEC CX
JNZ BACK
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
14
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
END START
RESULT:
I/P : 56H 49H 33H
O/P : 05H,06H, 04H,09H, 03H,03H
***************************************************************************
***************************************************************************
Program No: 5(b) UNPACKED BCD TO PACKED
DATA SEGMENT
N1 DB 05H, 06H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV AL, N1
MOV BL, AL
MOV CL, 04H
ROR BL, CL
OR AL, BL
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
I/P : 05H 06H
O/P : 56H
15
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 56H
N2 DB 02H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV AL, N1
MOV SI, OFFSET N2
MOV BL, AL
AND AL, 0F0H
ADD AL, 30H
MOV CL, 4H
ROR BL, CL
AND BL, 0FH
ADD BL, 30H
MOV [SI] , BL
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
I/P : 56H
O/P: 35H,36H
***************************************************************************
16
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 35H
N2 DB 02H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV AL, N1
AND AL, 0FH
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
I/P : 35H
O/P : 05H
***************************************************************************
***************************************************************************
Application Programs:
DATA SEGMENT
N1 DB 56H, 49H, 33H
17
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV SI, OFFSET N1
MOV DX, 0000H
MOV BX, 0000H
MOV CX, 0003H
BACK: MOV AL, [SI]
ROR AL, 01H
JC X
INC BX
JMP Y
X: INC DX
Y: INC SI
DEC CX
JNZ BACK
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
I/P : 56H 49H 33H
O/P : BX=0001H,DX=0002H
***************************************************************************
***************************************************************************
18
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
DATA SEGMENT
N1 DB 51H, 20H, 33H,80H,19H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV SI, OFFSET N1
MOV DX, 0000H
MOV BX, 0000H
MOV CX, 0005H
BACK: MOV AL, [SI]
ROL AL, 01H
JC X
INC BX
JMP Y
X: INC DX
Y: INC SI
DEC CX
JNZ BACK
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
19
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
RESULT:
I/P : 56H 49H 33H
O/P : BX=0004H,DX=0001H
***************************************************************************
***************************************************************************
Program No: 7(a) ASCENDING ORDER
DATA SEGMENT
N1 DB 56H, 49H, 33H,05H,12H,17H,08H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV BX, 0006H
Z: MOV SI, OFFSET N1
MOV CX, 0006H
BACK: MOV AL, [SI]
INC SI
CMP AL,[SI]
JBE Y
XCHG AL,[SI]
DEC SI
MOV [SI], AL
INC SI
Y: DEC CX
JNZ BACK
DEC BX
JNZ Z
20
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
***************************************************************************
***************************************************************************
Program No: 7(b) DESCENDING ORDER
DATA SEGMENT
N1 DB 56H, 49H, 33H,05H,12H,17H,08H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV BX, 0006H
Z: MOV SI, OFFSET N1
MOV CX, 0006H
BACK: MOV AL, [SI]
INC SI
CMP AL,[SI]
JAE Y
XCHG AL,[SI]
DEC SI
MOV [SI],AL
21
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
INC SI
Y: DEC CX
JNZ BACK
DEC BX
JNZ Z
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
I/P : 56H, 49H, 33H,05H,12H,17H,08H
O/P : 56H, 49H,33H,17H,12H,08H,05H
***************************************************************************
***************************************************************************
Program No: 8 BLOCK TRANSFER
DATA SEGMENT
N1 DB 01H,02H,03H
DATA ENDS
EXTRA SEGMENT
N2 DB 03H DUP (00)
EXTRA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, ES:EXTRA
START: MOV AX, DATA
MOV DS, AX
MOV AX, EXTRA
MOV ES, AX
22
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
RESULT:
I/P : 01H, 02H, 03H
O/P : 01H, 02H, 03H
***************************************************************************
***************************************************************************
Program No: 9(a) READ A CHARACTER WITH & WITH OUT ECHO
ASSUME CS:CODE,
START : MOV AH, 01H
INT 21H
MOV AH, 4CH
INT 21H
INT 3H
CODE END
END START
RESULT:
INPUT : ‘a’
OUPUT:’a’
23
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
ASSUME CS:CODE,
START : MOV AH, 07H
INT 21H
MOV AH, 4CH
INT 21H
INT 3H
CODE END
END START
RESULT:
INPUT: ‘a’
OUPUT:
***************************************************************************
***************************************************************************
Program No: 9(b) DISPLAY CHARACTER
ASSUME CS CODE:
START: MOV AX,DATA
MOV DS, AX
MOV CX, 0005H
X: MOV AH, 02H
MOV DL, ‘Z’
INT 21H
MOV AH, 02H
MOV DL, 20H
INT 21H
DEC CX
JNZ X
INT3H
CODE END
24
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
END START
RESULT:
INPUT : ‘Z’
OUTPUT : Z Z Z Z Z
***************************************************************************
***************************************************************************
Program No:( 10) STRING REVERSAL
DATA SEGMENT
N1 DB ‘MLRIT$’
N2 DB 05H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
MOV SI, OFFSET N1
MOV DI, OFFSET N2
ADD DI, 0005H
CLD
MOV AH, ‘$’
X: CMP AH, [SI]
JE Y
MOV AL, [SI]
MOV [DI], AL
INC SI
DEC DI
LOOP X
25
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
RESULT:
***************************************************************************
***************************************************************************
Program No: 11 LENGTH OF THE STRING
DATA SEGMENT
STRING1 DB 'EMPTY VESSELS MAKE MORE NOISE$'
STRLEN EQU ($-STRING1)
RES DB 0
CORT DB 'STRLENGTH FOUND CORRECT$'
INCORT DB 'STRLENGTH FOUND INCORRECT$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
SUB CL, CL
MOV BL, STRLEN
MOV SI, OFFSET STRING1
BACK: LODSB
INC CL
CMP AL,'$'
26
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
JNZ BACK
MOV RES, CL
CMP CL, BL
JZ CORRECT
MOV DX, OFFSET INCORT
MOV AH, 09
INT 21H
CORRECT: MOV DX, OFFSET CORT
MOV AH, 09
INT 21H
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
***************************************************************************
***************************************************************************
Program No: 12 STRING COMPARISION
DATA SEGMENT
STRING1 DB 'EMPTY'
STRLEN EQU ($-STRING1)
NOTSFUL DB 'STRINGS ARE UNEQUAL$'
SFUL DB 'STRINGS ARE EQUAL$'
DATA ENDS
EXTRA SEGMENT
STRING2 DB 'EMPTY'
27
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
EXTRA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, ES:EXTRA
START: MOV AX, DATA
MOV DS, AX
MOV AX, EXTRA
MOV ES, AX
MOV SI, OFFSET STRING1
MOV DI, OFFSET STRING2
CLD
MOV CX,LENGTH STRING1
MOV CX, STRLEN
REP CMPSB
JZ FORW
MOV AH, 09H
MOV DX, OFFSET NOTSFUL
INT 21H
JMP EXITP
FORW:MOV AH,09H
MOV DX, OFFSET SFUL
INT 21H
EXITP:
NOP
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START
RESULT:
28
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
II.INTERFACING
1. 8259 Interfacing:
The Study module card is connected to the 8086 kit through a 50 pin FRC cable.
Before making connections check the polarity of the cable.
switches, debounce switches for single stepping, Buffers and Tags for applying
interrupts, Vcc TAGS, LEDS To Display status.
The toggle switch at top is for enabling single stepping. Push to ON for single
stepping of every instruction. When single stepping enable will show each data
transferred in an instruction on the data bus, including chip select, Read, Write,
Interrupt and Interrupt Acknowledge Signals.
DEMONSTRATION:
This is a demonstration in which 8259 will be used in the stand alone mode. Program 1 will
be used to illustrate this concept. In the main loop of program, it will be displaying (HELP),
and when L to H pulse is applied to IRO line using patch cord in the ISR, it displays “IRO”
Step 1
Connect the 8259 PIC study module through 50 pin FRC cable.
Step 2
Step 3
29
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Step 4
Step 5
At this stage “WAITING FOR INT” will display on the LCD of VMC – 8609. Give
the interrupt to the study card by connecting IRO (Lower) to VCC. Just after giving the
interrupt “IRO” will display on LCD.
Note : While using 8259 Study Module with 8086 kit switch of all position of SW1 Dip
Switch Position.
PROGRAM:
This program is to demonstrate the use of 8259 PIC. Here only Master 8259 is used,
during the main program, “HELP” is displayed while in the interrupt service loop, “IRO” is
displayed.
30
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Interface keyboard and display controller 8279 with 8086 at addresses 0080H. Write
an ALP to set up 8279 in scanned keyboard mode with encoded scan, N-key rollover mode.
Use a 16-character display in right entry display format. Then clear the display RAM with
zeroes. Read the FIFO for key closure. If any key is closed, store its code to register CL.
Then write the byte 55 to all the displays and return to DOS. The lock input to 8279 is 2MHz,
operate it at 100 kHz.
31
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Theory:
The 8279 is interfaced with lower byte of the data bus, i.e. D0-D7. Hence the A0
input of 8279 is connected with address line A1. The data register of 8279 is to be addressed
as 0080H, i.e. A0=0. For addressing the command or status word A0 input of 8279 should be
1 (the address line A1 of 8086 should be 1), i.e. the address of the command word should be
0082H.
Procedure:
Step1: Set 8279 command words according to program i.e. Keyboard/Display Mode Set CW,
Program clock selection, Clear Display RAM, Read FIFO, Write Display RAM
commands.
Step3: Wait for clearing of Display RAM by reading FIFO Du bit of the status word i.e. if Du
bit is not set wait, else proceed.
Step4: Read FIFO command for checking key closure, also read FIFO status.
Step5: Mask all bits except the number of characters bits. If any key is pressed, take required
action; otherwise proceed to write display RAM by using write display command.
Step 7: Call routine to read the key code of the pressed key is assumed available.
This Program displays the code of the key, which is pressed on the keyboard pad. The code is
displayed in the data field and remains unchanged till the next key is pressed.
32
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
The port of 8255 i.e. P1 is initialized to make port A as input port and port C as output
port. The three Rows of the key are scanned one by one and process is repeated till the key is
pressed, in the routine code and F code (final code). The information of code is then
displayed and the monitor jumps back again to see if any other key is pressed.
33
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
ASSUME CS:CODE,DS:DATA
SINE DB 0,11,22,33,43,54,63,72,81,90,97,104,109,115,119,122
DB 125,,126,127,126,122,119,115,109,104,97,90,81,72,63,54,43,33,22,11
PA EQU 44A0H
CR EQU 44A3H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV DX, CR
MOV AL, 80H
OUT DX, AL
REPEAT: MOV DX, PA
34
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
OUT DX, AL
INC SI
LOOP NEXT
MOV CX, 36
LEA SI, SINE
NEXT1: MOV AL, 128
MOV AH,[SI]
SUB AL, AH
OUT DX, AL
INC SI
LOOP NEXT1
JMP REPEAT
MOV AH, 4CH
INT 21H
CODE ENDS
END START
4. 8251 (USART)
DEMONSTRATION:
In this experiment we will be using 8253 in Mode3, using counter 0 and load the
count with 16 bit count. The 8251 is also initialized by specifying both command as well as
the mode word. In the Experiment whatever data is transmitted from the CPU (with the help
of RS – 232) will be received by the 8251 and then will be transmitted back to the CPU and
displayed on the screen. The program can be run either in free run mode or single stepping
mode.
Step 1:
Connect the 8253 / 8251 study module card to the 8086 kit via a 50 pin FRC. Check the
polarity of the cable for proper data transmission.
35
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Step 2 :
Connect the 8253 kit to the computer input / output port with a RS232 cable.
Step 3 :
Connect the CLK 0 tag to the 8086 CLK
Step 4 :
Connect Gate 0 tag to +5V VCC
Step 5 :
Connect out O tag to R x C & T x C tags
Step 6 :
Enter the Program given below
Step 7 :
Enter the Program by pressing Reset, Exmem, Next Keys.
Step 8 :
Execute the Program using <Reset>, <Go>, <.> Keys
36
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
The stepper motors have been designed to work with digital circuits. Binary
level pulses of 0-5V are required at its winding inputs to obtain the rotation of the
shafts. The sequence of the pulses can be decided, depending upon the required
37
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
motion of the shaft. By suitable sequence of the pulses the motor can be used in
three modes of operation.
WORKING
8255 is interfaced with 8086 in I/O mapped I/O. port C (PC0, PC1, PC2, PC3)
is used to give pulse sequence to stepper motor. The 8255 provides very less current
which will not be able to drive stepper motor coils so each of the winding of a stepper
motor needs to be interfaced using high speed switching Darlington transistors with max
1A, 80V rating with heat sink, with the output port of 8255. Output the sequence in
correct order to have the desired direction to rotate the motor.
38
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
program:
Delay program
39
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
FEATURES
1. Resolution 8 bits
2. Conversion time 100 micro sec.
3. Single supply 5V
4. 8 channel multiplexed with latched control logic
5. easy interface to all microprocessor
6. 0 to 5V analog input voltage range with single 5V supply
7. low power consumption 15mW
8. latched tristate output
WORKING
ADC interface consists of a NAND gate oscillator witch feeds 50 KHz as the input
clock to ADC, input to channel is given through terminal blocks provided on the card.
Channel selection is done using port lines PC0, PC1 & PC2, START OF CONVERSION and
ALE is controlled by port line PC7. Converted digital output is read by ADC through
PORTA lines by enabling OE. OE line is connected to port line PC6
1V 33H
2V 66H
40
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
3V 99H
4V CCH
5V FFH
The following is the assembly language using DAC to interface with 8255 and
generate a square wave on CRO. Here in the code, we use two delay elements one for the
rising part of the wave and the other delay element to reach zero i.e. decrement. Certain value
chosen is delayed or sustained for a time period to form the square wave. The two loops used
in the program are iterated to repeat cycles of a square wave.
41
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Delay program:
RESULT:
The following is the assembly language using DAC to interface with 8255 and
generate a square wave on CRO. Here in the code, we use two loops one for the rising part of
the wave and the other element to reach zero i.e decrement. The two jump instructions used
in the program are iterated to repeat cycles of a triangular wave.
42
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Program:
Delay program
43
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
RESULT:
44
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
8279 theory:
Features:
45
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
CS: Chip select that enables programming, reading the keyboard, etc.
OUT A3-A0/B3-B0: Outputs that sends data to the most significant/least significant
Nibble of display.
RL7-RL0: Return lines are inputs used to sense key depression in the keyboard
matrix.
SL3-SL0: Scan line outputs scan both the keyboard and displays.
46
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Pin diagram:
47
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Whether new data are entered to the rightmost or leftmost display position.
48
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
49
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Program:
50
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
51
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
RESULT:
52
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
III.8051 Programming:
1.Reading and writing on a parallel port.
The basic 8051 has two on-chip timers that can be used for timing durations or for
counting external events Interval timing allows the programmer to perform operations at
specific instants in time. For example, in our LED flashing program the LED was turned on
for a specific length of time and then turned off for a specific length of time. We achieved
this through the use of time delays. Since the microcontroller operates at a specific frequency,
we could work out exactly how many iterations of the time delay was needed to give us the
desired delay. However, this is cumbersome and prone to error. And there is another
disadvantage; the CPU is occupied, stepping through the loops. If we use the on-chip timers,
the CPU could be off doing something more useful while the timers take on the menial task
of keeping track of time
53
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
The 8051 has two 16-bit timers. The high byte for timer 1 (TH1) is at address 8DH
while the low byte (TL1) is at 8BH The high byte for timer 0 (TH0) is at 8CH while the low
byte (TL0) is at 8AH.Both timers can be used in a number of different modes. The
programmer sets the timers to a specific mode by loading the appropriate 8-bit number into
the Timer Mode Register (TMOD) which is at address 89H.
The functions of the 8-bits of TMOD are described in the above table. The top four bits are
for timer 1 and the bottom four bits have the exact same function but for timer 0. The Gate
bits are used in conjunction with interrupts and will be dealt with at a later stage. For the
moment we can take it that bits 7 and 3 are always cleared. As mentioned above, the timers
can be used for counting external events or for timing intervals. If you wish the timer to be an
event counter you set the corresponding C/T-bar bit. Similarly, if you wish it to be an interval
timer you reset the corresponding C/T-bar bit. There are two mode bits (M1 and M0) for each
timer. The table below describes their function.
54
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
There are four timer modes, set by the bits M1 and M0. Mode 0 is not commonly used.
The high byte (THx) is cascaded with the low byte (TLx) to produce a 16-bit timer.
This timer counts from 0000H to FFFFH - it has 216 (65,536) states. An overflow occurs
during the FFFFH to 0000H transition, setting the overflow flag (to be dealt with shortly).
The timer low byte (TLx) operates as an 8-bit timer (counting to FFH) while the high-
byte holds a reload value. When the timer overflows from FFH, rather than starting again
from 00H, the value in THx is loaded into TLx and the count continues from there
55
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
In Parallel communication, data being transferred between one location and another
(R0 to the accumulator, for example) travel along the 8-bit data bus. Because of this data bus,
data bytes can be moved about the microcontroller at high speed.
Serial communication has the advantage of requiring only one line for the data, a
second line for ground and possibly a third line for the clock. Therefore, because serial
communication requires less physical wires, it is more suitable for transmitting data over
longer distances.
56
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Synchronous serial communication requires an extra line for the clock signal. For
serial communication, the 8-bit parallel data byte must be shifted down the serial line (in
transmission). Therefore, one bit is followed by another. Some kind of system must be used
to determine how long each bit is on the line. For example, the serial system designer may
decide each bit will be on the line for 1us and, as explained above, transmission of the full
eight bits would take 8us. With synchronous communication, the clock signal is transmitted
on a separate line, as shown in the diagram below.
In this way, the receiver is synchronized with the transmitter. As we shall see, the 8051 serial
port in mode 0 is an example of synchronous serial communication.
57
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
dependent upon the typist. The user may type at a rate of sixty words per minute, but at other
times he/she may type a lot less. And for long periods there may be no data sent at all.
Because of this erratic data rate an asynchronous communication system is suitable.
In any communication system, the receiver must know what kind of data to expect
and at what rate the data will arrive. In both synchronous and asynchronous serial
communication, the receiver needs to know with which bit the transmitter begins. In most
systems the LSB is the first bit transmitted. For an asynchronous system, the number of bits
transmitted per second must be known by the receiver. Since the clock signal is not
transmitted, the receiver needs to know what clock frequency the transmitter is using so that
it can use the same. The receiver also needs to know how many bits per word the transmitter
is using (in most cases we deal with 8-bit words, but we will see cases where nine bits are
transmitted per word). And the receiver needs to know where the data begins and where the
data stops. All these parameters make up the protocol. If the receiver uses the same protocol
as the transmitter is should receive the data correctly (although errors can occur and we will
look at how we catch these errors at a later date). If the receiver uses a protocol other than the
one used by the transmitter, then the two devices are effectively speaking two different
languages and the data received will be garbage.
In asynchronous communication, at least two extra bits are transmitted with the data
word; a start bit and a stop bit. Therefore, if the transmitter is using an 8-bit system, the actual
number of bits transmitted per word is ten. In most protocols the start bit is a logic 0 while the
stop bit is logic 1. Therefore, when no data is being sent the data line is continuously HIGH.
The receiver waits for a 1 to 0 transition. In other words, it awaits a transition from the stop
bit (no data) to the start bit (logic 0). Once this transition occurs the receiver knows a data
byte will follow. Since it knows the data rate (because it is defined in the protocol) it uses the
same clock as frequency as that used by the transmitter and reads the correct number of bits
58
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
and stores them in a register. For example, if the protocol determines the word size as eight
bits, once the receiver sees a start bit it reads the next eight bits and places them in a buffer.
Once the data word has been read the receiver checks to see if the next bit is a stop bit,
signifying the end of the data. If the next bit is not logic 1 then something went wrong with
the transmission and the receiver dumps the data. If the stop bit was received the receiver
waits for the next data word, ie; it waits for a 1 to 0 transition
The 8051 includes an on-chip serial port that can be programmed to operate in one of
four different modes and at a range of frequencies. In serial communication the data is rate is
known as the baud rate, which simply means the number of bits transmitted per second. In the
serial port modes that allow variable baud rates, this baud rate is set by timer 1.
59
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
The 8051 serial port is full duplex. In other words, it can transmit and receive data at
the same time. The block diagram above shows how this is achieved. If you look at the
memory map you will notice at location 99H the serial buffer special function register
(SBUF). Unlike any other register in the 8051, SBUF is in fact two distinct registers – the
write-only register and the read-only register. Transmitted data is sent out from the write-only
register while received data is stored in the read-only register. There are two separate data
lines, one for transmission (TXD) and one for reception (RXD). Therefore, the serial port can
be transmitting data down the TXD line while it is at the same time receiving data on the
RXD line.
The TXD line is pin 11 of the microcontroller (P3.1) while the RXD line is on pin 10
(P3.0). Therefore, external access to the serial port is achieved by connecting to these pins.
For example, if you wanted to connect a keyboard to the serial port you would connect the
transmit line of the keyboard to pin 10 of the 8051. If you wanted to connect a display to the
serial port you would connect the receive line of the display to pin 11 of the 8051. This is
detailed in the diagram below.
60
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Essentially, the job of the serial port is to change parallel data into serial data for transmission
and to change received serial data into parallel data for use within the microcontroller.
along with the data while asynchronous communication requires the use of stop bits
and start bits. However, the programmer wishing to use the 8051 need not worry
about such things. To transmit data along the serial line you simply write to the serial
buffer and to access data received on the serial port you simply read data from the
serial buffer.
Essentially, the job of the serial port is to change parallel data into serial data for
transmission and to change received serial data into parallel data for use within the
microcontroller.
61
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
transmit data along the serial line you simply write to the serial buffer and to access data
received on the serial port you simply read data from the serial buffer.
For example:
MOV SBUF, #45H - this sends the byte 45H down the serial line
MOV A, SBUF - this takes whatever data was received by the serial port and puts it in
the accumulator.
How do we know when the complete data byte has been sent?
As mentioned earlier, it takes a certain length of time for a data byte to be transmitted
down the serial line (determined by the baud rate). If we send data to SBUF and then
immediately send more data to SBUF, as shown below, the initial character will be
overwritten before it was completely shifted down the line.
Therefore, we must wait for the entire byte to be sent before we send another. The serial port
control register (SCON) contains a bit which alerts us to the fact that a byte has been
transmitted; ie; the transmit interrupt flag (TI) is set by hardware once an entire byte has been
transmitted down the line. Since SCON is bit-addressable we can test this bit and wait until it
is set, as shown below:
MOV SBUF, #23H; send the first byte down the serial line
JNB TI, $; wait for the entire byte to be sent
CLR TI; the transmit interrupt flag is set by hardware but must be cleared by software
MOV SBUF, #56H; send the second byte down the serial line
62
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Similarly, we need to know when an entire byte has been received by the serial port.
Another bit in SCON, the receive interrupt flag (RI) is set by hardware when an entire byte is
received by the serial port. The code below shows how you would program the controller to
wait for data to be received and to then move that data into the accumulator.
Addition:
LCALL 03 Halt
Subtraction:
LCALL 03 Halt
63
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Multiplication:
LCALL 03 Halt
Division:
LCALL 03 Halt
Exchange:
LCALL 03 Halt
64
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
Increment :
LCALL 03 Halt
Decrement:
LCALL 03 Halt
65
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
B.SURESH
Asst Professor
Department of ECE
66
www.sureshQ.blogspot.in
MP&MC LAB MANUAL
Department of ELECTRONICS AND COMMUNICATION ENGINEERING
MICROPROCESSORS
AND
MICROCONTROLLERS
67
www.sureshQ.blogspot.in