Sie sind auf Seite 1von 41

LABORATORY MANUAL

COURSE CODE: ECE306 COURSE TITLE: UNIFIED ELECTRONICS LAB-IV

S.NO 1 2 3 4 5 6 7 8 9 10 11 12

TITLE OF THE EXPERIMENT


Introduction to Microcontroller Programming tool i.e. Keil Simulator 8051 Assembly language programming using cross-assembler. (At least 10 programs. Annexure 1) 8051 Interfacing: Interfacing with 7-segment display. 8051 Interfacing: Interfacing with LCD. 8051 Interfacing: Interfacing with DAC. 8051 Interfacing: Interfacing with ADC. 8051 Interfacing: Interfacing with Keyboard. Programming for serial communication. A small Project using 8051. To develop program for computing inverse Z-transform. To develop program for designing FIR filter in MATLAB. To develop program for designing IIR filter in MATLAB.

PAGE NO. 3-10 11-16 17-19 20-22 23-24 25-27 28-30 31-32 33 34-36 37-43 37-43

Experiment No. 1
Aim: Introduction to Microcontroller Programming tool i.e. Keil Simulator

Equipment Required: Keil Simulator Learning Objective: To learn keil simulator for programming of microcontrollers. Procedure: 1. Double Click on the icon present on the desktop.

2. The following window will be popped-up

3. Go to the project & click on new project

4. Make a folder on desktop & give file name.

5. when you click on the save button ,following window opens

6. Select ATMEL & AT89S51 / Philips & 89c51RD2xx

7. Then select NO on the pop-up given below.

1) Then make a New File.

9. Write or copy your code there & save it with extension .c or .asm depending on your coding. 10. Go to target & then source group, right click on there & click on the option add files to the project.Select your asm or c file which you want to add. 11. Go to the option for target, click on output &tick on create hex file option

12.Now build target.(Click on the pointed option)...

13.It will show you 0 errors &0 warning on Output Window.

Experiment no:2
Am: 8051 Assembly language programming using cross-assembler. (At least 10 programs. Annexure 1) Equipment Required: Keil simulator

Learning Objective: To learn to write programs in assembly language and generate .hex files.
a) Find the sum of the values 79H, F5H, and E2H. Put the sum in register R0 (low byte) and R5 (high byte).

org 0000h MOV A,#79h MOV B,#0f51h ADD A,B ADD A,#0e2h MOV R0,A MOV R5,C end b. Write a program to copy the values 55H into RAM memory locations 40H to
45H using i) Direct addressing mode ii) Register indirect addressing mode without using loop iii) With a loop.

i) org 0000h MOV A,#55h MOV 40,A MOV 41,A MOV 42,A MOV 43,A MOV 44,A MOV 45,A End

ii) org 0000h


9

MOV A,#55h MOV R0,#40h MOV @R0,A INC R0 MOV @R0,A INC R0 MOV @R0,A INC R0 MOV @R0,A INC R0 MOV @R0,A INC R0 MOV @R0,A End iii) org 0000h MOV A,#55h MOV R0,#40h Again: MOV @R0,A INC R0 CJNE R0,#45h,again end c) Write a program to toggle all the bits of P1 after some delay. org 0000h again: cpl P1 acall delay sjmp again delay:MOV R0, #0ffh Here:DJNZ R0, Here RET end d) Write a program to generate square wave of 50% duty cycle on bit 0 of port 1. org 0000h
10

again: cpl P1.0 acall delay acall delay sjmp again delay:MOV R0, #0ffh DJNZ R0, Here RET End e) Write a program to add two 16 bit numbers 3CE7H and 3B8DH. Place the sum in R7 and R6 (Lower Byte). ORG 0000h MOV A,#0E7h MOV B,#8Dh ADD A,B MOV R6,A MOV A,#3Ch MOV B,#3Bh ADDC A,B MOV R7,A END f) Write a program for Hex to ASCII conversion.
ORG 0000H MOV A,#234 MOV B,#10 DIV AB MOV 01,B MOV B,#10 DIV AB MOV 02,B MOV 03,A MOV A,01 ADD A,#30 MOV 01,A MOV A,02 ADD A,#30 MOV 02,A
11

MOV A,03 ADD A,#30 MOV 03,A END

g) Write a program to
i) Make P1 as input port. ii) To get hex data from P1 and convert it into decimal and save the digits in R7, R6, R5. ORG 0000H MOV P1,#0FFH MOV A,P1 MOV B,#10 DIV AB MOV R7,B MOV B,#10 DIV AB MOV R6,B MOV R5,A MOV A,R7 ADD A,#30 MOV R7,A MOV A,R6 ADD A,#30 MOV R6,A MOV A,R5 ADD A,#30 MOV R5,A END

h) A switch is connected to P1.7. Write a program to check the status of SW and


perform the following: i) If SW=0, send letter N to P2. ii) If SW=1, send letter Y to P2. ORG 00000H SETB P1.7 JB SENDY MOV A,#N MOV P2,A MOV A,#Y MOV P2,A
12

AGAIN:

SENDY:

SJMP AGAIN END

i) Assume that the lower 3-bits of P1 are connected to 3-switches. Write a program to send ASCII characters for 0-7 base on the status of switches using look up table. ORG 0000H SETB P1.0 SETB P1.1 SETB P1.2 CLR P1.3 CLR P1.4 CLR P1.5 CLR P1.6 CLR P1.7 MOV A,P1 ACALL DELAY MOV A,P1 MOV R1, A ACALL DELAY MOV R2,#03 DJNZ R2, AGAIN MOV A,P1 ACALL DELAY MOV R2,#03 DJNZ R2, AGAIN1 ORL A,R1 MOV R1,A MOV A,P1 ACALL DELAY MOV R2,#03 DJNZ R2, AGAIN2 ORL A,R1 MOV R1,A CLR A MOVE DPTR,#DATA MOV A,@DPTR+A DB 0,1,2,3,4,5,6,7

AGAIN:

AGAIN1:

AGAIN2:

DATA:

13

j) Write a program to generate square wave using timer. ORG 0000H MOV TL0,#0F2H MOV TH0,#0FFH CPL P1.5 ACALL DELAY SJMP HERE SETB TR0 JNB TF0, AGAIN CLR TR0 CLR TF0 RET END

HERE:

DELAY: AGAIN:

14

Experiment: 3
Aim: 8051 Interfacing: Interfacing with 7-segment display.

Material Required:
8051, 11.0592MHz Crystal, 30pF (2), 10uF, 10K, push button, 1K (10), 7-segment display. Learning Objective: To learn the interfacing of 7- segment display with 8051 Outline of the Procedure: i) Write the program code in the keil software ii) Simulate the program code for any error. iii) Generate the .hex file for the written code iv) Make the connection as per the circuit diagram v) Program the microcontroller with the generated .hex file. vi) Insert the microcontroller in the circuit and observe the out by giving proper power supply.

15

Circuit Diagram

Program Code:
org 0000h ljmp main org 30h

main:mov r0,#08h mov a,#00000001b up: rr a mov port,a acall delay djnz r0,up

;test all segments of disp

again:mov port,#11111100b acall delay mov port,#01100000b acall delay mov port,#11011010b
16

acall delay mov port,#11110010b acall delay mov port,#01100110b acall delay mov port,#10110110b acall delay mov port,#10111110b acall delay mov port,#11100000b acall delay mov port,#11111110b acall delay mov port,#11110110b acall delay sjmp again

delay:mov r2,#0ffh up3: mov r4,#03fh up2: mov r3,#0fh up1: djnz r3,up1 djnz r4,up2 djnz r2,up3 ret end

Caution: a) All the connections should be correct and their should be no loose connection. b) Power supply to the 7-segment should be given by first identifying the type of display (common anode or common cathode). c) Power supply to the microcontroller should not be more than 5V.

17

Experiment No. 4:
Aim: 8051 Interfacing: Interfacing with LCD. Material Required: 8051, 11.0592MHz Crystal, 30pF (2), 10uF, 10K, push button, LCD (16x2), 10K Pot. Learning Objective: To learn the interfacing of LCD display with 8051 Outline of the Procedure: i) Write the program code in the keil software ii) Simulate the program code for any error. iii) Generate the .hex file for the written code iv) Make the connection as per the circuit diagram v) Program the microcontroller with the generated .hex file. vi) Insert the microcontroller in the circuit and observe the out by giving proper power supply.

Circuit Diagram

18

Program Code:

