Sie sind auf Seite 1von 30

Microprocessors and Microcontrollers Lab Manual

-------------------------------------------------------------------------------
PART B
Introduction

Interfacing 8086 with I/O devices through 8255

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

.It can be programmed to transfer data from i/o device.


.It has 3 8bit ports : portA, portB and portC

What is a port?
A port is usually an interface through which data are sent and received

Operating modes of 8255

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 :

Control word format

7 6 5 4 3 2 1 0

Mode set flag Port C(lower)


1= active 1-i/p, 0-o/p
Mode selection port A
Port B
00-mode0 1-i/p, 0-o/p
01-mode1 mode selction port B
xx-mode2 0- mode0, 1- mode1

Port A Port C (upper)


1- i/p, 0-o/p 1-i/p, 0-o/p

Exercise1: Write a control word to initialize 8255 port C as output port

100000000

Control word = 80H

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 LED display interface

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

Each display has seven segments and a dot ( a,b,c,d,e,f,g,h and . )


It is shown in the figure below.

.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

TO DISPLAY FIRE AND HELP ALTERNATIVELY

.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

lea si,blnk ;point si to the blanks, to clear all 4 7-seg LED


call disp ;displays
call delay

----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------

lea si,help ;initially, point si to address of code of P in PLEH,


call disp ;then display P, then L, E, H successively
call delay

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

push ax ;since al is used to send clock signal, save current


;contents on stack

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

pop ax ;restore contents of al from stack to continue with


;remaining segments of same 7-seg LED.

dec bl ;are all segments displayed?


jnz nxtbit ; if not, display remaining segments
inc si ;point to the code of next char to be displayed
loop nxtchr ;are all chars displayed? if not, display remaining characters
ret

----------------------------------------------------------------------------
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.

Figure. Stator winding


connection

General diagram of the stepper motor interfacing is given below.

----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------

8086

A
PC0
Stepper
B Motor
PC1
Windings
8255
C
PC2
D
PC3

title STEPPER MOTOR IN CLOCK WISE


.model small
.data
pa=0d880h
pb=0d881h
pc=0d882h
cr=0d883h ; control word register address
cw=80h ; control word to make port-C as output
n dw 10 ; counter to rotate stepper motor 10 steps i.e. 18 degrees
msg db 'rotation in clock wise','$'
.code
mov ax,@data
mov ds,ax

lea dx,msg
mov ah,09h
int 21h

mov al,cw ; Initialize 8255, port-C output


mov dx,cr
out dx,al

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)

Digital to Analog Module

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

DAC 0800 Xout

-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.

The waveform is shown below

FFH

80H

00H

The formula to calculate points: 128 + 128 sinθ


If θ = 0 , point1 = 128 + 128 sin0 = 128 + 0 =128(in decimal) = 80H ( in hex)
θ = 90, point = 128 + 128 sin90 = 128 + 128 = 256(in decimal)= FFH (in hex)
Similarly if θ = 180, point N = 128 + 128 sin 180 = 128 = 80H (in hex)

title GENERATION OF SINE WAVE


.model small
.data
pa equ 0d880h
pb equ 0d881h
pc equ 0d882h
cr equ 0d883h

----------------------------------------------------------------------------
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 dx,cr ; Initialize 8255, port-A & port-B as output


mov al,cw
out dx,al

start:mov cx,36 ; counter to plot 36 values on CRO to generate one cycle


lea si,table ; point si to the table values
again: 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 36 points are plotted on CRO

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

mov ah,4ch ; terminate the program


int 21h
end

11b) Generate a Half rectified sine wave form using the DAC interface

----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------

title GENERATION OF HALF-RECTIFIED WAVE


.model small
.data
pa equ 0d880h
pb equ 0d881h
pc equ 0d882h
cr equ 0d883h
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 plot
db 0feh,0f8h,0eeh,0e2h,0d2h,0c0h,0abh,96h ; one +ve half cycle
.code
mov ax,@data
mov ds,ax

