Binary assignment syntax - confused?


Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Default Binary assignment syntax - confused?

    I'm not sure of how the binary bits are assigned to registeres when written different ways.

    - I know I can change bit 4 of TRISA by writing: TRISA.4 = 1

    - I know I can set all bits of an 8 bit register to 1 by writing: TRISC = %11111111

    But I don't know what order those numbers corespond to the registers. For example:

    TRISC = %01111111

    Does that set bit 0 or bit 8 to "0"?


    And what about the many registeres that don't have all their values - a register that has bits I can set for bits 0-2, but I can't set 3, but I can set bit 4 and 5, and I can't set bit 7 and 8.

    Does that mean I just omit those out of the placement in my string? For example:

    PCON = %11000

    ... where each position in the string automatically falls into the bits I can change, or do I still need to fill all the didgets with some value, even if that place in the string represents a bit I cannot change (it's a grey box with a dash in the data sheet).


    My confusion on this has lead me to writing all my programs like:

    PCON.0 = 1
    PCON.1 = 0
    PCON.4 = 0
    PCON.5 = 1

    ... I'd like to save some space and say:

    PCON = %1001 or...
    PCON = %10000100 or....
    PCON = %00100001 (the above reversed)


    ..... but I don't know how the various positions assign to the various bits.




    And to expand on that .... how would I assign just a few bits without changing the others? What if I wanted to assign "1111" to bits 2,3,4,5 without effecting bits 0,1 and 6,7? I've seen stuff like "$0f" in this context which I assume refers to the hex assignement of something, but again, no luck finding a consise primer or tutorial on this stuff.

    I get what hex and binary numbering shemese are - lots of refrences for those, but none that show how to actually syntax it in PBP.

    Can someone provide a good reference on this? I'm sure it's spelled out someplace but searching for "bit" "bitwise" "assembly bit assignment", etc on google turns up nothing.
    Last edited by kevj; - 10th November 2007 at 21:51.

Similar Threads

  1. PIC16F628 - Convert Binary to BCD?
    By steng in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th March 2009, 08:17
  2. help required regarding reading binary files
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th March 2008, 22:30
  3. Math operations & Syntax?
    By kevj in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 23rd February 2008, 01:40
  4. Serial reading of binary at 75 baud
    By JasonMarsh in forum Serial
    Replies: 5
    Last Post: - 20th February 2008, 16:36
  5. Decimal to binary conversion
    By Demon in forum Code Examples
    Replies: 9
    Last Post: - 25th February 2005, 20:05

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts