Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Read 10 bits and 16 bits as an number in MPLAB asm

Status
Not open for further replies.

vishy71

Full Member level 2
Joined
Dec 16, 2010
Messages
126
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Iran
Activity points
2,296
Hi
I wanna read TMR3 value and show it on LCD!
before you help me to show decimal value(0 to 255) as number on LCD!
but now what we can do to show 16 bits on LCD as number?

and if you say how I can divide numbers in assembly and how can I puls or.... in
assembly with numbers greather than 255
thanks
 

This code will do a single binary number and store the results in 3 varaibles, in there ascii format ready for displaying

Code:
Hundreds     equ     0x20
Tens        equ     0x21
units        equ    0x22
working        equ    0x23
numtocon    equ    0x24
count        equ    0x25
 
 
Start
        clrf    Hundreds
        clrf    Tens
        clrf    Units
 
        movlw    d'159'    ;load w with the number to covert
        movwf    numtocon        
 
        movlw    d'8'
        movwf    count        
ShiftLoop
;test lowerbcd        
        movfw    units
        andlw    b'1111'
        movwf    working
        movlw    d'5'
        subwf    working,0
        SKPC        
        Goto    TestUpperNibble
        movlw    d'3'
        addwf    units
TestUpperNibble        
        movfw    units
        andlw    b'11110000'
        movwf    working
        movlw    H'50'
        subwf    working,0
        SKPC        
        goto    Shiftbit
        movlw    H'30'
        addwf    units
shiftbit
        rlf    units,1
        rlf    hundreds,1
        SKPNC
        bsf    hundreds,0
        rlf    numtocon,1
        SKPNC    
        bsf    Units,0
        decfsz    count
        goto    ShiftLoop
        movfw    Units
        Movwf    Tens
        swapf    Tens,1
        movlw    b'1111'
        andwf    Units,1
        andwf    Tens,1
        movlw    d'48'
        addwf    Hundreds
        addwf    Tens
        addwf    Units
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi

thanks but I do it!it's for 8bit numbers but I wanna convert 16bits numbers!as example TMR1
 

thanks! but I can't understand! we don't have 10bit register!do we have?

---------- Post added at 16:51 ---------- Previous post was at 16:50 ----------

and I want assembly code not C
 

The first link explains the principle of the process, this can then be used to convert using assembler, which is what I did for 8 bits.

Check out this link **broken link removed** for 16 bit to 5 digit binary, for 10bits, just set the remaining bits to 0.
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
thanks a lot!I will try it!
 

Hi vishy71,


I have modified the code I post earlier to work with 5 digit numbers, here is the code using the Double dabble process.


Code:
TensThousands     equ 0x20
Thousands    equ 0x21
Hundreds        equ 0x22
Tens        equ 0x23
units        equ 0x24
working        equ 0x25
numtoconLb    equ 0x26
numtoconHb    equ 0x27
count        equ 0x28
 
 
 
 
 
Start
        clrf    tensthousands
        clrf    Thousands
        clrf    Hundreds
        clrf    Tens
        clrf    Units
 
;this is the number to be converted
        movlw    0xDD                
        movwf    numtoconHB
        movlw    0xF5
        movwf    numtoconLB        
 
        movlw    d'3'
        movwf    count        
InitialShift
;perform 3 shifts before 1st test
        rlf    numtoconLB
        rlf    numtoconHB
        rlf    Units        
        decfsz    count
        goto    InitialShift
 
        movlw    d'13'
        movwf    count
ShiftLoop
        movfw    Units
        andlw    b'1111'
        movwf    working
        movlw    d'5'
        subwf    working,0
        SKPC        
        Goto    TestUnitsUpperNibbleByte
        movlw    d'3'
        addwf    units
TestUnitsUpperNibbleByte        
        movfw    units
        andlw    b'11110000'
        movwf    working
        movlw    H'50'
        subwf    working,0
        SKPC        
        goto    TestHundredsbyteLowerNibble
        movlw    H'30'
        addwf    units
 
TestHundredsbyteLowerNibble
        movfw    Hundreds
        andlw    b'1111'
        movwf    working
        movlw    d'5'
        subwf    working,0
        SKPC        
        Goto    TestHundredsbyteUpperNibble
        movlw    d'3'
        addwf    Hundreds
TestHundredsbyteUpperNibble        
        movfw    Hundreds
        andlw    b'11110000'
        movwf    working
        movlw    H'50'
        subwf    working,0
        SKPC        
        goto    TestTensThousandsByteLowerNibble
        movlw    H'30'
        addwf    Hundreds
 
;Use tensthousands, means that we need not move after conversion
TestTensThousandsByteLowerNibble
        movfw    TensThousands
        andlw    b'1111'
        movwf    working
        movlw    d'5'
        subwf    working,0
        SKPC        
        Goto    Shiftbits
        movlw    d'3'
        addwf    TensThousands
shiftbits
;rotate through the C flag and into the variables
        rlf    numtoconLB
        rlf    numtoconHB
        rlf    Units
        rlf    Hundreds
        rlf    TensThousands    
        decfsz    count
        goto    ShiftLoop
 
 
;get the BDC results in the correct variables
        movfw    Units
        Movwf    Tens
        swapf    Tens,1
        movlw    b'1111'
        andwf    Units,1
        andwf    Tens,1
 
        movfw    Hundreds
        Movwf    Thousands
        swapf    Thousands,1
        movlw    b'1111'
        andwf    Hundreds,1
        andwf    Thousands,1
 
;Convert variables to their ASCII code
        movlw    d'48'
        addwf    TensThousands
        addwf    Thousands
        addwf    Hundreds
        addwf    Tens
        addwf    Units
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
wow!

thanks!really thanks! it working!

---------- Post added at 16:30 ---------- Previous post was at 16:16 ----------

hi
another question please!
whats the skpc instruction in our code please?
thanks
 

Hi
microchip site in our country is forbbiden!can you please download it for me and upload it to another server to I can download it? thanks
 

Here we go .
 

Attachments

  • MASM.pdf
    81.1 KB · Views: 120
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
really thanks!a lot of thanks!
i wish the best happens for you
be happy in your life is my wish
thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top