lea dx,msg
mov ah,09h
int 21h

mov dx,cr ; Initialize 8255, port-A & port-B as output


mov al,cw
out dx,al

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

#include <LPC214x.H> // Header file for LPC2148


#include <STRING.H> // Header file for string manipulations
#define LCD_DATA_PORT(DATA) (DATA << 16)
// Pin from P1.16 to P1.23 configured as LCD data port.
#define LCD_CMD_PORT(CMD) (CMD << 8)
// Pin from P0.9 to P0.11 configured as LCD control signals.
// Pin P0.11 configured as LCD enable signals. (high to low) ENABLE = 0x08;
// Pin P0.10 configured as LCD read/write signals. (1-read, 0-write) RD_WR = 0x04;
// Pin P0.9 configured as LCD register seletion signals.(1-data, 0-command) RE_SE = 0x02;*/

void DELAY_1S(unsigned int n) // 1s delay


{
unsigned int i, j;
for(i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
void LCD_ENABLE() // Singal for LCD enable (high to low with 50ms)
{
IO0SET = LCD_CMD_PORT(0x08); // enable is set to 1
DELAY_1S(50); // 50ms delay
IO0CLR = LCD_CMD_PORT(0x08); // enable is cleared to 0
}
void LCD_DATA(unsigned int LDATA) // function to display the message
{
IO1PIN = LCD_DATA_PORT(LDATA); // moving the message to LCD data port
IO0CLR = LCD_CMD_PORT(0x04); // LCD to write mode(RD_WR = 0)
IO0SET = LCD_CMD_PORT(0x02); // LCD to data mode (RE_SE = 1)
LCD_ENABLE(); // Latching the data to display from buffer
}
void LCD_CMD(unsigned int LCMD) // function to configure the LCD
{
IO1PIN = LCD_DATA_PORT(LCMD); // moving the command to LCD data port
IO0CLR = LCD_CMD_PORT(0x04); // LCD into write mode (RD_WR = 0)
IO0CLR = LCD_CMD_PORT(0x02); // LCD into command mode (RE_SE = 0)
LCD_ENABLE(); // Latching the data to display from buffer
}
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);

----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
MSG++;
}
}

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 initialize
LCD_CMD(0x38); // 8 Bit Mode, 2 Rows, 5x7 Font Style
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

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);
}
}

13). To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148. Write a


program to rotate stepper motor

----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------

#include <LPC214x.H> // Header file for LPC2148


