0% found this document useful (0 votes)
61 views6 pages

8051 Microcontroller1

The document provides a detailed guide on running assembly language code for the 8051 microcontroller using Kiel µVision 5, including step-by-step instructions for setting up a project and executing code. It includes examples of assembly language programs for data transfer between internal and external RAM, as well as exchanging data blocks. Results before and after execution are also presented for each program to demonstrate functionality.

Uploaded by

princek2005singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views6 pages

8051 Microcontroller1

The document provides a detailed guide on running assembly language code for the 8051 microcontroller using Kiel µVision 5, including step-by-step instructions for setting up a project and executing code. It includes examples of assembly language programs for data transfer between internal and external RAM, as well as exchanging data blocks. Results before and after execution are also presented for each program to demonstrate functionality.

Uploaded by

princek2005singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

8051 Microcontroller (BECL456A)

Steps to run a assembly language code in Kiel

1. Double click on the Icon Kiel µVision 5.


2. Select Project tab, under that option New µVision Project.
3. A window opens to create a project. Create a folder and save by giving a file name
to the project.
4. A window opens to select the device. Select AT89C51 from the list of devices and
say OK.
5. Select File tab, under that new that opens a window where you can type the code
and save.
6. On the left palette, under the source group option, right click, add existing files to
source group. Select the file to be added to the source group.
7. Select Debug tab, under that option, start/stop debug option, the code is ready to be
executed.
8. To provide data in the memory, Select View tab, Select memory window, you can
select any memory location by typing the required address.
i. Internal RAM:I:0x20
ii. External Ram: X:0x20
9. After providing the input data, Select Debug Tab, Option Run and verify the results.
Data Transfer Programs
1. Write an ALP to move a block of n bytes of data from source (20h) to destination (40h) using
Internal-RAM. (select at89c51)
Program:
; ALP to transfer block of 5 data’s from location X (internal RAM) to location Y (internal RAM)
; It is assumed that location X starts from RAM location 20H & location Y starts from 40H
Org 0000 ; defining code location to start from location 0000
Mov r0,#0x20 ; initialising r0 as a memory pointer to location X
Mov r1,#0x40 ; initialising r1 as a memory pointer to location Y
Mov r2,#0x05 ; number of elements in the array is defined as a count= 05
Back: Mov a,@r0 ; reads a data from location X. @ indicates the value at 0x20 (Source)
Mov @r1,a ; transfers data to location Y (Destination)
Inc r0 ; points to next location in X (increment r0)
Inc r1 ; points to next location in Y (increment r1)

Djnz r2, back ; repeat data transfer until all the data are transferred (decrement r2, and jump to back
when r2 is not equal to zero)
Exit: sjmp exit ; specifies logical end of the program
End ; specifies physical end of the program
(to view go to memory location D:0x20, D represents data memory space(refers to internal ram), C represents
code memory space(refers to program memory), eg. If the RAM specification is 128 bytes, then internal
memory value ranges from 0x00 to 0x7F (i.e., 0 to 127 = 128/16 =8-1 = 7F)

Result:
Before Execution:
I:0020h: 01 02 03 04 05 06
I:0040h: 00 00 00 00 00 00

After Execution:
I:0020h: 01 02 03 04 05 06
I:0040h: 01 02 03 04 05 00
2. Write an ALP to move a block of n bytes of data from source (2000h) to destination (2050h) using
External RAM.

; ALP to transfer block of n bytes from source (2000h) to destination (2050h) using External-RAM
Org 0000h ; beginning of the program at 0000h location
Mov dptr,#2000h ; load dptr(one of 16 bit register(user accessible) out of two(program counter &
DPTR) with source location address
Mov r0,#50h ; r0 is loaded with destination location lower byte
; need 16 bit to store external ram memory location(20 is 8 bit and 50 is another 8 bit, I.e., 2050h) but we have
only one 16 bit register i.e., dptr which is already used for source address. So we are using 2, 8 bit registers, 1
for 20h and another for 50h, all together 2050h
Mov r1,#20h ; r1 is loaded with destination location upper byte
Mov r2,#04 ; r2 is loaded with block size
Loop: Movx a,@dptr ; here dptr is loaded with external memory so instead of mov, we should movx
– x is for external memory. Accumulator is loaded with content of address
which is present in dptr(16bit address)
Push dph ; save dptr content into stack (dph is data pointer higher or upper)
;(in order to load to the destination location which is stored in r0 and r1 we have to
take it to dptr, in such condition it will delete source location 2000h to avoid that
push the values to dph and dpl)
Push dpl ; save dptr content into stack (dpl is data pointer lower)
Mov dph,r1 ; load dph with r1 destination content(MSB) upper byte
Mov dpl,r0 ; load dpl with r0 destination content(LSB) lower byte
Movx @dptr,a ; move accumulator content to destination location

