Sample 8051 Programs
Sample 8051 Programs
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
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