#define MOTOR_PORT(DATA) (DATA << 16)// Pin from P1.16 to P1.19 configured as motor
port.
unsigned char COUNT=0;
unsigned int j=0;
unsigned int CLOCK[4] = {0x03,0x09,0x0C,0x06}; // data for clockwise rotation
unsigned int ANTI_CLOCK[4] = {0x06,0x0C,0x09,0x03}; // data for anti-clockwise rotation
void DELAY_1S(unsigned int n) // 1s delay
{
unsigned int i,j;
for(i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
//Function for clockwise direction
void CLOCK_WISE_DIRECTION(unsigned int STEP, unsigned int TIME)
{
for(j=0;j<=STEP;j++)
{
IO0PIN = MOTOR_PORT(CLOCK[COUNT]);
COUNT ++;
DELAY_1S(TIME);
if(COUNT==4) COUNT=0;
}
}
//Function for anti-clockwise direction
void ANTI_CLOCK_WISE_DIRECTION(unsigned int STEP, unsigned int TIME)
{
for(j=0;j<=STEP;j++)
{
IO0PIN = MOTOR_PORT(ANTI_CLOCK[COUNT]);
COUNT ++;
DELAY_1S(TIME);
if(COUNT==4) COUNT=0;
}
}
int main() // Main function
{
IO0DIR = 0x000F0000; // Pin from P1.16 to P1.19 configured as output pins.
while(1) // infinite loop
{
CLOCK_WISE_DIRECTION (200,10); // clockwide direction with step and speed
ANTI_CLOCK_WISE_DIRECTION(200,10); // anti-clockwide direction with step and speed
}
}
Study Experiments:
1. Interfacing of temperature sensor with ARM freedom board (or any other ARM
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
microprocessor board) and display temperature on LCD

#include <LPC214x.H> // Header file for LPC2148


#include <STRING.H> // Header file for string manipulations
#define LCD_DATA_PORT(DATA) (DATA << 16) // Pin from P1.16 to P1.23 configured as
LCD data port.
#define LCD_CMD_PORT(CMD) (CMD << 8) // Pin from P0.9 to P0.11 configured as LCD
control signals.
unsigned int ENABLE = 0x08; // Pin P0.11 configured as LCD enable signals. (high to low)
unsigned int RD_WR = 0x04; // Pin P0.10 configured as LCD read/write signals. (1-read, 0-
write)
unsigned int RE_SE = 0x02;// Pin P0.9configured as LCD register seletion signals(1data,0-
command)
unsigned int TEMP=0,ADC=0;
void DELAY_1M(unsigned int VALUE) // 1ms delay
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void LCD_ENABLE() // Singal for LCD enable (high to low with 50ms)
{
IO0SET = LCD_CMD_PORT(ENABLE); // enable is set to 1
DELAY_1M(50); // 50ms delay
IO0CLR = LCD_CMD_PORT(ENABLE); // enable is cleared to 0
}
void LCD_DATA(unsigned char LDATA)
{
IO1SET = LCD_DATA_PORT(LDATA); // moving the message to LCD data port
IO1CLR = ~(LCD_DATA_PORT(LDATA)); // moving the message to LCD data port
IO0CLR = LCD_CMD_PORT(RD_WR); // LCD to write mode (RD_WR = 0)
IO0SET = LCD_CMD_PORT(RE_SE); // LCD to data mode (RE_SE = 1)
LCD_ENABLE(); // Latching the data to display from buffer
}
void LCD_CMD(unsigned int LCMD)
{
IO1SET = LCD_DATA_PORT(LCMD); // moving the command to LCD data port
IO1CLR = ~(LCD_DATA_PORT(LCMD)); // moving the command to LCD data port
IO0CLR = LCD_CMD_PORT(RD_WR); // LCD into write mode (RD_WR = 0)
IO0CLR = LCD_CMD_PORT(RE_SE); // LCD into command mode (RE_SE = 0)
LCD_ENABLE(); // Latching the data to display from buffer
}
void LCD_INIT() // initializing the LCD with basic commands
{
LCD_CMD(0x38); // 8 Bit Mode, 2 Rows, 5x7 Font Style

----------------------------------------------------------------------------
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
}
}

2. Power Saving System

----------------------------------------------------------------------------
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

2. Program for data transfer using different addressing modes


.model small
.data
Num dw 4321h
.code
Mov ax,@data ; Initialize the data segment
Mov ds, ax
Mov ax, 1234h ; immediate addressing
Mov bx, ax ; register addressing
Mov ax, num ; direct addressing
Mov si, 1000h
Mov al, [si] ; indirect addressing
Mov bl, [si+100h] ; relative addressing
Mov bx, 1000h
Mov ax, [si+bx] ; base index addressing
Mov cx, [si+bx+100h]; relative base index addressing
Int 3
End

3. Program to Multiply unsigned 16-bit numbers


.model small
.data
N1 dw 0ffffh
N2 dw 0ffffh
res dw 5 dup(0)
.code
Start: Mov ax,@data ; initializes DS
Mov ds, ax
Mov ax, N1 ; copy ax with first number
Mov cx, N2 ; copy cx with second number
Mul cx ; multiply ax with cx
Mov res, ax ; store the result in ax and dx
Mov res+2, dx
Int 3 ; Terminate the program
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
End start

