0% found this document useful (0 votes)
37 views

2 Addition

Uploaded by

Aritra Ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

2 Addition

Uploaded by

Aritra Ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

//1ADDITION //6 Write an 8051 assemble language program: (a) Set SP = 0D, (b) //9 Write a program to add

rogram: (a) Set SP = 0D, (b) //9 Write a program to add 10 bytes of data and store the result in
ORG 0000H MOV A,#05H MOV B,#05H ADD A,B H: SJMP H END Put a different value in each of RAM locations 0D, 0C, 0B, 0A, 09 registers R2 and R3. The bytes are stored in the ROM space
and 08 (c) POP each stack location into registers R0 - R4. starting at 200H. The data would look as follows: MYDATA: DB 92,
34, 84, 129, ... Pick your own data. Notice that you must first bring
ORG 000H MOV SP,#0DH MOV 0DH,#10H MOV 0CH,#20H MOV
//2 SUBTRACTION the data from ROM space into the CPU's RAM, and then add them
0BH,#30H MOV 0AH,#40H MOV 09H,#50H MOV 08H,#60H POP 0
POP 1 POP 2 POP 3 POP 4 POP 5 HERE: SJMP HERE END together. Use a simulator to single step the program and examine
ORG 0000H MOV A,#05H MOV B,#04H SUB A,B H: SJMP H END
the data.
ORG 000H MOV DPTR, #200H MOV R0, #10H MOV R2, #00H MOV
//DIVISION //7 Write and assemble a program to load valuesinto each of R3, #00H LOOP: CLR A MOVC A, @A+DPTR ADD A, R2 JNC NEXT
registers R0 - R4 and then push each of these registers onto the INC R3 NEXT: INC DPTR MOV R2, A DJNZ R0, LOOP HERE: SJMP
ORG 0000H MOV A,#05H MOV B,#05H MUL AB H: SJMP H END
stack and pop them back. Single step the program, and examine HERE ORG 200H DB 22H, 43H, 23H, 34H, 31H, 77H, 91H, 33H,
the stack and the SP register after the execution of each 43H, 07H END
//4 Write and assemble a program to add the following data and instruction.
then use the simulator to examine the CY flag. 92H, 23H, 66H, ORG 0000H MOV R0, #10H MOV R1, #20H MOV R2, #30H MOV
87H, FSH R3, #40H MOV R4, #50H PUSH 0 PUSH 1 PUSH 2 PUSH 3 PUSH 4 //10 Write and assemble a program to toggle all the bits of P0, P1,
POP 4 POP 3 POP 2 POP 1 POP 0 END and P2 continuously by sending 55H and AAH to these ports. Put
ORG 0000H MOV A, #92H MOV R0, #23H ADD A, R0 JNC L1 INC a time delay between the "on" and "off" states. Then using the
R3 L1: ADD A, #66H JNC L2 INC R3 L2: ADD A, #87H JNC L3 INC simulator, single step through the program and examine the ports.
R3 L3: ADD A, #0F5H JNC L4 INC R3 L4: SJMP L4 END Do not single-step through the time delay calL
//8 Write a program to transfer a string of data from code space
starting at address 200H to RAM locations starting at 40H. The CODE ORG 0000H HERE: MOV P0, #55H MOV P1, #55H MOV P2,
//5 Write and assemble a program to load values into each of data is as shown below: 0200H: DB "VIT UNIVERSITY" Using the #55H ACALL DELAY MOV P0, #0AAH. MOV P1, #0AAH MOV P2,
registers R0 - R4 and then push each of these registers onto the simulator, single step through the program and examine the data #0AAH ACALL DELAY SJMP HERE DELAY: MOV R1, #04H BACK:
stack. Single step the program and examine the stack and the SP transfer and registers. MOV R2, #20H AGAIN: DJNZ R2, AGAIN DJNZ R1, BACK RET END
register after the execution of each instruction. ORG 0000H MOV DPTR, #0200H MOV R1, #0EH MOV R0, #40H
ORG 000H MOV R0,#30H MOV R1,#40H MOV R2,#50H MOV LOOP: CLR A MOVC A, @A+DPTR MOV @R0, A INC DPTR INC R0
DJNZ R1, LOOP HERE: SJMP HERE ORG 0200H DB "VIT //11 Get the Data from Port P1 and Send it to Port P2, Note: P1 as
R3,#60H MOV R4,#70H PUSH 0 PUSH 1 PUSH 2 PUSH 3 PUSH 4 input Port and P2 as Output Port
HERE: SJMP HERE END UNIVERSITY" END
MOV A, #0FFh MOV P1, A HERE: MOV A, P1 MOV P2, A SJMP HERE
END

//12 Write a program using timer 0 to generate a 500 Hz square


