1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PIC sequential variables

Discussion in 'Microcontrollers' started by throbscottle, Jul 10, 2017.

  1. throbscottle

    throbscottle Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,776
    Likes:
    113
    Location:
    Nuneaton, Warwickshire, UK
    Hi folks
    I having a go a double dabble (or it's reverse) to convert an 8 digit unpacked BCD to binary. Rather than assign a variable name to each digit, I think I can do this:
    If I use
    Code (text):

    digits idata
        digit db 1,2,3,4,5,6,7,8

    myprog code
    ...
    end
     
    I think I can loop through each digit by incrementing fsr and accessing indf, but how do I address the first (or any other, for that matter) digit?
    Also, if I use
    Code (text):

    output res 4    ; it needs to end up a 32bit word, whatever
     
    can I rrf my way through "output" instead of having 4 variable names to manage?

    Many thanks :)
     
  2. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,008
    Likes:
    316
    Location:
    Brisbane Australia
    Both should work. However, decide first whether you're using big or little endian. I prefer little endian - I.E lowest byte stored first.
    You can then do,
    Code (text):

        rrf  output+3,f    ;shift msbyte
        rrf  output+2,f    ;shift next byte
        rrf  output+2,f    ;shift next byte
        rrf  output,f    ;shift lsbyte
     
    Edit, you probably want to clear the carry before the shifts.

    I used double dabble a few years ago but wrote it in C.

    Mike.
     
  3. throbscottle

    throbscottle Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,776
    Likes:
    113
    Location:
    Nuneaton, Warwickshire, UK
    That's great, thanks Mike.
    It occurred to me after I posted the question, I need to change individual digits of the BCD input (which comes from a keypad). Do I use the same notation? eg digit+1, digit+2 etc?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. throbscottle

    throbscottle Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,776
    Likes:
    113
    Location:
    Nuneaton, Warwickshire, UK

    Now I get
    Code (text):
     Illegal directive (IDATA)
    And yet it's perfectly happy with udata :(
    Wahhhhhh....
     

Share This Page