Programs in 8051 microcontroller




















Notify me of new comments via email. Notify me of new posts via email. This site uses Akismet to reduce spam. Learn how your comment data is processed. Yes jump to L2. If there is carry go to next step. Now small number is in R4. It works well. If there is no carry go to next step. Now large number is in R4. Yes; jump to L3. Note: Figure shows internal RAM organization of This is the lowest level of programming languages and is the language that a Microcontroller or Microprocessor actually understands.

The next level of Programming Language is the Assembly Language. Assembly Language is a pseudo-English representation of the Machine Language. The Microcontroller Assembly Language is a combination of English like words called Mnemonics and Hexadecimal codes. It is also a low level language and requires extensive understanding of the architecture of the Microcontroller.

The name High-level language means that you need not worry about the architecture or other internal details of a microcontroller and they use words and statements that are easily understood by humans. Although High-level languages are easy to work with, the following reasons point out the advantage of Assembly Language.

Each line or statement of the assembly language program of Microcontroller consists of three fields: Label, Instruction and Comments. The arrangement of these fields or the order in which they appear is shown below. NOTE: The brackets for Label and Comments mean that these fields are optional and may not be used in all statements in a program. Before seeing about these three fields, let us first see an example of how a typical statement or line in an Microcontroller Assembly Language looks like.

The Label is programmer chosen name for a Memory Location or a statement in a program. The Label part of the statement is optional and if present, the Label must be terminated with a Colon :.

An important point to remember while selecting a name for the Label is that they should reduce the need for documentation. The Instruction is the main part of the Microcontroller Assembly Language Programming as it is responsible for the task performed by the Microcontroller.

The first part of the Instruction is the Op-code, which is short for Operation Code, specifies the operation to be performed by the Microcontroller. Op-codes in Assembly Language are called as Mnemonics. Mov r7, 0Ah ; initialize counter by 10d. Mov r0, 20h ; get initial source location. Mov dptr, h ; get initial destination location.

Nxt: Mov a, r0 ; get first content in acc. Movx dptr, a ; move it to external location. Inc r0 ; increment source location. Inc dptr ; increase destination location. Djnz r7, nxt ; decrease r7.

Statement 6: — find out how many equal bytes between two memory blocks 10h to 20h and 20h to 30h. Solution: — here we shall compare each byte one by one from both blocks. Increase the count every time when equal bytes are found. Mov r0, 10h ; get initial location of block1. Mov r1, 20h ; get initial location of block2. Mov r6, 00h ; equal byte counter. Starts from zero. Nxt: Mov a, r0 ; get content of block 1 in acc. Mov a, r1 ; get content of block 2 in acc.

Cjne a, b, nomatch ; compare both if equal. Inc r6 ; increment the counter. Nomatch: inc r0 ; otherwise go for second number. Inc r1. Statement 7: — given block of h to h. Find out how many bytes from this block are greater then the number in r2 and less then number in r3. Store the count in r4. Solution: — in this program, we shall take each byte one by one from given block. Now here two limits are given higher limit in r3 and lower limit in r2. So we check first higher limit and then lower limit if the byte is in between these limits then count will be incremented.

Mov dptr, h ; get initial location. Mov r7, 0FFh ; counter. Mov r4, 00h ; number counter. Mov 20h, r2 ; get the upper and lower limits in.

Mov 21h, r3 ; 20h and 21h. Nxt: Movx a, dptr ; get the content in acc. Cjne a, 21h, lower ; check the upper limit first. Sjmp out ; if number is larger. Lower: jnc out ; jump out. Cjne a, 20h, limit ; check lower limit. Sjmp out ; if number is lower. Limit: jc out ; jump out. Inc r4 ; if number within limit increment count. Out: inc dptr ; get next location. Djnz r7, nxt ; repeat until block completes.

Statement the crystal frequency is given as 12 MHz. Make a subroutine that will generate delay of exact 1 ms. Use this delay to generate square wave of 50 Hz on pin P2.



0コメント

  • 1000 / 1000