You are on page 1of 27

228W1A0424, K.

SWATHI

Date: /09/2022

1(A). BASIC ARTHEMATIC INSTRUCTIONS


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
TOOLS REQUIRED: PC, Keil µvision5
PROCEDURE:
1. Turn on the computer, create a folder on D drive saved with Register Number.
2. Open Keil uVision5 in desktop, or windows start menu -> all programs->open Keil uVision5.

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

2nd Year, ECE-1 1


228W1A0424, K.SWATHI

a)

b)

2nd Year, ECE-1 2


228W1A0424, K.SWATHI

PROGRAM:
a)

ADDRESS OPCODES LABELS MNEMONICS OPERANDS

0000 ORG 00H

0000 7405 MOV A,#07H

0002 75F002 MOV B,#02H

0005 25F0 ADD A,B

0007 F540 MOV 30H,A

0009 7425 MOV A,#05H

000B 95F0 SUBB A,B

000D F541 MOV 31H,A

000F 7425 MOV A,#05H

0011 A4 MUL AB

0012 F542 MOV 32H,A

0014 7425 MOV A,#24H

0016 75F012 MOV B,#02H

0019 84 DIV AB

001A F543 MOV 33H,A

001C 7425 MOV A,#25H

001E 04 INC A

001F F546 MOV 36H,A

0021 14 DEC A

0022 F547 MOV 37H,A

END

b)
ADDRESS OPCODES LABELS MNEMONICS OPERANDS

0000 ORG 00H

0000 7405 MOV A,#04H

0002 7804 MOV R0,#03H

0004 88F0 BACK MOV B,R0

0006 A4 MUL AB

0007 D8FB DJNZ R0,BACK

0009 F540 MOV 60H,A

000B 85F041 MOV 61H,B

2nd Year, ECE-1 3


228W1A0424, K.SWATHI

END

2nd Year, ECE-1 4


228W1A0424, K.SWATHI

c)

ADDRESS OPCODES LABELS MNEMONICS OPERNADS


0000 ORG 00H
0000 780A MOV R0,#0AH
0002 88F0 MOV B,R0
0004 7400 MOV A,#00H
0006 28 BACK ADD A,R0
0007 D8FD DJNZ R0,BACK
0009 84 DIV AB
000A F550 MOV 50H,A
000C 85F051 MOV 51H,B
END

d)

ADDRESS OPCODES LABELS MNEMONICS OPERANDS


0000 ORG 00H
0000 7840 MOV R0,#40H
0002 7908 MOV R1,#07H
0004 86F0 LOOP MOV B,@R0
0006 08 INC R0
0007 E6 MOV A,@R0
0008 25F0 ADD A,B
000A 08 INC R0
000B F6 MOV @R0,A
000C 18 DEC R0
000D D9F5 DJNZ R1,LOOP
END

RESULT: The given Assembly Language Programs using arithmetic instructions

2nd Year, ECE-1 5


228W1A0424, K.SWATHI

a) Basic Arithmetic Operations


b) Factorial of a number
c) Average of first ten numbers
d) Fibonacci Series
are created and verified by using 8051 microcontroller.

2nd Year, ECE-1 6


228W1A0424, K.SWATHI

Date: /10/2022
1(B). BASIC LOGICAL INSTRUCTIONS
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
TOOLS REQUIRED: PC, Keil µvision5
PROCEDURE:
1. Turn on the computer, create a folder on D drive saved with Register Number.
2. Open Keil uVision5 in desktop, or windows start menu -> all programs->open Keil uVision5.

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

2nd Year, ECE-1 7


228W1A0424, K.SWATHI

2nd Year, ECE-1 8


228W1A0424, K.SWATHI

PROGRAMS:
a)
ADDRESS OPCODES LABELS MNEMONICS OPERANDS
0000 7867 MOV R0,#18H
0002 58 ANL A,R0
0003 F520 MOV 40H,A
0005 7445 MOV A,#45H
0007 48 ORL A,R0
0008 F521 MOV 41H,A
000A 7404 MOV A,#04H
000C 7445 MOV A,#45H
000E 68 XRL A,R0
000F F522 MOV 42H,A
0011 7416 MOV A,#16H
0013 F4 CPL A
0014 F523 MOV 43H,A
0016 C4 SWAP A
0017 F524 MOV 44H,A
0019 7404 MOV A,#04H
001B 03 RR A
001C F525 MOV 45H,A
001E 23 RL A
001F F526 MOV 46H,A
END

2nd Year, ECE-1 9


228W1A0424, K.SWATHI

2nd Year, ECE-1 10


228W1A0424, K.SWATHI