wave frequency on one of the pins of P1.0 Then examine the //14 Write a program using timer 1 to generate a 2 KHz square //18 Write an 8051 program to get data from port P0 and send it to
frequency using the KEIL IDE inbuilt Logic Analyzer. wave frequency on one of the pins of P1.0. port P1 continuously while an interrupt will do the following:
Frequency f = 500Hz ORG 0000H MOV TMOD, #20H HERE: MOV TH1, #19H BACK: Timer 0 will toggle the P2.1 bit every 100 microseconds.
Total time period T = 2ms SETB TR1 AGAIN: JNB TF1, AGAIN CPL P1.0 CLR TF1 SJMP BACK ORG 0000H LJMP MAIN ORG 000BH CPL P2.1 RETI ORG 0030H
Required delay = TON = TOFF = 1ms END MAIN: MOV TMOD,#02H MOV P0,#0FFH MOV TH0,#0A4H MOV
IE,#10000010B SETB TR0 BACK: MOV A,P0 MOV P1,A SJMP BACK
[(FFFF - XXXX) + 1] * 1.085µs = 1ms END
(65536 - X) * 1.085µs = 1ms //15 Assuming that clock pulses are fed into pin T1, write a
program for counter 1 in mode 2 to count the pulses and display
X = (64614)D the state of the TL1 count on P2, which connects to 8 LEDs. //19 Write an 8051 program to get data from a single bit of P1.2
X = XXXX = FC66H MOV TMOD, #01100000B MOV TH1, #0 SETB P3.5 AGAIN: SETB and send it to P1.7 continuously while an interrupt will do the
following: A serial interrupt service routine will receive data from a
ORG 0000H MOV TMOD, #01H HERE: MOV TL0, #66H MOV TH0, TR1 BACK: MOV A, TL1 MOV P2, A JNB TF1, BACK CLR TR1 CLR
PC and display it on P2 ports
#0FCH CPL P1.0 ACALL DELAY SJMP HERE DELAY: SETB TR0 TF1 SJMP AGAIN END
AGAIN: JNB TF0, AGAIN CLR TR0 CLR TF0 RET END ORG 0000H LJMP MAIN ORG 0023H LJMP DISP ORG 0050H MAIN:
SETB P1.2 MOV TMOD, #20H MOV TH1, #-3 MOV SCON, #50H
//16 Write an 8051-assembly program to transfer data serially at MOV IE, #10010000B SETB TR1 BACK:MOV C, P1.2 MOV P1.7, C
//13 Write a program using timer 1 to generate a 1 kHz square baud rate 9600 with 8- bit data, one stop bit, and observe the SJMP BACK DISP: MOV A, SBUF MOV P2, A CLR RI RETI END
wave frequency on one of the pins of P1. Then examine the transmi ed data in the serial window of the simulator
//20
frequency using the KEIL IDE inbuilt Logic Analyzer. ORG 0000H START: MOV DPTR, #MYDATA MOV TMOD, #20H MOV
TH1, #-3 MOV SCON, #50H SETB TR1 MOV R1, #14 AGAIN: CLR A Write an assembly-level program to display your roll number on
Frequency f = 1 KHz
MOVC A, @A+DPTR MOV SBUF, A HERE: JNB TI, HERE CLR TI INC LCD which is interfaced with an 8051 microcontroller.
Total time period T = 1ms
DPTR DJNZ R1, AGAIN SJMP START MYDATA: DB 'VIT UNIVERSITY' ORG 0000H MOV A, #38H ACALL COMMAND ACALL DELAY MOV
Required delay = TON = TOFF = 0.5ms END A, #0EH ACALL COMMAND ACALL DELAY MOV A, #01H ACALL
[(FFFF - XXXX) + 1] * 1.085µs = 0.5ms COMMAND ACALL DELAY MOV A, #82H ACALL COMMAND
ACALL DELAY MOV DPTR, #string back: MOV A, #00H MOVC A,
XXXX = FE33H //17 Generate a square wave signal from P1.2 which has 0.1ms off @A+DPTR JZ AGAIN ACALL DATATRANSFER ACALL DELAY INC
ORG 0000H MOV TMOD, #10H HERE: MOV TL1, #33H MOV TH1, me and 0.1ms on me use Timer 1 – mode 2 (Auto Reload mode) DPTR SJMP back ACALLDELAY AGAIN: SJMP AGAIN COMMAND:
#0FEH CPL P1.0 ACALL DELAY SJMP HERE DELAY: SETB TR1 ORG 0000H MOV TMOD, #20H HERE: MOV TH1, #0A4H CPL P1.2 MOV P2, A CLR P0.5 CLR P0.6 SETB P0.7 CLR P0.7 RET DELAY:
AGAIN: JNB TF1, AGAIN CLR TR1 CLR TF1 RET END LCALL DELAY SJMP HERE DELAY: SETB TR1 AGAIN: JNB TF1, MOV R3, #255 HERE: DJNZ R3, HERE RET DATATRANSFER: MOV
AGAIN CLR TF1 RET END P2, A SETB P0.5 CLR P0.6 SETB P0.7 CLR P0.7 EN

You might also like