Connect with us

Pic Micro Nybble question

Discussion in 'Electronic Design' started by Chris Miller, Feb 22, 2004.

Scroll to continue with content
  1. Chris Miller

    Chris Miller Guest

    Is it possible to define two nybble variables for the same 8 bit register
    with
    a 16F84A pic micro?

    I want to use an 8 bit reg to hold two BCD numbers.

    When I inc or dec each BCD number it would be much easier to do If I could
    refer to them as independant variables instead of masking and shifting.

    Any help is much appreciated.

     
  2. Dan Henry

    Dan Henry Guest

    Not for using them the way you really *want* to as you've described.
    FYI, the PIC18 family has a decimal adjust (DAW) instruction for
    handling BCD that the PIC16 family lacks.
    We call that packed BCD.
    Shifting is optional. Add 1 to increment the LSN. Add 16 to
    increment the MSN. Masking and comparison operations will be required
    to handle nibble overflow from 9 to 0.
     
  3. j.b. miller

    j.b. miller Guest

    yes, what language do you use ? ASM,BASIC, C , ???

    need a bit( no pun) more info !!

    jay
     
  4. Chris Miller

    Chris Miller Guest

    I am using assembly.
     
  5. Ben Bradley

    Ben Bradley Guest

    Use an Atmel AVR microcontroller, it has a "swap" instruction that
    swaps the upper and lower nybbles of a byte. :)

    Seriously (if you're not going to use an AVR), you are left with
    the processor's available instructions to implement this. The idea of
    using the processor's equivalent of add #1,reg and add #$10,reg for
    incrementing lower and upper nybbles, and similar subtract
    instructions for decrementing are great if you know you won't get
    overflow or underflow. If you do, then you'll obviously have to write
    a lot of 'checking' code. There's just no short cut for this.
    For this method to be worth your time programming it, you have to
    be really cramped for RAM/registers, and going to a chip with more ram
    is unacceptable for some very good reason.
     
  6. Tim Dicus

    Tim Dicus Guest

    PICs have SWAPF. That swaps nybbles.

    Tim
     
  7. Tim Shoppa

    Tim Shoppa Guest

    How many BCD digits do you deal with in whole? Are they always grouped
    in pairs?

    Unless you're dealing with dozens of digits, the savings you get by
    packing two digits per byte is probably negligible.

    Of course in a PIC, register file space is not directly exchangeable
    with program space. But only when I'm running out of register file
    space and have plenty of extra program space do I even think about
    putting two BCD digits in a byte.

    Tim.
     
  8. If you're talking about incrementing/decrementing a packed-BCD number,
    you can use the DC bit (STATUS, bit 1) to help do a correction after
    regular 2's complement addition or subtraction.

    Eg. add 0x66 to the number first, then increment. The carry is the BCD
    carry. If there is no DC then subtract 0x06, if there is no carry,
    then subtract 0x60. That easy.

    Best regards,
    Spehro Pefhany
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-