b)
ADDRESS OPCODES LABELS MNEMONICS OPERANDS
0000 ORG 00H
0000 7840 MOV R0,340H
0002 E6 MOV A,@R0
0003 54F0 ANL A,#0F0H
0005 C4 SWAP A
0006 2430 ADD A,#20H
0008 F541 MOV 21H,A
000A E6 MOV A,@R0
000B 540F ANL A,#0FH
000D 2430 ADD A,#20H
000F F542 MOV 22H,A
END
c)
ADDRESS OPCODES LABELS MNEMONICS OPERANDS
0000 ORG 00H
0000 7840 MOV R0,#40H
0002 E6 MOV A,@R0
0003 540F ANL A,#0FH
0005 C4 SWAP A
0006 F9 MOV R1,A
0007 08 INC R0
0008 E6 MOV A,@R0
0009 540F ANL A,#0FH
000B 29 ADD A,R1
000C 08 INC R0
000D F6 MOV @R0,A
END

2nd Year, ECE-1 11


228W1A0424, K.SWATHI

2nd Year, ECE-1 12


228W1A0424, K.SWATHI

d)
ADDRESS OPCODES LABELS MNEMONICS OPERANDS
0000 ORG 00H
0000 7808 MOV R0,#09H
0002 7900 MOV R1,#00H
0004 749F MOV A,#5DH
0006 C3 L1 CLR C
0007 33 RLC A
0008 5001 JNC L2
000A 09 INC R1
000B D8F9 L2 DJNZ R0,L1
000D 8940 MOV 30H,R1
END

RESULT: The given Assembly Language Programs using logical instructions


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
are created and verified by using 8051 microcontoller.

2nd Year, ECE-1 13


228W1A0424, K.SWATHI

Date: /10/2022

2. PROGRAMS ON TIMER OPERATON


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 .

TOOLS REQUIRED: PC, Keil µvision5


PROCEDURE:
1. Turn on the computer, create a folder on D drive saved with Register Number.
2. Open Keil uVision5 in desktop, or windows start menu -> all programs->open Keil uVision5.

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

2nd Year, ECE-1 14


228W1A0424, K.SWATHI

CALCULATIONS:
a) TIMER 0 MODE 1, 1SEC TIME DELAY

 Since XTAL = 11.0592 MHz


 12 Machine Cycles = 1 Clock Cycles
 Single clock period = 11.0592MHz/12 = 921.6KHz
= 1/921.6 = 1.085us
 Required delay = number of clocks X single clock period
1sec = number of clocks X 1.085us
Number of clocks = 9,21,658
 Mode 1 is 16 bit timer, Maximum clocks 65536
 Maximum time delay from 0000H state to FFFFH state is
= 65536 X 1.085us = 71.1ms
 1 sec = loop count X 71.1ms
Loop count = 14.06 = 0EH
 Therefore, we have initial values in TH = #00H and TL = #00H, TMOD
= #01H

b) TIMER 1 MODE 2, 2SEC TIME DELAY

 Since XTAL = 11.0592 MHz,


 12 Machine Cycles = 1 Clock Cycle
 Single clock period = 11.0592MHz/12 = 921.6Khz
= 1/921.6KHz = 1.085us
 Required delay = number of clocks X single clock period
2sec = number of clocks x 1.085us
Number of clocks = 18,43,317
 Mode 2 is 8 bit timer, Maximum clocks 256
 Maximum time delay from 00H state to FFH state is
= 256 X 1.085us = 277.76us
 2 sec = loop count X 277.76us
Loop count = 7200 = 1C20H
 Therefore, we have Initial values in TH = #00H, TMOD = #20H

2nd Year, ECE-1 15


228W1A0424, K.SWATHI

THEORY:

 The 8051 has two timers/counters, they can be used either as


 Timers to generate a time delay or as
 Events counters to count events happening outside the microcontroller.
 Both Timer 0 and Timer 1 are 16 bits wide
 Since 8051 has an 8-bit architecture, each 16-bit timer is accessed as two separate
registers of low byte and high byte

 Accessed as low byte and high byte


 The low byte register is called TL0/TL1 and
 The high byte register is called TH0/TH1
 Accessed like any other register

 MOV TL0, #4FH


 MOV R5, TH0

 Both timers 0 and 1 use the same register, called TMOD (timer mode), to set the various
timer operation modes
 TMOD is 8-bit register
 The lower 4 bits are for Timer 0
 The upper 4 bits are for Timer 1
 In each case
 The lower 2 bits are used to set the timer mode
 The upper 2 bits to specify the operation

2nd Year, ECE-1 16


228W1A0424, K.SWATHI

2nd Year, ECE-1 17


228W1A0424, K.SWATHI

PROGRAMS:
a)
ADDRESS OPCODES LABELS MNEMONICS OPERANDS
0000 ORG 00H
0000 758901 MOV TMOD,#01H
0003 7455 MOV A,#55H
0005 90FFC0 MOV DPTR,#0FFC0H
0008 1110 L2 ACALL DELAY
000A F0 MOVX @DPTR,A
000B F5A0 MOV P2,A
000D F4 CPL A
000E 80F8 SJMP L2
0010 780E DELAY MOV R0,#0EH
0012 758A00 L1 MOV TL0,#00H
0015 758C00 MOV TH0,#00H
0018 D28C SETB TR0
001A 308DFD HERE JNB TF0, HERE
001D C28D CLR TF0
001F C28C CLR TR0
0021 D8EF DJNZ R0,L1
0023 22 RET
END

2nd Year, ECE-1 18


228W1A0424, K.SWATHI

2nd Year, ECE-1 19


228W1A0424, K.SWATHI

b)
ADDRESS OPCODES LABELS MNEMONICS OPERANDS
0000 ORG 00H
0000 758920 MOV TMOD,#20H
0003 7455 MOV A,#55H
0005 90FFC0 MOV DPTR, #0FFC0H
0008 1110 LOOP ACALL DELAY
000A F4 CPL A
000B F0 MOVX @DPTR,A
000C F5A0 MOV P2,A
000E 80F8 SJMP LOOP
0010 791C DELAY MOV R1,#1CH
0012 7A20 BACK2 MOV R2,#20H
0014 758D00 BACK1 MOV TH1,#00H
0017 D28E SETB TR1
0019 308FFD HERE JNB TF1,HERE
001C C28F CLR TF1
001E C28E CLR TR1
0020 DAF2 DJNZ R2,BACK1
0022 D9EE DJNZ R1,BACK2
0024 22 RET
END

RESULT: The given Assembly Language Programs are successfully created and verified.

2nd Year, ECE-1 20


228W1A0424, K.SWATHI

Date: /09/2022
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.

TOOLS REQUIRED: PC, Keil µvision5


PROCEDURE:
1. Turn on the computer, create a folder on D drive saved with Register Number.
2. Open Keil uVision5 in desktop, or windows start menu -> all programs->open Keil uVision5.

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

2nd Year, ECE-1 21


228W1A0424, K.SWATHI

CALCULATIONS:
b)

 T = 1 / f = 1 / 2 kHz = 500 us is the period of square wave


 1 / 2 of it for the high and low portion of the square is 250 us
 Required delay=number of clocks X single clock period
250 us=number of clocks x 1.085us
Number of clocks=230
 Timer 1 Mode 1 is 16 bit timer, Maximum clocks 65536
65536 – 230 = 65306 which in hex is FF1AH.
TL1 = 1AH and TH1 = FFH

2nd Year, ECE-1 22


228W1A0424, K.SWATHI

THEORY:

 Timers can also be used as counters counting events happening outside the 8051
 When it is used as a counter, it is a pulse outside of the 8051 that increments the TH,
TL registers
 TMOD and TH, TL registers are the same as for the timer discussed previously
 Programming the timer in the last section also applies to programming it as a counter
 Except the source of the frequency

 The C/T bit in the TMOD registers decides the source of the clock for the timer
 When C/T = 1, the timer is used as a counter and gets its pulses from outside the 8051
o The counter counts up as pulses are fed from pins 14 and 15, these pins are
called T0 (timer 0 input) and T1 (timer 1 input)

2nd Year, ECE-1 23


228W1A0424, K.SWATHI

2nd Year, ECE-1 24


228W1A0424, K.SWATHI

PROGRAMS:
a)
ADDRE OPCOD LABE MNEMONI OPERNADS
SS ES LS CS
0000 ORG 00H
0000 758906 MOV TMOD,#06H
0003 90FFC1 MOV DPTR,#0FF
C1H
0006 758C00 MOV TH0,#00H
0009 D2B4 SETB P3.4
000B D28C AGAI SETB TR0
N
000D E58A BACK MOV A,TL0
000F F0 MOVX @DPTR,A
0010 F5A0 MOV P2,A
0012 308DF8 JNB TF0,BACK
0015 C28C CLR TR0
0017 C28D CLR TF0
0019 80F0 SJMP AGAIN
END

2nd Year, ECE-1 25


228W1A0424, K.SWATHI

2nd Year, ECE-1 26


228W1A0424, K.SWATHI

b)

ADDRE OPCOD LABE MNEMONI OPERNADS


SS ES LS CS
0000 ORG 00H
0000 758961 MOV TMOD,#61H
0003 D2B5 SETB P3.5
0005 90FFC1 MOV DPTR,#0FFC
1H
0008 758D00 MOV TH1,#00H
000B D28E AGAI SETB TR1
N
000D 111F L2 ACALL DELAY
000F B2B5 CPL P3.5
0011 E58B MOV A,TL1
0013 F0 MOVX @DPTR,A
0014 F5A0 MOV P2,A
0016 308FF4 JNB TF1,L2
0019 C28E CLR TR1
001B C28F CLR TF1
001D 80EC SJMP AGAIN
001F 758A1A DELA MOV TL0,#1AH
Y
0022 758CFF MOV TH0,#0FFH
0025 D28C SETB TR0
0027 308DFD HERE JNB TF0,HERE
002A C28D CLR TF0
002C C28C CLR TR0
002E 22 RET
END

RESULT: The given Assembly Language Programs are successfully created and verified.

2nd Year, ECE-1 27

You might also like