Sunteți pe pagina 1din 23

LABORATORY MANUAL

ECE-306

Unified Electronics Lab


ECE lab manual

Experiment :1

Title: interfacing of segment display with 8255 using 8085.

Equipment used: 8085 microprocessor kit, 7-segment display

Procedure:
For 8255, Port A and B are used as output ports. The control word format of 8255 according to
hardware connections is:

Source program:

SOFTWARE TO INITIALIZE 8255:

MVI A, 80H : Load control word in AL


OUT CR : Load control word in CR

SUBROUTINE TO DISPLAY MESSAGE ON MULTIPLEXED LED DISPLAY:

SET UP REGISTERS FOR DISPLAY:

MVI B, 08H : load count


MVI C, 7FH : load select pattern
LXI H, 6000B : starting address of message

DISPLAY MESSAGE:

DISP 1: MOV A, C : select digit


OUT PB
MOV A, M : get data
OUT PA : display data
CALL DELAY : wait for some time
DISP 1: MOV A, C
RRC
MOV C, A : adjust selection pattern
INX H
DCR B : Decrement count
JNZ DISP 1 : repeat 8 times
RET

Note: This "display message subroutine" must be called continuously to display


the 7-segment coded message stored in the memory from address 6000H.

Delay subroutine:

Delay: LXI D, Count


Back: DCX D
MOV A, D
ORA E
JNZ Back
RET
Experiment:2

Title: Generating a square wave of 50% duty cycle using 8085.

Equipment: 8085 microprocessor kit

Procedure:
Experiment: 3

Title: To develop a program for discrete convolution and correlation without using
inbuilt functions.

EQUIPMENT: MATLAB

PROCEDURE:
ALGORITHM:

1. Enter the input Sequence ,x having length=4


2. Enter the Impulse Sequence, h having length=4
3. Performing the Convolution, store the value in y
4. Plotting the Input Sequence.
5. Plotting the Impulse Sequence.
6. Plotting the Output Sequence.

PROGRAM CODE:

% program for discrete Convolution

x=[1,1,1,2];

h=[1,1,2,1];

Nx=length(x);

Nh=length(h);

y=conv(x,h);

n=0:1:Nx-1;

subplot(2,2,1),stem(n,x);

xlabel('n'),ylabel('x(n)');
title('input sequence');

n=0:1:Nh-1;

subplot(2,2,2),stem(n,h);

xlabel('n'),ylabel('h(n)');

title('impulse sequence');

n=0:1:Nx+Nh-2

subplot(2,2,3),stem(n,y);

xlabel('n'),ylabel('y(n)');

title('output sequence(linear convolution)');

RESULT:

input sequence impulse sequence


2 2

1.5 1.5
x(n)

h(n)

1 1

0.5 0.5

0 0
0 1 2 3 0 1 2 3
n n
output sequence(linear convolution)
6

4
y(n)

0
0 2 4 6
n
ALGORITHM:

1 Enter the input Sequence ,x having length=4

2 Enter the Impulse Sequence, y having length=4

3 Performing the Correlation, store the value in y

4 Plotting the Output Sequence ,store in z.

%program for discrete Correlation

X = [1 2 3 4];

Y = [2 3 4 5];

Z = xcorr(x,y);

stem(z);

RESULT:

40

35

30

25

20

15

10

0
1 2 3 4 5 6 7
Fig shows discrete Correlation of two signals

EXPERIMENT NO:4

TITLE: to develop program for computing DFT and FFT in MATLAB and compare
this simulation.

Equipment: MATLAB

Procedure:

Function
function [Xkl = dft(111.N)
% Computes Discrete Fourier Transform
% Ixkl = dft(xn.N)
% Xk = DFT coeff. array over 0 <= k <= N-I
% xn = N-point finite-duration sequence
% N = Length of DFT
X
n = [O:l:N-11; % row vector for n
k = CO:I:N-11; X row vecor for k
UN = eq(-j*l*pi/N); % Wn factor
nk = nl*k;
UNnk =UN .- nk;
xk = m * UNnk;
% creates a N by N matrix of nk values
% DFT matrix
% row vector for DFT coefficients

ALGORITHM:

1 Enter the input Sequence ,x having length=4

2 Set the range of k according to the length of x.

3 Computing DFT, store the value in X(k).


4 Plotting the DFT of given Sequence,store in X(k).

PROGRAM CODE:

% Program to perform Discrete Fourier Transform

clc;clear all; close all hidden;

x=input('The given sequence is x(n): ');

N=length(x);

for k=1:N

X(k)=0;

for n=1:N

X(k)=X(k)+x(n).*exp(-j.*2.*pi.*(n-1).*(k-1)./N);

end

end

display('The DFT of the given sequence is:')

p=0:(N-1);

stem(p,abs(X)),grid

Input Sequence:-
RESULT:

20

18

16

14

12

10

0
0 0.5 1 1.5 2 2.5 3

Fig shows DFT of input sequence

For FFT
Function:

% Nmar = 2048;
% fft-time=zeros(l,Nmar);
% for n-1:l:Nmax
% I-raud(1,n) ;
%t-ciock;fft(x) ;fft-time(n)=etime(clock,t) ;
% end
>> n=Cl:l:Nmaxl;
>> plot(n,fft-time. I . ' )
>> xlabel('NS) ;ylabel('Time in Sec. ')
>> title('FFT execution times')

Experiment:5

Title: to develop a program for computing circular convolution.

Software used: MATLAB

PROCEDURE:

ALGORITHM:

1 Enter the input Sequence, x having length=4

2 Enter the Impulse Sequence, h having length=4

3 Performing the Convolution, store the value in y(n)

4 Plot the y(n).

PROGRAM CODE:

%program to perform circular convolution%

clc;close all hidden;clear all;

x=input('enter the input sequence x(n):');

h=input('enter the impulse response h(n):');


N1=length(x);

N2=length(h);

N=max(N1,N2);

N3=N1-N2;

%loop for getting equal length seq

if(N3==0)

x=[x,zeros(1,N3)];

h=[h,zeros(1,N3)];

end

if(N1>N2)

h=[h,zeros(1,N3)];

end

if(N1<N2)

x=[x,zeros(1,-N3)];

end

%computation of circular convolved seq

for n=1:N,

y(n)=0;

for i=1:N,

j=n-i+1;

if(j==0)

j=N+j;
end

if(j<0)

j=N+j;

end

y(n)=y(n)+x(i).*h(j);

end

end

display('convoluted sum:');

p=0:(N-1);

stem(p,y),grid;

RESULT:
40

35

30

25

20

15

10

0
0 0.5 1 1.5 2 2.5 3

Input:

1. Enter the input sequence x(n): [1 2 3 4]

Enter the impulse response h(n):[2 3 4 5]


OUTPUT: 1.Convolution sum: y = [36 38 36 30]

Experiment no:6

a) Title: send an alphabet to PC using serial communication port of 8051.


Equipment used:

Procedure:
b) Title: sending string “HELLO” to PC using serial communication port of
8051.
c) Addition of two numbers and display the result on PC using serial
communication.

EXPERIMENT NO: 8

TITLE: 8051 Interfacing: Interfacing 7 segment display to 8051.


SOFTWARE REQD. KIT 8051
PROGRAME CODE:

start:
SETB P3.3 ; |
SETB P3.4 ; | enable display 3
MOV P1, #11111001B ; put pattern for 1 on display
MOV P1, #0FFH ; clear the display
CLR P3.3 ; enable display 2
MOV P1, #10100100B ; put pattern for 2 on display
MOV P1, #0FFH ; clear the display
CLR P3.4 ; |
SETB P3.3 ; | enable display 1
MOV P1, #10110000B ; put pattern for 3 on display
MOV P1, #0FFh ; clear the display
CLR P3.3 ; enable display 0
MOV P1, #10011001B ; put pattern for 4 on display
MOV P1, #0FFH ; clear display
JMP start ; jump back to start

for Port 0
MOV A,#55H
BACK: MOV P0,A
ACALL DELAY
CPL A
SJMP BAC

Port 0 as Input
MOV A,#0FFH ; A = FF hex
MOV P0,A ; make P0 an input port
BACK: MOV A,P0 ;get data from P0
MOV P1,A ;send it to port 1
SJMP BACK

Experiment no:9
8051 Assembly language programming using Keil compiler. (At least 5 programs.).
a) Write a program to add two numbers lying at two memory locations and
display result.

Sample program:
Start
.org 4000h
MOV A,30h
MOV B,31h
ADD A,B Load the Two
MOV 80h,A numbers from
memory to register
.end
A&B

Add the two numbers

Display the result at


PORT0

END

b. Write a program to perform multiplication of 2 numbers lying at memory


locations and display result.

Sample program:

.org 4000h
MOV A,30h
MOV B,31h
MUL AB
MOV 80h,A
.end

