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

Sample 8051 Programs

The document contains four assembly programs for the 8051 microcontroller. Program 1 transfers a string from code space to RAM, Program 2 calculates a polynomial using a lookup table, Program 3 transmits data serially at a baud rate of 9600, and Program 4 continuously transfers data from one pin to another while handling serial interrupts. Each program includes specific instructions and data locations for execution.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Sample 8051 Programs

The document contains four assembly programs for the 8051 microcontroller. Program 1 transfers a string from code space to RAM, Program 2 calculates a polynomial using a lookup table, Program 3 transmits data serially at a baud rate of 9600, and Program 4 continuously transfers data from one pin to another while handling serial interrupts. Each program includes specific instructions and data locations for execution.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program 1

Write a program to transfer a string of data from code space starting at


address 0200H to RAM locations starting at 40H. The data is as shown below:
0200H:DB 'VIT UNIVERSITY' Using the simulator, single-step through
the program and examine the data transfer and registers.

ORG 0000H
MOV DPTR,#0200H
MOV R1,#0EH
MOV R0,#40H
LOOP: CLR A
MOVC A,@A+DPTR
MOV @R0,A
INC DPTR
INC R0
DJNZ R1,LOOP
HERE: SJMP HERE
ORG 0200H
DB 'VIT UNIVERSITY'
END

Program 2

Write a program to calculate y where y = x^2 + 2x + 9. x is between 0 and 9 and the


look-up table for x^2 is located at the address (code space) of 200H. Register R0
has the x, and at the end of the program R2 should have y. Use the simulator to
change the x value and single-step
through the program,examining the registers as you go.
program :

ORG 000H
MOV DPTR,#200H
MOV A,#03H
MOV R1,A
MOV R0,A
ADDC A,R1
MOV R1,A
MOV A,R0
MOVC A,@A+DPTR
ADDC A,#09H
ADDC A,R1
MOV R2,A
HERE: SJMP HERE
ORG 200H
DB 00H,01H,04H,09H,10H,19H,24H,31H,40H,51H
END

Program 3
Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8
bit data, one stop bit and observe the transmitted data 'VIT UNIVERSITY ' in the
serial window of the simulator.

ORG 0000H
XX: MOV DPTR,#MYDATA
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
MOV R1,#15
AGAIN:CLR A
MOVC A,@A+DPTR
MOV SBUF,A
HERE: JNB TI,HERE
CLR TI
INC DPTR
DJNZ R1,AGAIN
SJMP XX
MYDATA: DB 'VIT UNIVERSITY '
END

Program 4
Write an 8051 program to get data from a single bit of P1.2 and send it to P1.7
continuously while an interrupt will do the following: A serial interrupt service
routine will receive data from a PC and display it on P2 ports. 9600 BAUD RATE.

ORG 0000H
LJMP MAIN
ORG 0023H ; serial interrupt vector table
LJMP SERIAL
ORG 0030H ; after vector table space
MAIN:SETB P1.2 ; P1.2 made as input pin
MOV TMOD,#20H ; timer 1 mode 2
MOV TH1,#-3 ; set baud rate 9600
MOV SCON ,#50H ; one stop bit
MOV IE,#10010000B ; serial int enabled.
SETB TR1 ; Timer 1 stared
BACK:MOV C,P1.2
MOV P1.7,C
SJMP BACK
SERIAL:JB TI,TRANS
MOV A,SBUF
MOV P2,A
CLR RI
RETI
TRANS:CLR TI
RETI
END

You might also like