4. Program to multiply signed 16-bit numbers


.model small
.stack 100
.data
num1 dw -1h
num2 dw 0032h
res dw 2 dup(0)
.code
Start: Mov ax,@data
Mov ds, ax
Mov ax, num1
Mov dx, 0000h ; initialize dx with zeros
Mul num2
Mov res, ax ; take the higher order word of product from dx
Mov res+2, dx
Int 3
End start

5. Program to convert binary number to BCD number


.model small
.data
num db 0FFh
res db 03 dup(0)
.code
Mov ax,@data
Mov ds, ax ; Initialize data segment
Mov al, num ; Move the binary number to al
Mov ah, 00h ; clear ah
Mov bl, 64h
Div bl ; Divide ax by 64h
Lea si, res
Mov [si], al ; Move the quotient to [si]
Mov al, ah ; Move the remainder to al
Mov ah, 0h ; cLear ah
Mov bl, 0ah
Div bl ; Divide ax by bl
Mov [si+1], al ; Move the quotient to [si+1]
Mov [si+2], ah ; Move the remainder to [si+2]
Int 3 ; Terminate the program
End

6. Program to interchange two blocks of data


.model small
.stack 20
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
.data
src db 31h,32h,33h,34h,35h,36h,37h,38h
dst db 41h,42h,43h,44h,45h,46h,47h,48h
Count dw 0008h
.code
Start: Mov ax,@data ; Initialization of data and extra segment.
Mov ds, ax
Mov es, ax
Mov cx, count ; Initialize cx reg with count
Mov bx, 0000h ; store bx with 00
repeat:
Mov al, src[bx] ; move the contents at location o to al
xchg al, dst[bx] ; Excahnge the contents of al with dst
Mov src [bx], al ; copy the contents of al to src
Inc bx ; Increment bx by 1
loop repeat ; go to the label repeat if cx != 0
Int 3 ; Terminate the program
End

7. Program to Divide 32-bit unsigned number by 16-bit number

.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

8. Program to illustrate use of AAA instruction (ASCII addition)


.model small
.data

----------------------------------------------------------------------------
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

9. Program to convert binary number to BCD number


.model small
.data
num db 0FFh
res db 03 dup(0)
.code
Mov ax,@data
Mov ds, ax ; Initialize data segment
Mov al, num ; Move the binary number to al
Mov ah, 00h ; clear ah
Mov bl, 64h
Div bl ; Divide ax by 64h
Lea si, res
Mov [si], al ; Move the quotient to [si]
Mov al, ah ; Move the remainder to al
Mov ah, 0h ; cLear ah
Mov bl, 0ah
----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018
Microprocessors and Microcontrollers Lab Manual
-------------------------------------------------------------------------------
Div bl ; Divide ax by bl
Mov [si+1], al ; Move the quotient to [si+1]
Mov [si+2], ah ; Move the remainder to [si+2]
Int 3
End

10. Program to find LCM of two 8-bit numbers


.model small
.data
nums dw 0010,0048
lcm dw 2 dup(?)
.code
start: Mov ax,@data
Mov ds, ax
Mov ax, nums
Mov cx, nums+2
Mov dx, 00h
back: push ax
push dx
Div cx ; Divide one no. by another
cmp dx,00h ; compare the remainder with zero
je lcm1
pop dx
pop ax
add ax,nums ; if the remainder is not zero, take the next Multiple of the
DividEnd and again try to Divide it by the Divisor till the
remainder becomes zero
Jnc skip
Inc dx
skip: jmp back
lcm1: pop lcm+2; when the remainder is zero,
pop lcm ; the DividEnd value is the lcm
Int 3 ; Terminate the program
End start

----------------------------------------------------------------------------
BNMIT/CSE Page 19 2018

Das könnte Ihnen auch gefallen