C. Write a program to find factorial of a number.


.org 4000h
MOV A,#05h
MOV B,A
DEC B
loop1:MUL AB
DEC B
DJNZ B,loop1
MOV 80h,A
.end

d. Write a program to convert BCD number to hexadecimal number.

Sample program

.org 4000h
MOV A,30h
MOV B,#10h
MUL AB
MOV B,31h
ADD A,B
MOV B,#0Fh
DIV AB
.end

e. Write a program to arrange 10 numbers in ascending order and descending


order. The starting location of the first number is 2050h

sample program

.ORG 00h
MOV R0, #0Fh
LOOP1: MOV DPTR, #2050h
MOV A, R0
MOV R1, A

LOOP2: MOVX A, @DPTR


MOV R2, A
INC DPTR
MOVX A, @DPTR
SUBB A, R2
JNC Continue2
SwapNumbers: MOVX A, @DPTR
XCH A, R2
MOVX @DPTR, A
DEC DPL
MOV A, R2
MOVX @DPTR, A
INC DPTR
Continue2: DJNZ R1, LOOP2
Continue1: DJNZ R0, LOOP1
Here: SJMP Here
END

f. Write a program to generate a square wave of 1KHz frequency.


Mov r6, #0Ah ; load 10d in r6
Acall delay ; call 20 ms delay ×10 = 200 ms
Clr p2.0 ; send 0 to port pin
Mov r6, #0Ah ; load 10d in r6
Acall delay ; call 20 ms delay ×10 = 200 ms
Sjmp loop ; continuous loop
Delay: ; load count 5000d
Lp2: Mov r7, #1388h
Lp1: Nop ; 1 cycle
Nop ; 1+1=2 cycles
Djnz r7, lp1 ; 1+1+2 = 4 cycles
Djnz r6, lp2 ; 4×5000 = 20000 cycles = 20000 µs = 20 ms
ret

g. A string of 10 bytes is stored in memory location starting at 2050h. Write a


program to check each byte in the string and save the bytes in the range of 30h to
39h(both inclusive) in memory location starting from 2070h.
Mov dptr, #2050h ; get initial location
Mov r7, #0Ah ; counter
Mov r4, #00h ; number counter
Mov 20h, r2 ; get the upper and lower limits in
Mov 21h, r3 ; 20h and 21h
Nxt: Movx a, @dptr ; get the content in acc
Cjne a, 21h, lower ; check the upper limit first
Sjmp out ; if number is larger
Lower: jnc out ; jump out
Cjne a, 20h, limit ; check lower limit
Sjmp out ; if number is lower
Limit: jc out ; jump out
Inc r4 ; if number within limit increment count
Out: inc dptr ; get next location
Djnz r7, nxt ; repeat until block completes

Experiment no:10
Title: 8051 Interfacing
a. ADC
b. DAC
c. LCD
d. Keyboard

a) Title: Interfacing with keyboard.


Equipment used: 8051 kit

Program code:

Start of main program:

to check that whether any key is pressed

start: mov a,#00h


mov p1,a ;making all rows of port p1 zero
mov a,#0fh
mov p1,a ;making all rows of port p1 high
press: mov a,p2
jz press ;check until any key is pressed
after making sure that any key is pressed

mov a,#01h ;make one row high at a time


mov r4,a
mov r3,#00h ;initiating counter
next: mov a,r4
mov p1,a ;making one row high at a time
mov a,p2 ;taking input from port A
jnz colscan ;after getting the row jump to check
column
mov a,r4
rl a ;rotate left to check next row
mov r4,a
mov a,r3
add a,#08h ;increment counter by 08 count
mov r3,a
sjmp next ;jump to check next row

after identifying the row to check the column following steps are followed

colscan: mov r5,#00h


in: rrc a ;rotate right with carry until get the carry
jc out ;jump on getting carry
inc r3 ;increment one count
jmp in
out: mov a,r3
da a ;decimal adjust the contents of counter
before display
mov p2,a
jmp start ;repeat for check next key.
b) Interfacing with LCD

WAIT_LCD:
CLR EN ;Start LCD command
CLR RS ;It's a command
SETB RW ;It's a read command
MOV DATA,#0FFh ;Set all pins to FF initially
SETB EN ;Clock out command to LCD
MOV A,DATA ;Read the return value
JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy
CLR EN ;Finish the command
CLR RW ;Turn off RW for future commands
RET

S-ar putea să vă placă și