ORG MOV A,#38H ACALL COMWRT ACALL DELAY MOV A,#0EH ACALL COMWRT ACALL DELAY MOV A,#01H ACALL COMWRT ACALL DELAY MOV A,#06H ACALL COMWRT ACALL DELAY MOV A,#84H ACALL COMWRT ACALL DELAY MOV A,#Y ACALL DATAWRT
19

ACALL DELAY MOV A,#E ACALL DATAWRT ACALL DELAY MOV A,#S ACALL DATAWRT ACALL DELAY AGAIN: SJMP AGAIN COMWRT: MOV P1,A CLR P2.0 :RS CLR P2.1 :R/W SETB P2.2 :E ACALL DELAY CLR P2.2 RET DATAWRT: MOV P1,A SETB P2.0 CLR P2.1 SETB P2.2 ACALL DELAY CLR P2.2 RET

Caution: a) All the connections should be correct and their should be no loose connection. b) Main power supply and supply to the contrast pin should be connected as per circuit diagram. c) Power supply to the microcontroller should not be more than 5V. d) Control pins of the LCD should be connected asa per the program code written.

20

Experiment No:5 Aim: 8051 Interfacing: Interfacing with DAC. Material Required:
8051, 11.0592MHz Crystal, 30pF (2), 10uF, 10K, push button, DAC0800, 5K (2), 10K (2), 0.1uF (2), 0.01uF. Learning Objective: To learn the interfacing of DAC display with 8051 Outline of the Procedure: i) Write the program code in the keil software ii) Simulate the program code for any error. iii) Generate the .hex file for the written code iv) Make the connection as per the circuit diagram v) Program the microcontroller with the generated .hex file. vi) Insert the microcontroller in the circuit and observe the out by giving proper power supply.

Circuit Diagram:

21

Program Code: ORG 0000H MOV DPTR,#TABLE MOV R2, #13 BACK: CLR A MOV C,@A+DPTR MOV P1.A INC DPTR DJNZ R2, BACK SJMP AGAIN ORG 300 DB 128,192,238,255,238,192,128,64,17,0,17,64,128

TABLE:

Caution: a) All the connections should be correct and there should be no loose connection. b) All the connections of data pins of DAC to microcontroller should be as per the bit designation of the DAC. c) Power supply to the microcontroller should not be more than 5V. d) Output should be measured between the pins 2 and 4 of DAC not wrt gnd.

22

Experiment no:6
Aim: 8051 Interfacing: Interfacing with ADC.

Material Required: 8051, 11.0592MHz Crystal, 30pF (2), 10uF, 10K, push button, D0804, 10K Pot, 10K, 150pF. Learning Objective: To learn the interfacing of ADC display with 8051 Outline of the Procedure: i) Write the program code in the keil software ii) Simulate the program code for any error. iii) Generate the .hex file for the written code iv) Make the connection as per the circuit diagram v) Program the microcontroller with the generated .hex file. vi) Insert the microcontroller in the circuit and observe the out by giving proper power supply.

Circuit Diagram

23

Program Code:

ORG 0000H RD BIT P2.5 WR BIT P2.6 INTR BIT P2.67 MYDATA EQU P1 MOV P1,#0FFH SETB INTR BACK:CLR WR SETB WR HERE:JB INTR,HERE CLR RD MOV A,MYDATA NOP
24

NOP SETB RD SJMP BACK END

Caution: a) All the connections should be correct and their should be no loose connection. b) All the control pins of the ADC should be connected to microcontroller as per the written program code. c) Power supply to the microcontroller should not be more than 5V. d) Analog signal is to be connected to

25

Experiment no:7 Aim: 8051 Interfacing: Interfacing with Keyboard. Material Required:
8051, 11.0592MHz Crystal, 30pF (2), 10uF, 10K, push button, Push Buttons (4), 4.7K (4). Learning Objective: To learn the interfacing of Keyboard with 8051 Outline of the Procedure: i) Write the program code in the keil software ii) Simulate the program code for any error. iii) Generate the .hex file for the written code iv) Make the connection as per the circuit diagram v) Program the microcontroller with the generated .hex file.
vi) Insert the microcontroller in the circuit and observe the out by giving proper

power supply. Circuit Diagram:

26

Program code: Start of main program: to check that whether any key is pressed start: mov a,#00h mov p1,a mov a,#0fh mov p1,a press: mov a,p2 jz press ;making all rows of port p1 zero ;making all rows of port p1 high ;check until any key is pressed

