Conversion of 8-bit binary numbers in R0 to 3-bit BCD-microcontroller programming

Source: Internet
Author: User

Single-chip microcomputer is not difficult programming problems! URGENT!!!!!!

Converts the 8-bit binary number in the R0 to 3-bit BCD, resulting in a 1002h~1000h (from high to low) unit of external RAM.

For example: At the beginning, the data in the R0 is: 81H (129) 10; After the program executes, the external RAM:
Address content
1002H 01H
1001H 02H
1000H 09H

Reward Points: 15-resolution Time: 2009-10-15 19:10
Questioner: Stefine_-First Class
;-----------------------------------------------------
Best Answer:

Oh, the program upstairs, the use of Dec DPTR, to know, 51 SCM instruction system inside, is no dec DPTR instructions.

According to the following ideas, you can also be more concise.

  mov   DPTR, #1000H    , single-digit address
    mov   a,   R0
    mov   b,   #10
    div   AB
     xch   a,   B
    movx  @DPTR, A
    INC    DPTR
    mov   a,   #10
    xch   A,    b
    div   AB
    xch   a,   b
    movx  @DPTR, A
    inc   DPTR
    xch    a,   B
    movx  @DPTR, A
    RET

Only 24 bytes are used.
;-------------------------------------------------------
Respondents: doing and talking about the Tao-level eight 2009-10-15 19:02
The questioner evaluates the answer: Thank you.
Original URL: http://zhidao.baidu.com/question/121520777.html
;-------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.