Shop OBEX P1 Docs P2 Docs Learn Events
Help Joining Nibbles — Parallax Forums

Help Joining Nibbles

GrimChildGrimChild Posts: 3
edited 2010-05-29 05:00 in BASIC Stamp
lcdbits VAR Byte
n1 VAR Nib

tempbyte VAR Byte

Main:
 lcdbits=%01000111
 n1= %1000

 tempbyte=[noparse][[/noparse]n1+lcdbits.LOWNIB]
 DEBUG ? tempbyte
END


I'm trying to concatenate 2 nibbles without much luck.
..instead of joining the low and high nibs it appears to be adding them.

taking n1 as 1000
and the low nib of lcdbits 0111
the output should be %10000111

thanks for the help .

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-29 03:55
    Taking the .LOWNIB of %01000111 is %0111. The .HIGHNIB of %01000111 is %0100.

    It sounds like you want to do "tempbyte.lownib = lcdbits.lownib", then "tempbyte.highnib = n1.lownib".
  • GrimChildGrimChild Posts: 3
    edited 2010-05-29 04:34
    Thanks mike, but my code was just for demonstration
    i'm aware that you can change the upper/lower nibbles
    .but im wondering if you can concatenate them as you would with String manipulation.
    ..I have alternatives, but doing it this way would lessen the code
    ..as lcdbits.HIGHNIB constantly changes and lcdbits.LOWNIB changes on occasion
    ..yet the output needs to be 8 bits

    can SHIFTOUT send only 4 bits ? or does it have to be 8 ?
    i'm using the 74hc595 and sending 2 sets of nibbles then latching fails.

    either solution would work i suppose.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-29 04:53
    You can't concatenate nibbles like strings. In fact, you can't concatenate strings with a Stamp. Stamps don't really have strings the way you're thinking of them

    SHIFTOUT can send any number of bits up to 16. Look at the chapter in the Manual on SHIFTOUT. You'll see a "\" suffix that lets you specify the number of bits.
  • GrimChildGrimChild Posts: 3
    edited 2010-05-29 05:00
    Gotcha ! . Thanks Mike
    i'll be needing your help in the future im sure [noparse]:)[/noparse]
Sign In or Register to comment.