after making sure that any key is pressed mov a,#01h mov r4,a mov r3,#00h next: mov a,r4 mov p1,a mov a,p2 jnz colscan mov a,r4 rl a mov r4,a mov a,r3 add a,#08h mov r3,a sjmp next ;make one row high at a time ;initiating counter ;making one row high at a time ;taking input from port A ;after getting the row jump to check column ;rotate left to check next row

;increment counter by 08 count ;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
27

da a mov p2,a jmp start END

;decimal adjust the contents of counter before display ;repeat for check next key.

28

Experiment no:8
Aim: Programming for serial communication. Material Required: 8051, 11.0592MHz Crystal, 30pF (2), 10uF, 10K, push button, MAX 232, DB-9 Connector, 10uF (4). Learning Objective: To learn the interfacing of PC(Serial Communication) with 8051 Outline of the Procedure: i) Write the program code in the keil software ii) Simulate the program code for any error. iii) Generate the .hex file for the written code iv) Make the connection as per the circuit diagram v) Program the microcontroller with the generated .hex file. vi) Insert the microcontroller in the circuit and observe the out by giving proper power supply.

Circuit Diagram:

29

Program Code: ORG 0000H MOV TMOD,#20H MOV TH1,#-6 MOV SCON,#50H SETB TR1 AGAIN: MOV SBUF,#a HERE: JNB TI, HERE CLR TI SJMP AGAIN END

30

Experiment 9: A small project using 8051 microcntroller.( It is done by students in their respective groups)

31

Experiment no:10 Aim: To develop program for computing inverse Z-transform. Equipment Required: Software matlab 7 Learning Objective: To equip the students with the MATLAB functions or routines which can be used to find the z-transform of a function?
PROGRAM:%program to perform Inverse Z-Transform b=[3,1,6]; a=[9,10,3]; [R,P,K]=residuez(b,a); m=abs(P); subplot(1,2,1); plot(m); title('magnitude'); A=angle(P)/pi; subplot(1,2,1); plot(A); title('Angle'); freqz(a,b,10)

32

M-FILE OF PROGRAM:-

RESULT:-

33

Experiment no:11 and 12 Aim: To develop program for designing FIR and IIR filter in MATLAB using simulink Equipmtnt Required: Software MATLAB7 Learning Objective: To equip the students with the designing of FIR and IIR filters using MATLAB software.
PROGRAM:n=input('Enter the order of filter') t=linspace(-0.5,0.5,n) w=input('Enter the cut off frequency') win=rectwin(n) a=fir1(n-1,w,win) subplot(3,2,1) plot(a) title('rectwin') win1=hamming(n) b=fir1(n-1,w,win1) subplot(3,2,2) plot(b) title('hamming') win2=hamming(n) c=fir1(n-1,w,win2) subplot(3,2,3) plot(c) title('hanning') win3=hanning(n) d=fir1(n-1,w,win3) 34

subplot(3,2,4) plot(d) title('hanning') win4=blackman(n) e=fir1(n-1,w,win4) subplot(3,2,5) plot(e) title('blackman') subplot(3,2,6) plot(t,a,t,b,t,c,t,d,t,e) title('superimposed response') legend('a','b','c','d','e')

35

M-FILE OF PROGRAM:-

RESULT:1) Input & Output at Command window

36

2) Output Graph (Frequency Response of FIR Filter).

37

IIR Filter PROGRAM:Ap=0.4 As=30 f1=400 f2=800 fs=2000 wp=(2*f1)/fs ws=(2*f2)/fs w=0:0.01:pi [n,wn]=buttord(wp,ws,Ap,As) [b,a]=butter(n,wn) h=freqz(b,a,w,'whole') subplot(2,2,1) plot(w/pi,abs(h)) title('Frequency response for bwlpf') subplot(2,2,2) plot(w/pi,angle(h)) title('Phase response for bwlpf') [b,a]=butter(n,wn,'high') k=freqz(b,a,w,'whole') subplot(2,2,3) plot(w/pi,abs(k)) title('Frequency respose for bwhpf') subplot(2,2,4) plot(w/pi,angle(k)) title('Phase response for bwhpf')

38

M-FILE OF PROGRAM:-

39

RESULT:1. Input and Output at the Command Window.

2. Output Graph (Frequency response of IIR Filter).

40

41

Das könnte Ihnen auch gefallen