20EC3352 LAB EXPERIMENTS Old
20EC3352 LAB EXPERIMENTS Old
20EC3352 LAB EXPERIMENTS Old
2
EXPERIMENT 9
PROGRAMS ON SEVEN SEGMENT INTERFACING
Aim:
a). Write an assembly language program to interface the single Seven Segment Display module to
port 2 and display the information.
b). Write an assembly language program to interface the four Seven Segment Display module to
port 2 and display the information.
Program:
a).
ORG 4000H
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH, 0
; Lookup table for digits 0 to 9
ORG 0000H
MAIN: MOV DPTR, #4000H
REPEAT: CLR A
MOVC A, @A+DPTR
MOV P2, A
ACALL DELAY
INC DPTR
CJNE A, 0, REPEAT
SJMP MAIN
DELAY:
MOV R0, #08H
LP2: MOV R1, #0FFH
LP1: MOV R2, #0FFH
LP3: DJNZ R2, LP3
DJNZ R1, LP1
DJNZ R0, LP2
RET
END
Output:
Peripherals->I/O ports -> Port 2
3
b).
ORG 4000H
DB 06H, 5BH, 4FH, 66H
ORG 0000H
MAIN: MOV DPTR, #4000H
MOV P3, #00H ; CLEAR THE PORT 3 TO USE IT AS OUTPUT PORT
CLR P3.3 ; MODE 1
CLR P3.4 ; 00
CLR A
MOVC A, @A+DPTR
CPL A
MOV P2, A ; P2 = 00000110B = PATTERN OF DIGIT ‘1’
ACALL DELAY
INC DPTR
4
SJMP MAIN ; RUN THIS PROGRAM FOREVER
DELAY:
MOV R0, #01H
LP2: MOV R1, #010H
LP1: MOV R2, #010H
LP3: DJNZ R2, LP3
DJNZ R1, LP1
DJNZ R0, LP2
RET
END
Output:
Peripherals->I/O ports -> Port 2
Theory
https://technobyte.org/seven-segment-8051-interfacing-tutorial-quad-single-
module/
5
EXPERIMENT 8
PROGRAMS ON DAC INTERFACING
Aim: Write an assembly language program to generate Square, Sawtooth and
triangular waveform by interface Digital to Analog Converter to the microcontroller
board in external memory location 0FFC8H.
Program:
SQUARE WAVEFORM GENERATION
ORG 00H
START:MOV DPTR,#0FFC8H
MOV A,#00H
MOVX @DPTR,A
MOV P2,A
LCALL DELAY
MOV A,#0FFH
MOVX @DPTR,A
MOV P2,A
LCALL DELAY
LJMP START
DELAY:MOV R1,#05
LOOP:MOV R2,#0FFH
HERE:DJNZ R2,HERE
DJNZ R1,LOOP
RET
END
ORG 00H
MOV DPTR,#0FFC8H
MOV A,#00H
LOOP:MOVX @DPTR,A
MOV P2,A
INC A
SJMP LOOP
END
6
TRIANGULAR WAVEFORM GENERATION
ORG 00H
MOV DPTR,#0FFC8H
START:MOV A,#00H
LOOP1:MOVX @DPTR,A
MOV P2,A
INC A
JNZ LOOP1
MOV A,#0FFH
LOOP2:MOVX @DPTR,A
MOV P2,A
DEC A
JNZ LOOP2
LJMP START
END
Out-Put
View -> Memory Window-> X:0FFC8H
7
For Waveform Generation:
8
EXPERIMENT 7
PROGRAMS ON LCD DISPLAY INTERFACING
Aim: Write an assembly language program to interface the LCD to port 1 and
display the information.
Program:
ORG 00H
MOV DPTR,#MYCOM
C1:CLR A
MOVC A,@A+DPTR
ACALL COMNWRT
ACALL DELAY
JZ SEND_DAT
INC DPTR
SJMP C1
COMNWRT:MOV P1,A
CLR P2.0
CLR P2.1
SETB P2.2
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
9
DELAY:MOV R3,#250
HERE2:MOV R4,#255
HERE:DJNZ R4,HERE
DJNZ R3,HERE2
RET
ORG 300H
MYCOM:DB 38H,0EH,01,06,84H,0
ORG 310H
MYDATA:DB 'HELLOW',0
END
OutPut:
Theory:
10
11
EXPERIMENT 6
PROGRAMS ON STEPPER MOTOR INTERFACING
ORG 00H
MOV DPTR,#0FFC8H
L1:MOV A,#05H
MOVX @DPTR,A
ACALL DELAY
MOV A,#06H
MOVX @DPTR,A
ACALL DELAY
MOV A,#0AH
MOVX @DPTR,A
ACALL DELAY
MOV A,#09H
MOVX @DPTR,A
ACALL DELAY
SJMP L1
DELAY:MOV R1,#14
MOV TMOD,#01H
12
L2:MOV TL0,#00H
MOV TH0,#00H
SETB TR0
SAME:JNB TF0 ,SAME
CLR TR0
CLR TF0
DJNZ R1,L2
RET
END
OutPut:
13
EXPERIMENT 5
PROGRAMS ON INTERRUPT MECHANISM
Aim: Write a program for interrupts mechanism to transmit the data serially with a
baud rate of 9600 and simultaneously complement the data with one second time
delay using timers in external memory location 0FFC0H.
Program:
ORG 00H
SJMP MAIN
ORG 00BH
SJMP TOISR
ORG 0023H
SJMP SISR
MAIN:MOV IE,#92H
MOV TH1,#-3
MOV TMOD,#21H
MOV SCON,#40H
MOV TH0,#00H
MOV TL0,#00H
MOV R0,#14
SETB TR1
MOV SBUF,#20H
MOV DPTR,#0FFC0H
MOV A,#0FFH
MOVX @DPTR,A
SETB TR0
MOV DPTR,#MYDATA
SETB TR1
MOV SBUF,#20H
HERE:SJMP HERE
TOISR:CLR TR0
PUSH DPH
PUSH DPL
14
DJNZ R0,REPEAT
MOV TH0,#00H
MOV TL0,#00H
CPL A
MOV DPTR,#0FFC0H
MOVX @DPTR,A
MOV R0,#14
SETB TR0
POP DPL
POP DPH
RETI
REPEAT:CLR TR0
MOV TL0,#00H
MOV TH0,#00H
SETB TR0
POP DPL
POP DPH
RETI
SISR:PUSH 0E0H
CLR TI
CLR A
MOVC A,@A+DPTR
JZ REPEAT1
MOV SBUF,A
INC DPTR
POP 0E0H
RETI
REPEAT1:MOV DPTR,#MYDATA
POP 0E0H
MOV SBUF,#20H
RETI
MYDATA:DB "VRSEC",0
END
15
OutPut:
View -> Serial Window-> UART #1
THEROY
16
17
18
EXPERIMENT 4
PROGRAMS ON SERIAL COMMUNICATIONS
Aim: Write a program for serial transmission and serial reception with an baud rate of
9600bps.
PROGRAM
ORG 00H
MOV P2,#0FFH
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
MOV DPTR,#MYDATA
H1:CLR A
MOVC A,@A+DPTR
JZ RECV
ACALL SEND
INC DPTR
SJMP H1
SEND:MOV SBUF,A
H2:JNB TI,H2
CLR TI
RET
RECV:
H3:JNB RI,H3
CLR RI
MOV A,SBUF
MOV P2,A
SJMP RECV
END
19
Output:
(Serial Transmission)
View->Serial Windows->#UART 1
(Serial Reception)
Note: For Reception Enter Single Character in Serial Window, the corresponding ASCII Values
is display in Port 2.
20
THEORY
21
22
EXPERIMENT 3
PROGRAMS ON COUNTER OPERATION
Aim:
a). Write an Assembly language program in 8051 micro controllers for Counter 0 in Mode 2 to
count the number of pulses and display the count value on port P2 and external memory location
0FFC1H.
b). Write an Assembly language program in 8051 micro controllers for Counter 1 in Mode 2 to
count the number of cycles in square waveform with an frequency of 2KHz and display the count
value on port P2 and external memory location 0FFC1H.
a)
ORG 00H
MOV TMOD,#06H ;Make Counter 0 in Mode 2
MOV DPTR,#0FFC1H
MOV TH0,#00H
SETB P3.4 ;Make 14 Pin as Input Pin for Counter 0 (i.e T0)
AGAIN:SETB TR0
BACK:MOV A,TL0
MOVX @DPTR,A
MOV P2,A
JNB TF0,BACK
CLR TR0
CLR TF0
SJMP AGAIN
END
Output:
Peripherals->I/O ports -> Port 3 ; ON and OFF the P3.4 as Input Pulse Signal
23
Peripherals->I/O ports -> Port 2
View->Memory Windows->Memory 1
Address: X:0FFC1H
24
b) Calculations
PROGRAM
ORG 00H
MOV TMOD,#61H ; Make Timer 0 Mode 1, and Counter 1 Mode 2
SETB P3.5 ; Make 15 Pin as Input Pin for Counter 1 (i.e T1)
MOV DPTR, #0FFC1H
MOV TH1,#00H
AGAIN:SETB TR1
L2:ACALL DELAY
CPL P3.5
MOV A,TL1
MOVX @DPTR,A
MOV P2,A
JNB TF1,L2
CLR TR1
CLR TF1
SJMP AGAIN
DELAY:MOV TL0,#1AH
MOV TH0,#0FFH
SETB TR0
HERE:JNB TF0,HERE
CLR TF0
CLR TR0
RET
25
END
Output:
Right Click on Target -> Options for Target->Target->Set Xtal 11.0592
Peripherals->I/O ports -> Port 3 ; ON and OFF the P3.5 as Input Pulse Signal
View->Memory Windows->Memory 1
Address: X:0FFC1H
26
For Square Waveform:
27
COUNTERS THEORY
28
EXPERIMENT 2
PROGRAMS ON TIMER OPERATION.
Aim:
a). Write an Assembly language program for 8051 micro controller to complement the data in
port-2 and external memory location 0FFC0H with time delay of 1 sec using timer 0 in mode 1 for
crystal frequency of 11.0592MHz .
b). Write an Assembly language program for 8051 micro controller to complement the data in port-
2 and external memory location 0FFC0H with time delay of 2 sec using timer 1 in mode 2 for
crystal frequency of 11.0592MHz .
29
a) TIMER 0 MODE 1, 1SEC TIME DEALY PROGRAM
ORG 00H
MOV TMOD,#01H
MOV A,#55H
MOV DPTR, #0FFC0H
L2:ACALL DELAY
MOVX @DPTR,A
MOV P2,A
CPL A
SJMP L2
DELAY:MOV R0,#0EH
L1:MOV TL0,#00H
MOV TH0,#00H
SETB TR0
HERE:JNB TF0,HERE
CLR TF0
CLR TR0
DJNZ R0,L1
RET
END
Output:
View->Memory Windows->Memory 1
Address: X:0FFC0H
30
b) Calculations (TIMER 1 MODE 2, 2 SEC TIME DEALY)
ORG 00H
MOV TMOD,#20H
MOV A,#55H
MOV DPTR,#0FFC0H
LOOP:ACALL DELAY
CPL A
MOVX @DPTR,A
MOV P2,A
SJMP LOOP
DELAY: MOV R1,#1CH
BACK2:MOV R2,#20H
BACK1:MOV TH1,#00H
31
SETB TR1
HERE :JNB TF1,HERE
CLR TF1
CLR TR1
DJNZ R2,BACK1
DJNZ R1,BACK2
RET
END
TIMERS THEORY
32
33
34
EXPERIMENT 1(A)
35
Aim: Write a following assembly language programs (ALP) using athematic instructions in 8051
Micro Controller.
a). Basic Athematic Operations
b) Factorial of a Number
c) Average of First 10 Numbers
d) Fibonacci Series
MOV A,#25H
SUBB A,B
MOV 41H,A
MOV A,#25H
MUL AB 4*4=16 LSB=A MSB=B
MOV 42H,A
MOV 43H,B
MOV A,#25H
MOV B,#12H
DIV AB
MOV 44H,A
MOV 45H,B
MOV A,#25H
INC A
MOV 46H,A
DEC A
MOV 47H,A
END
Output:
36
View->Memory Windows->Memory 1
Address: D:40h (PRESS ENTER KEY)
ORG 00H
MOV A,#03H
MOV R0,#02H
BACK:MOV B,R0
MUL AB
DJNZ R0,BACK
MOV 40H,A
MOV 41H,B
END
Output:
View->Memory Windows->Memory 1
Address: D:40h
37
ORG 00H
MOV R0,#0AH
MOV B,R0
MOV A,#00H
BACK:ADD A,R0
DJNZ R0,BACK
DIV AB
MOV 50H,A
MOV 51H,B
END
Output:
View->Memory Windows->Memory 1
Address: D:40h
38
ORG 00H
MOV R0,#40H
MOV R1,#08H
LOOP:MOV B,@R0
INC R0
MOV A,@R0
ADD A,B
INC R0
MOV @R0,A
DEC R0
DJNZ R1,LOOP
END
Output:
View->Memory Windows->Memory 1
Address: D:40h
Note: To generate Fibonacci series minimum two number are required, so the memory locations
40h and 41h are filled with 00 and 01 before run the program.
After enter the values in 40h and 41h then run the program. The required output is
39
40
EXPERIMENT 1(B)
Aim: Write a following assembly language programs (ALP) using logical instructions in 8051
Micro Controller.
a). Basic logical Operations
b) Packed BCD to ASCII Conversion
c) ASCII to Packed BCD Conversion
d) Counting the number of ones in Hexadecimal Number
MOV R0,#67H
ANL A,R0
MOV 20H,A
MOV A,#45H
ORL A,R0
MOV 21H,A
MOV A,#04H
MOV A,#45H
XRL A,R0
MOV 22H,A
MOV A,#16H
CPL A
MOV 23H,A
SWAP A
MOV 24H,A
MOV A,#04H
RR A
MOV 25H,A
RL A
MOV 26H,A
END
Output:
View->Memory Windows->Memory 1
Address: D:20h
41
b) Packed BCD to ASCII Conversion
ORG 00H
MOV R0,#40H
MOV A,@R0
ANL A,#0F0H
SWAP A
ADD A,#30H
MOV 41H,A
MOV A,@R0
ANL A,#0FH
ADD A,#30H
MOV 42H,A
END
Output:
View->Memory Windows->Memory 1
Address: D:40h
42
c) ASCII to Packed BCD Conversion
ORG 00H
MOV R0,#40H
MOV A,@R0
ANL A,#0FH
SWAP A
MOV R1,A
INC R0
MOV A,@R0
ANL A,#0FH
ADD A,R1
INC R0
MOV @R0,A
END
Output:
View->Memory Windows->Memory 1
Address: D:40h
43
d) Counting the number of ones of a Hexadecimal Number
ORG 00H
MOV R0,#08H
MOV R1,#00H
MOV A,#79H
L1:CLR C
RLC A
JNC L2
INC R1
L2:DJNZ R0,L1
MOV 40H,R1
END
Output:
View->Memory Windows->Memory 1
Address: D:40h
44
Lab Observation/Record Format
Based on LST File, it is present in Experiment folder
Observation Format
Address Opcode Label Mnemonics Operands
ORG 00H
MOV A,#25H
MOV B,#12H
ADD A,B
MOV 40H,A
MOV A,#25H
SUBB A,B
MOV 41H,A
MOV A,#25H
MUL AB
MOV 42H,A
MOV 43H,B
MOV A,#25H
MOV B,#12H
DIV AB
MOV 44H,A
MOV 45H,B
MOV A,#25H
INC A
MOV 46H,A
DEC A
MOV 47H,A
END
FACTORIAL OF A NUMBER
Observation Format
Address Opcode Label Mnemonics Operands
ORG 00H
MOV A,#03H
MOV R0,#02H
BACK: MOV B,R0
MUL AB
DJNZ R0,BACK
MOV 40H,A
MOV 41H,B
END
45
Note: 1 ) Above Table (Program) written in Right Side of the Observation
2). Outputs are written in the left side of the Observation.
3). Address, Opcodes (.LST File) and Outputs are generated by the compiler after
successful execution of the program.
4). In record one more “comments” column is added to the table
Record Format
Address Opcode Label Mnemonics Operands Comments
0000 ORG 00H Starting Memory
Location
0000 7645 MOV A,#05h # 05 Immediate
value Moved to
Accumulator A
i.e #05H -> A
0002 56A9 MOV B,#09h #09 Immediate
value Moved to
register B
i.e #09H -> B
0004 34232A ADD A,B Addition is
performed the result
is stored into
accumulator register
A
Loop Loop execution
DJNZ R0,Loop Conditional
Instruction
1.Value of R0
decremented
(R0=R0-1)
2. R0 value is not
Zero
3.Compiler Jump to
Loop Label
Location
4. otherwise it is
zero
5.Execute the next
instruction , i.e
END
46
Procedure to create a project in Keil uVision-5:
1. Turn on the computer, create a folder on D drive saved with Register Number.
2. Open Keil uVision 5 in desktop, or windows start menu -> all programs->open Keil
uVision 5
Creating Project :
3. Go to project ->click on new uVision project -> create a new folder saved with experiment
number within the already existed register number folder in D drive mentioned in step 1, -
> enter the project name -> click on save
4. Select the device for target -> In devices ->Enter P89C51RD2XX in Search toolbar -> click
on ok -> select No for dialog box message “Copy STARTUP.A51 to project folder and add
files to project”. (Project bar is created in the left side of workspace consisting of Target 1
within that Source Group 1 present).
(or)
Choose NXP -> to select the device P89C51RD2XX -> click on ok -> select No for Copy
STARTUP.A51 to project folder.
Creating Coding File:
5. Go to file -> click on new->go to save (choose the path to save the file, It is saved within
the name of experiment number folder mentioned in step 3)-> enter a file name with
extension .asm->save the file.
Linking the Coding File to Project :
6. Right-click on Source group1 in project bar-> Add existing files to source group1-> choose
the experiment number folder path and select all files in the folder -> select .asm code file
->click on add-> click on close (i.e Code file is added in source group1 with indication of
“+” symbol in source group 1)
7. Write the assembly language program in .asm code file and save it.
Executing the Code File:
8. Right-click on .asm code file->Click on Build target to check the errors (i.e 0-Errors,0-
Warning)
9. Go to debug->Click on Start/Stop Debug Session -> click on ok for dialog box message
“running code size limit 2K” -> and Click on RUN in debug label
10. Observe the output in Register windows, Memory windows, Serial window (i.e. select the
output windows in view label).
47