Professional Documents
Culture Documents
MICROPROCESSORS &
MICROCONTROLLERS
LAB MANUAL
Page 1
Page 2
Syllabus
I. Microprocessor 8086:
1. Introduction to TASM/MASM
2. Arithmetic operation Multi byte addition and subtraction, multiplication and division-signed
and unsigned arithmetic operation, ASCII-arithmetic operation.
3. Logic operations- Shift and rotate- converting packed BCD to unpacked BCD, BCD to ASCII
conversion.
4. By using string operation and instruction prefix: Move block, reverse string, sorting, inserting,
deleting, length of the string, string comparison.
5. DOS/BIOS programming: Reading keyboard (Buffered with and without echo)-Display
characters, strings.
II. Interfacing:
1. 8259 Interrupt Controller : Generate an Interrupt using 8259 timer.
2. 8279 Keyboard display : Write a small program to display a string of Characters.
3. 8255 PPI : Write ALP to generate sinusoidal wave using PPI.
4. 8251 USART : Write a program to establish communication between two processors.
Page 3
Page 4
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. Next step is to process the object file with linker.
Page 5
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
C:\TASM\BIN> Edit filename. Asm
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.
C:\TASM\BIN > TASM filename. asm X, Y, Z
With this command assembler generates three files.
4. 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.
5. 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.
6. 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.
Next step is to process the object file with linker.
C:\TASM\BIN>TLINK filename . obj
A Linker is a program used to join several object files into one layer object file
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)
Next Run
C:\TASM\BIN> TD filename.exe
Page 6
FOR EXAMPLE
. MODEL SMALL
. STACK size of stack ; define stack
. DATA ; define data segment
-----------Define variables
----------. CODE ; define code segment
HERE : MOV AX, @DATA ; load ES,DS
MOV ES, AX
MOV DS, AX
------------------------. EXIT 0 ; exit to DOS
END HERE
(or)
We can write Code segment as follows.
. CODE ; Define Code Segment
. STARTUP
---------. EXIT 0
END
Page 7
SMALL
MEDIUM
COMPACT
LARGE
HUGE
FLAT
Description
All data and code must fit into
one segment. Tiny programs are
written in .COM format, which
means that the program must be
originated at location 100H
This model contains two
segments: one data segment of
64K bytes and one code segment
of 64K bytes.
This model contains one data
segment of 64K bytes and any
number of code segments for
large programs.
One code segment contains the
program, and any number of data
segments contains the data.
The large model allows any
number of code and data
segments.
This model is the same as large,
but the data segments may
contain more than 64K bytes
each.
Only available to MASM 6.X.
The flat model uses one segment
of 512K bytes to tore all data and
code. Note that this model is
mainly used with Windows NT
Page 8
Page 9
Page 10
Page 11
Page 12
Page 13
PROGRAMS IN SYLLABUS:
8086 Assembly Language program1:
Adding two multi byte numbers and store the result as the third number:
DATA SEGMENT
BYTES EQU 08H
NUM1 DB 05H, 5AH, 6CH, 55H, 66H, 77H, 34H, 12H
NUM2 DB 04H, 56H, 04H, 57H, 32H, 12H, 19H, 13H
NUM3 DB 0AH DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV CX, BYTES
LEA SI, NUM1
LEA DI, NUM2
LEA BX, NUM3
MOV AX, 00
NEXT: MOV AL, [SI]
ADC AL, [DI]
MOV [BX], AL
INC SI
INC DI
INC BX
DEC CX
JNZ NEXT
INT 3H
CODE ENDS
END START
Page 14
Page 15
Page 16
Page 17
Page 18
Page 19
Page 20
Page 21
Page 22
Page 23
Page 24
Page 25
Study module card is connected to the 8086 kit through a 50 pin FRC cable. Before
making connections check the polarity of the cable.
It consists of 8259, 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.
8259 is connected to IR4
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
Enter the program as given
Step 3
Enable Single Stepping by Switch of module & kit.
Step 4
Execute the Program and observe the results on the LEDs
Step 5
0 implies LED is OFF and 1 implies LED is ON DATA BUS
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.
Addresses FOR 8086 CPU
IRR ( Interrupt Request Register) - 60 H
IMR (Interrupt Mask Register) - 66 H
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.
0400 B8 00 00 MOV AX, 0000 ; Data segment is initialize to zero
0403 8E D8 MOV DS, AX
0405 B8 00 20 MOV AX, 2000 ; interrupt location is defined
0408 89 06 00 00 MOV [0000], AX
040C B8 00 00 MOV AX, 0000
040F 89 06 02 00 MOV [0002], AX
0413 B0 17 MOV AL, 17 ; ICW1 Command
0415 E6 60 OUT 60, AL
0417 B0 00 MOV AL, 00 ;ICW2 Command
0419 E6 66 OUT 66, AL
041B B0 01 MOV AL, 01 ; ICW4 Command
Page 26
Page 27
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.
Step2: Read FIFO command for checking display RAM.
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 6: Write the byte 55H to all display RAM locations.
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.
Description of the Program:
Address
Opcode
Label
Mnemonic
Description
0400
KBD
MOV DX,FFFF
0403
0405
0406
BA FF FF
B0 90
EE
B7 00
0408
040A
INIT
B3 01
88 D8
SCAN
040C
040F
0410
0413
0414
EC
E8 27 00
0417
0419
041B
3C 08
78 10
80 C7 08
BA FD FF
EE
BA F9 FF
MOV AL,90
OUT DX,AL
MOV BH,00
Initialize the final
key code in Reg.
BH
MOB BL,01
Put the walking one
pattern in register C with
one LSB position
MOV AL, BL
Move the pattern
in AL on port C
MOV DX, FFFD
OUT DX, AL
MOV DX, FFF9
IN AL,DX
Input Port A
CALL CODE
Classify the 8 word into
8 bits
CMP AL,08
Any Ke closure
JS DISP
Yeas go to display it
ADD BH,08
Increment the PC code
in the partial result.
Page 28
80 FF 18
79 E3
CMP BH,18
JNS INIT
Page 29
Page 30
Page 31
8051
1. Reading and writing on a parallel port.
1. Writing to a port pin
SETB P3.5; set pin 5 of port 3
MOV P1, #4AH; sending data 4AH to port 1 - the binary pattern on the
port will be 0100 1010 MOV P2, A; send whatever data is in the accumulator to port 2
2. Reading a port pin
SETB P1.0 ; initialize pin 0 of port 1 as an input pin MOV P2, #FFH ; set all pins of port 2
as inputs MOV C, P1.0 ; move value on pin 0 of port 1 to the carry MOV R3, P2 ; move
data on port 2 into R3
Page 32
1
0
M1
M0
0
0
M1
0
M0
0
Mode
0
0
1
1
0
1
2
is an event counter,
when cleared timer
is an interval timer.
Mode bit 1
Mode bit 0
Description
13-bit timer mode
(this mode exists
simply to keep the
8051
backwards
compatible with its
predecessor,
the
8048, which had a
13-bit timer) - we
will not be using
mode 0.
16-bit timer mode
8-bit
auto-reload
mode
Split timer mode this mode will be
dealt with at a later
stage
There are four timer modes, set by the bits M1 and M0. Mode 0 is not commonly used.
Mode 1 - 16-bit mode
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).
Mode 2- 8-bit auto-reload mode
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.
Page 33
Page 34
Page 35
Page 36