sample 8051prgm

12
Microprocessors and Microcontrollers 8051 programs

Upload: ayush-purohit

Post on 22-Oct-2015

59 views

Category:

Documents


0 download

DESCRIPTION

cvcx

TRANSCRIPT

Page 1: Sample 8051Prgm

Microprocessors and Microcontrollers

8051 programs

Page 2: Sample 8051Prgm

Microprocessors and Microcontrollers

• Write an 8051 program to fill the odd series from memory location 0030h to 0035h

ORG 0MOV R1,#30HMOV R2,#05MOV A,#1BACK:MOV @R1,AINC R1ADD A,#2DJNZ R2,BACKEND

Page 3: Sample 8051Prgm

Microprocessors and Microcontrollers

• Write an 8051 program to copy the string “Welcome to 8051 Programming” stored at 300H ROM space to RAM location starting at location 22H.

• Note: Loop should repeat exactly as the length of the string

Page 4: Sample 8051Prgm

Microprocessors and Microcontrollers

ORG 000CLR AMOV DPTR,#COUNTMOVC A,@A+DPTRMOV R1,AMOV DPTR,#MYDATAMOV R0,#22HBACK: CLR AMOVC A,@A+DPTRMOV @R0,AINC DPTRINC R0DJNZ R1,BACKHERE: SJMP HEREORG 300HMYDATA:DB "WELCOME TO JIITU !!!"COUNT:DB $-MYDATAEND

Indirect Addressing Mode

Indirect Addressing Mode

Page 5: Sample 8051Prgm

Microprocessors and Microcontrollers

Execute the above program with the string terminated by NULL character and without using the counter.

Page 6: Sample 8051Prgm

Microprocessors and Microcontrollers

ORG 000MOV DPTR,#MYDATAMOV R0,#22HBACK: CLR AMOVC A,@A+DPTRJZ HEREMOV @R0,AINC DPTRINC R0SJMP BACKHERE: SJMP HEREORG 300HMYDATA:DB "WELCOME TO JIITU !!!",0END

String Terminated by NULL Character

Indirect Addressing Mode

Page 7: Sample 8051Prgm

Microprocessors and Microcontrollers

Addition of two 8 bit number which are stored at 300H ROM space as DATA1 and DATA2

Page 8: Sample 8051Prgm

Microprocessors and Microcontrollers

ORG 000MOV DPTR,#DATA1BACK: CLR AMOVC A,@A+DPTRMOV R0,AMOV DPTR,#DATA2CLR AMOVC A,@A+DPTR ADD A,R0INC DPTRHERE: SJMP HEREORG 300HDATA1:DB 12HDATA2:DB 55HEND

Page 9: Sample 8051Prgm

Microprocessors and Microcontrollers

• Program to add the two consecutive memory locations stored at 50H ROM space using DATA directive and storing the result in next consecutive memory location. ORG 0

DATA1 DATA 0x50DATA2 DATA 0x51DATA3 DATA 0x52LJMP 250ORG 250MOV DATA1,#55hMOV DATA2,#22hMOV A,DATA1ADD A,DATA2MOV DATA3,AHERE: SJMP HEREEND

DATA directive

Page 10: Sample 8051Prgm

Microprocessors and Microcontrollers

• Computes Z = X + Y; Using EQU directive

ORG 0X EQU 66HY EQU 77HZ EQU 0MOV A,#XADD A,#YMOV Z,AMOV R0,ZHERE: SJMP HEREEND

EQU directive

Page 11: Sample 8051Prgm

Microprocessors and Microcontrollers

Write program to add R0,R1,R2,R3 of Bank-0, Bank-1, Bank-2, Bank-3 respectively.

P --OVRS0RS1F0ACCY PSW

Page 12: Sample 8051Prgm

Microprocessors and Microcontrollers

ORG 0CLR PSW.3CLR PSW.4CLR AMOV R0,#1ADD A,R0SETB PSW.3CLR PSW.4MOV R1,#2ADD A,R1CLR PSW.3SETB PSW.4MOV R2,#3ADD A,R2SETB PSW.3SETB PSW.4MOV R3,#4ADD A,R3END

BANK-0

BANK-1

BANK-2

BANK-3