Inc dptr ; increment dptr (now it is destination location i.e., 2051)


Mov r1,dph ; once again store dph content (destination address) in r1 for upper bytes
Mov r0,dpl ; once again store dpl content (destination address) in r0 for lower bytes
Pop dpl ; restore dpl content of source location i.e., 00h
; (we already pushed 1st dph and 2nd dpl into stack which is first in last out principal,
so we should now pop as 2nd i.e., dpl first which is at the top of stack and then dph
which is next to dpl.)
Pop dph ; restore dph content of source location i.e., 20h
Inc dptr ; increment dptr address by 1 i.e., 2001h
Djnz r2,loop ; decrement r2, if not zero jump to lable ‘loop’
End ;
Result:
Before Execution:
X:2000h: 11 22 33 44 55 66
X:2050h: 00 00 00 00 00 00

After Execution:
X:2000h: 11 22 33 44 55 66
X:2050h: 11 22 33 44 00 00
3. Write an ALP To exchange the source block starting with address 20h, (Internal RAM) containing
N (05) bytes of data with destination block starting with address 40h (Internal RAM).
; ALP to exchange block of N bytes between source (20h) and destination (40h) in Internal-RAM
Org 0000h ; Define code location to start from address 0000h
Mov r0, #20h ; Load R0 with source address
Mov r1, #40h ; Load R1 with destination address
Mov r2, #05h ; Load R2 with the number of bytes to exchange
Back: Mov a, @r0 ; Load accumulator with the content of the source address
Xch a, @r1 ; Exchange accumulator content with the content of the destination address
Mov @r0, a ; Store the accumulator content at the source address
Inc r0 ; Increment source address
Inc r1 ; Increment destination address
Djnz r2, Back ; Decrement R2 and repeat the loop if it's not zero
End ; End of the program

Result:
Before Execution:
I:0020h: 01 02 03 04 05
I:0040h: 11 22 33 44 55
After Execution:
I:0020h: 11 22 33 44 55
I:0040h: 01 02 03 04 05
4. Write an ALP to exchange the source block starting with address 10h (Internal memory), containing
n (06) bytes of data with destination block starting at location 00h (External memory).
Program:
Org 0000h ; defining code location to start from location 0000
Mov r0,#10h ; load r0 with source location address
Mov dptr, #2000h ; load dptr register to hold destination address (or use 00h as per program)
Mov r2,#06h ; load r2 with block size
Back: movx a,@dptr ; load accumulator with the content of the address specified by (@)dptr, here
we are using external memory so we need to use movx, here x mention
external memory
Mov b,@r0 ; load reg b with internal memory(so no x) content
Xch a,b ; xchange accumulator (a) and reg b content
Movx @dptr,a ; from acc, move the content to dptr address [external]
Mov @r0,b ; from reg b move the content to r0 address [internal]
Inc r0 ; internal memory location increment r0 by 1
Inc dptr ; external memory location increment dptr by 1
Djnz r2,back ; decrement reg r2, if not zero jump to label ‘back’
End

Result:
Before Execution:
I:0010h: 01 02 03 04 05 06
X:2000h: 11 22 33 44 55 66
After Execution:
I:0010h: 11 22 33 44 55 66
X:2000h: 01 02 03 04 05 06

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy