Beruflich Dokumente
Kultur Dokumente
-------------------------------------------------------------------------------
PART B
Introduction
8086
8255 I/O
device
8255 is available in
the I/O card fitted into
IBM pc expansion slot
of mother board
IBM PC has expansion slots, through these slots different I/O card can be connected. All the address
lines, data lines and control signals from the microprocessor are available for the expansion of the
system. For simple I/O device interface, an I/O card with 8255 chip is available. This card can be fit
into the slot available in the mother board. Pin outs of 8255 are made available through a connector
outside the system. Different I/O modules can be connected to the I/O card output connector using a
flat cable.
8255
8255 is a Programmable Peripheral device used for parallel data transfer. It has 40 pins. Out of 40
pins, 24 pins are I/O pins which may be individually programmed in 3 groups of 8-bit ports : port-
A, port-B and port-C.
Port-C can be grouped into two 4-bit ports Cupper and Clower
Features of 8255
What is a port?
A port is usually an interface through which data are sent and received
The 8255 can operate in three I/O modes: mode0, mode1 and mode2
In mode0, Port A & Port B, Port C U & Port CL can be configured as simple 8-bit input or output
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
ports.
All these modes can be selected by programming a register internal 8255 known as control word
register (CWR).
The ports of 8255 can be programmed by writing a single control word into the control register
when required
Mode0 :
7 6 5 4 3 2 1 0
100000000
Sample Program:
mov dx, 0123h ; address of control word register into dx
mov al, 80h ; load al with control word
out dx,al ; send control word
8a). Implement a BCD Up-Down Counter (00-99)on the Logic Controller Interface.
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
.model small
.stack 200
.data
pa=0d880h ; port address assigned in order
pb=0d881h
pc=0d882h
ctrl=0d883h
cw= 80h
msg db 'press any key to come to dos prompt$'
.code
mov ax,@data ; initialization of data segment in CS
mov ds,ax
lea dx,msg
mov ah,09h ; interrupt to display the message
int 21h
mov al,cw ; control word decision
mov dx,ctrl
out dx,al
mov dx,pa
mov al,0oh
upcnt: out dx,al
call delay
add al,1
daa
call kbhit
cmp al,99h
je dncnt
jne upcnt
dncnt: out dx,al
call delay
sub al,1
das
call kbhit
cmp al,00
je upcnt
jne dncnt
kbhit proc
push ax
mov ah,01h ; interrupt that waits until any key is pressed
int 16h
jnz exit
jmp l1
exit: mov ah ,4ch
int 21h
l1: pop ax
ret
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
kbhit endp
;---delay procedure-----
delay proc
mov di,2000h ; procedure with suitable delay
tere:mov cx,0ffffh
here:loop here
dec di
jnz tere
ret
delay endp
end
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
8b). Read the status of two 8-bit inputs (X & Y) from the Logic controller Interface and
display X*Y.
.model small
.stack 200
.data
pa=0d880h ; port address assigned in order
pb=0d881h
pc=0d882h
ctrl=0d883h
m1 db 10,13,’ enter 1st data from port B$’
m2 db 10,13,’ enter 2nd data from port B$’
msg db 'press any key to come to dos prompt$'
.code
mov ax,@data ; initialization of data segment in CS
mov ds,ax
mov al,8ah
mov dx,ctrl ; control word decision
out dx,al
lea dx,m1
mov ah,09h ; interrupt to display the message
int 21h
bg:
mov dx,pb ; accepting the 1’st i/p from port B
in al,dx
mov bl,al
call delay
lea dx,m2
mov ah,09h ; interrupt to display the message
int 21h
mov dx,pb ; accepting the 2’nd i/p from port B
in al,dx
mul bl
push ax
mov dx,pa
mov al,ah
out dx,al
call delay
pop ax
mov dx,pa
out dx,al
mov ah,4ch
int 21h
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
delay proc
mov di,2000h ; procedure with suitable delay
tere: mov cx,0ffffh
here: loop here
dec di
jnz tere
ret
delay endp
end
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
9). Display FIRE and HELP alternatively with flickering effects on a seven-segment display
interface for a suitable period of time. Ensure a flashing rate that makes it easy to read both
the messages.
Seven segment display interface provides a four digit 7 segment display driven by the output of four
cascaded serial-in parallel-out shift registers. Hex code of Character/digit to be displayed is
transmitted serially bit by bit to the interface over the port line PB0.
Characters are displayed starting from the last display ( i.e fourth one )
Each bit is clocked into the shift registers by providing a clock through the port line PC0.
Figure shows the schematic of the seven segment display interface
.glow
. blank
For displaying any character the corresponding segments must be given low inputs.
Example:
For displaying digit 3, segments a, b, c, d, g must be given low inputs (i.e. 0’s) and the rest high
inputs (i.e. 1’s)
Segment h g f e d c b a
Inputs 1 0 1 1 0 0 0 0
Hex code B 0
Code to display digits are given in the table below
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
Displayed Hex
Digit code Displayed Hex
0 C0 Digit code
1 F9 A 88
2 A4 b 83
3 B0 c C6
4 99 d A1
5 92 E 86
6 82 F 8E
7 F8
8 80
9 90
.model small
.data
pa=1080h
pb=1081h
pc=1082h
cr=1083h
msg db 'press any to come to dos prompt$'
fire db 86h,0ceh,0cfh,8eh ;codes to store chars E, R, I, F
blnk db 0ffh,0ffh,0ffh,0ffh ;codes to store 4 blanks
help db 8ch,0c7h,86h,89h ;codes to store chars P, L, E, H
.code
mov ax,@data
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
mov dx,cr ;initialize 8255 with portB and portC as output ports
mov al,80h ;no need of input ports here
out dx,al
start:
lea si,fire ;initially, point si to address of code of E in ERIF,
call disp ;then display E, then R, I, F successively
call delay ;call delay between displays of FIRE and HELP
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
lea si,blnk
call disp
call delay
mov ah,01 ;DOS subfunction 01h of 16h checks whether key has
int 16h ;been pressed on kdb, if so, stop and return to DOS
jz start ;else continue with flickering display
mov ah,4ch
int 21h
;-----display procedure----
disp proc
mov cx,4 ;load cx with number of chars to display
nxtchr:
mov bl,8 ;load bl with number of segments in each char
mov al,[si] ;al has the code of first char to display
nxtbit:
rol al,1 ;LSB of al has data for on/off of a-seg, and so on, and
;MSB of al has data for on/off of h-seg. But first data
;sent to 7-seg LED has to be for h-seg. So we rotate the
;MSB into LSB position and send this bit to h-seg to on/off it.
mov dx,pb
out dx,al ;the LSB in al is sent on portB to 7-seg LED
mov dx,pc
mov al,00 ;send data pulse thro portC, first low (00h), then high (0ffh).
out dx,al ;This pulse, along with on/off data, will on/off
mov al,0ffh ;the particular segment
out dx,al
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
disp endp
;-----delay procedure------
delay proc
mov di,0ffffh
there: mov cx,2000h
here:loop here
dec di
jnz there
ret
delay endp
end
10) Drive a stepper motor interface to rotate the motor in clockwise(or anti clockwise)
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
direction by N steps. Introduce suitable delay between successive steps.
Stepper motor
A stepper motor is an electromechanical device which converts electrical pulses into discrete
mechanical movements. The shaft or spindle rotates in discrete step increments when electrical
pulses are applied in proper sequences.
Stepper can be good choice whenever controlled movement is required. They can be used advantage
in application where you need to control rotation angle, speed, position, and synchronization.
Examples: In printers, hard disk drive, fax machines etc.
The operating voltage is +12V D.C. the step angle is 1.8 degrees.
The parts:
Rotor: the rotating center position. Term may refer to the winding that is on the rotor.
Stator: the stepper motor has 4 stator winding around the rotor.
To control the direction and speed appropriate pulses are applied to the stator windings of the motor.
Four pins (PC0, PC1, PC2 and PC3) of an 8255 are used to excite the windings. Each of the four
pins are connected to the respective windings through an interfacing circuit.
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
8086
A
PC0
Stepper
B Motor
PC1
Windings
8255
C
PC2
D
PC3
lea dx,msg
mov ah,09h
int 21h
mov cx,n
mov dx,pc
mov al,88h ; data to excite one of the winding of the stepper
ag:
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
out dx,al
push cx
call delay ; call delay so that stepper motor rotates by an angle 1.8 degree
pop cx
ror al,1 ; Rotate to excite the next winding
loop ag ; Repeat to excite the winding
mov ah,4ch ; Terminate the program
int 21h
;---delay procedure---
delay proc
mov di,2000h
L1:mov cx,0ffffh
L2:loop L2
dec di
jnz L1
ret
delay endp
end
11a) Generate a sine wave using the DAC interface (the output of the DAC is to
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
be displayed on a CRO)
DAC module consists of 0800 DAC chip, an Op-amp. The output voltage of +5V is obtained from
the DAC when the digital input is FFH and output will be 0 Volts when the digital input is 00H.
The output of the DAC 0800 is fit to the Op-amp to get the final output at XOUT.
8255
PortA/PortB
+12V
-12V
The parallel 8-bits data can be fed into the DAC from PortA and PortB. The required +12V, -12V
and GND are supplied from an external power supply to the module. The X OUT should be connected
to the CRO to read the analog o/p data. Programming 8255 interfaced to DAC can generate the
required waveform.
FFH
80H
00H
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
cw equ 80h
msg db 10,13,"press any key to exit",10,13,"$"
table db 80h,96h,0ABh,0C0h,0D2h,0E2h,0EEh,0F8h,0FEh,0FFh ; Initialize values to
db 0FEh,0F8h,0EEh,0E2h,0D2h,0C0h,0ABh,96h,80h ; plot one cycle
db 69h,54h,40h,2Dh,1Dh,11h,07h,01h,00h
db 01h,07h,11h,1Dh,2Dh,40h,54h,69h
.code
mov ax,@data
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
mov ah,01 ; read a key from the keyboard to stop the program from running
int 16h
jz start; else the key is not pressed, repeat the generation of sine wave
11b) Generate a Half rectified sine wave form using the DAC interface
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
lea dx,msg
mov ah,09h
int 21h
start:mov cx,18 ; counter to plot 18 values on CRO to generate +ve half cycle
lea si,table ; point si to the table values
bg:mov al,[si] ; Load al with value to be plotted on CRO
mov dx,pa
out dx,al ;output the value in al to port-A/port-B to plot the point on CRO
mov dx,pb
out dx,al
inc si ; increment si to point to next value
loop bg ; repeat this till all the 18 points are plotted on CRO
mov cx,18 ; counter to plot 18 values (80h) on CRO to generate -ve half cycle
mov al,80h
back:mov dx,pa
out dx,al ;output the value in al to port-A/port-B to plot the point on CRO
mov dx,pb
out dx,al
loop back
mov ah,01 ; read a key from the kbd to stop the program from running
int 16h
jz start ; else the key is not pressed, repeat the generation of half rectified wave
mov ah,4ch
int 21h
end
12). To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
programs in C language for displaying text messages and numbers on LCD
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
MSG++;
}
}
DISPLAY_MESSAGE (0x80, " CHIPMAX DESIGN "); // Address of first row and message
DISPLAY_MESSAGE (0xC0, "0123456789ABCDEF"); // Address of second row and
message
while(1)
{
LCD_CMD(0x18); //to shift message to LEFT use code: 0x18,Right:0x1C,Stable:0x06
DELAY_1S(50);
}
}
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
LCD_CMD(0x0C); // Display Switch Command : Display on, Cursor on, Blink off
LCD_CMD(0x06); // Input Set : Increment Mode
LCD_CMD(0x01); // Screen Clear Command , Cursor at Home
}
void DISPLAY_MESSAGE(unsigned char ADDRESS,char *MSG)
// Function to display a complete message
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void DISPLAY_TEMPERATURE(unsigned int TEMPERATURE)
// Function to display temperature values
{
LCD_CMD(0xCA);
LCD_DATA((TEMPERATURE % 10000/1000) | 0x30);
LCD_DATA((TEMPERATURE % 1000/100) | 0x30);
LCD_DATA((TEMPERATURE % 100/10) | 0x30);
LCD_DATA('.');
LCD_DATA((TEMPERATURE % 10/1) | 0x30);
return;
}
void INIT_ADC() // initializing ADC
{
PINSEL1 |= 0x01000000; // selecting P0.28/AD0.1 as an ADC pin
AD0CR = 0x00200602;
}
int READ_ADC() // Reading ADC values from pin
{
int VAL;
AD0CR |= 0x01000000;
do
{
VAL = AD0DR1;
}
while (!(VAL & 0x80000000));
AD0CR &= ~0x01000000;
VAL >>=6;
VAL = VAL & 0x3FF;
return(VAL);
}
int TEMPERATURE_VALUE() //
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
Convering the adc value to Tempeature
{
unsigned int CNT,TEMPERATURE=0;
unsigned long int TEMP_SUM=0,TEMP_AVG=0;
for(CNT=0;CNT<5000;CNT++)
{
TEMPERATURE = READ_ADC();
TEMP_SUM = TEMP_SUM + TEMPERATURE;
}
TEMP_AVG = (TEMP_SUM/5000);
TEMPERATURE = TEMP_AVG;
TEMP_SUM = TEMP_AVG = 0;
TEMPERATURE = (1000*(TEMPERATURE*(3.901/1024)))-100;
return TEMPERATURE;
}
int main() // Main Function
{
IO0DIR =0x00000E00; // Pin from P0.9 to P0.11 configured as output pins.
IO1DIR =0X00FF0000; // Pin from P1.16 to P1.23 configured as output pins.
LCD_INIT(); // LCD initialize
INIT_ADC(); // ADC initialize
DISPLAY_MESSAGE(0x80," TEMPERATURE "); // first row message
DISPLAY_MESSAGE(0xC0,"DEGREE C = "); // second row message
while(1)
{
DISPLAY_TEMPERATURE (TEMPERATURE_VALUE());
// reading and updating the temperature value in infinite loop
}
}
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
#include <LPC214x.H> // Header file for LPC2148
unsigned int LDR = 0x00010000; // Pin P0.16 configured as LDR input signal
unsigned int LED = 0x00040000; // Pin P0.18 configured as LED ouput signal
void DELAY_1S(unsigned int n) // is delay
{
unsigned int i,j;
for(i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
void POWER_SAVING_SYSTEM(unsigned int TIME) // function for power saving system
{
unsigned int TEMP=0;
TEMP = IO0PIN;
TEMP = TEMP<<2;
IOSET0 = TEMP;
IOCLR0 = ~TEMP;
DELAY_1S(TIME);
}
int main() // Main Function
{
IO0DIR =0x00040000; // Pin P0.16 is input and P0.18 is an output pin
while(1)
{
POWER_SAVING_SYSTEM(100); // Power saving system with time adjustment
Viva Questions
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
1). Define mp – if whole processing unit is installed on single IC is called mp.
2). List general purpose register- AX-Accumulator, BX- base register, CX-counter reg, DX-
implied operand, SI- source index, DI-destination index, SP-stack pointer, BP-base pointer.
3). How many byte queue is there in 8086 & 8088 --- 6 byte and 4 byte.
4). How many bit flag register is there in 8086---16 bit.
5). List conditional flag of 8086 – CF,AC,PF,SF,OF,ZF.
6). Use of flag reg: used for conditional operation.
7). Mention system bus : address bus, data bus & control bus.
8). Address bus is ----uni-directional and is of 20 bit in 8086.
9). Data bus --- is bi-directional and 16-bit in 8086 and 8-bit in 8088.
10). On what basis u say that a processor is 8-bit or 16-bit or 32-bit based on the processing unit.
11).Difference between *procedure & macro *8086 & 8088 *minimum mode & maximum mode
12).Explain instructions : XLAT, DAA, AAM, ADC.
13). How to set & reset DF (direction flag) --- STD & CLD.
14). Draw back of recursive technique – time consuming due to lot of stacking operation.
15). Advantage of macro –very fast as no stacking operation is require.
16). One machine cycle has ----4 T-States
17).Explain :--- NMI,RESET,READY,INTR, HOLD , LOCK,.
18). Register is represented by ---3 bits in machine language.
19). Define addressing mode—it is way to access the information from memory
20). List out addressing modes present : immediate, implied, direct, register, register indirect,
base-indexed, etc.
21). Explain how to calculate physical address in memory addressing mode :--
PA= Segment address * 10h + offset address
22). Advantage of multiplexing --- reduces the complexity, reduces the number of pins.
23). Use of ground pin – safe guard the circuit.
24). Which pins can be multiplexed :-- only those pins which are not used at the same time.
Eg: address & data pins, status & address pins
25). Advantage of segmentation:-- for faster accessing, extention of memory, security.
26).What is 8255-it is a PPI(peripheral programmable interface)used to connect to outside
world(to/ for)
27). Explain reset operation: if reset is pressed high for 4 clock cycle it gets reseted, and all reg
=0000.
28). Explain the logic of all program?
29). Who introduces the wait state : READY pin.
30). Write the control world of 8255? I/O, M,M,PA,PCU,M,PB,PCL.
31). Write the program to generate the square wave, triangle wave.
32). Shift register works in SERIAL IN PARALLEL OUT mode.
33). Clock pulse is applied to – port C.
34). Explain ROR,ROL,SHL,SHR.
35). In & Out Instruction works with – AL & DX pair register.
36). With respect to signed operation which is greater –08H or 80H(08 is greater because sign bit
is zero)
37). Who generates clock, ready & reset in 8086 : 8284 clock generator.
38). What is assembler?
39). Explain stacking operation in recursive factorial program.
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
40). What is real time application of sorting, searching :--- maintain huge database.
41). What is real time application :-- stepper motor – positioning the hard disk
42). What is real time application :--DAC :--- in phones, etc.
43). What is real time application :-- Counter – in digital clock, signals
44). How to enable the decoder ? by having g1*, g2* =0 and g3=1
45). All control signals are activated during --- T2 and T3 state
46). Explain the 8259 counter.
47). What is DMA operation?
48). When is DMA operation is required?
49). Explain the generation of microprocessor.
50). What are co-processor? Explain how floating point operation can be done?
51). Explain 8087 coprocessor.
52). List the control signals generated in maximum mode? Using what pins it is generated.
53). Explain QS0 and QS1 pins.
54). What is interrupt?
55). List five software interrupts present.
56). What are maskable and nonmaskable interrupt?
57). Explain how file can be created and deleted using int 21h
58). What is the interrupt to access system time?
59). What is the interrupt to print a string on the monitor?
60). Explain int 16H interrupt?
Sample Programs
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
1. Write an ALP to find factorial of number for 8086
.model small
.code
mov ax,03
mov cx,02
back: mul cx
mov dx,ax
dec cx
jnz back
mov ah,4ch
int 21h
End
.model small
.data
dvd dd 15752510h
dvr dw 0ffffh
qut dw ?
rem dw ?
.code
Start: Mov ax,@data ; Initialization of data segment.
Mov ds, ax
Mov si, offset dvd ; copy the offset of dividend to si.
Mov ax, word ptr [si] ; copy the dividend o ax and dx
Mov dx, word ptr [si+2]
Mov cx, dvr ; copy the divisor to cx
Div cx
Mov qut, ax ; copy the ax to quoitent
Mov rem, dx ; copy the dx to reminder
Int 3 ; Terminate the program
End start
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
Read macro ; macro to read ASCII value
Mov ah, 01h
Int 21h
Endm
Write macro X
Mov dl, X ; macro to display ASCII value
Mov ah, 02h
Int 21h
Endm
.code
Start: Mov ax,@data
Mov ds, ax ; Initialization of data segment
Read; read 1st no.
Mov bl, al ; copy al to bl
Write ‘+’
read ; read 2nd no.
Mov cl, al
Write ‘=’
Mov al, cl
add al,bl ;result in hex
mov ah, 0
aaa ;converts to unpacked BCD
add ax,3030h
push ax
write ah ;displays higher nibble
pop ax
write al ;displays higher nibble
Int 3 ; Terminate the program
End start
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018