There has to be an easier way!


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default There has to be an easier way!

    I don't have much experience with the lookup command and I don't understand what the manual states. I will post the code here and someone let me know if I can clean it up please.

    B1=8
    B2=6
    B3=11
    B4=15

    'I NEED TO TAKE THESE INTO BINARY, BUT I CAN'T FIGURE OUT HOW TO DO IT. WITHIN B1, I NEED R1, R2, R3 AND R4 TO EQUAL THE BINARY OF B1, LIKE THIS

    'THE OUTPUT OF B1 LOOKS LIKE THIS:
    R1=0
    R2=0
    R3=0
    R4=0

    'THE OUTPUT OF B2 LOOKS LIKE THIS:
    R5=0
    R6=1
    R7=1
    R8=0

    'AND SO ON BUT THE PROBLEM IS THAT I HAVE TO SCAN 16 DIFFERENT SIGNALS AND IF THERE WAS A WAY TO SAY SOMETHING LIKE

    B1,B2,B3,B4=R1 THAT WOULD BE GREAT. SO, R1 EQUALS 8 AND B1=0, B2=0, B3=0 AND B4=1. IS THIS POSSIBLE?




    'I HAVE TO WRITE MY CODE LIKE THIS

    IF B1=1 THEN

  2. #2
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    I re-read what I wrote and it may be a bit confusing. Here is the short story:

    b=7 now I need to extrapolate to binary


    r1=1
    r2=1
    r3=1
    r4=0


    If it's still not clear, let me know.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    maybe i don't understand what you need but lets assume
    B1= 11110000 bin => F0 hex => 240 decimal
    B2=00001111 bin => 0F hex => 15 decimal

    even if you define
    B1=$F0
    OR
    B1=%11110000
    OR
    B1=240

    It do the same thing.

    IF B1=$F0 then....
    IF b1=%11110000 then ....
    IF B1=240 then .....

    Maybe i need to sleep, or it's really what you need
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    HONK! i think i got it.

    Let's say B1=%11110000

    R0 should be Bit 0 of B1, R7 should be Bit7 of B1... i'm i right?
    If so...
    R0=B1.0
    R1=B1.1
    R2=B1.2
    R3=B1.3
    ..
    ...
    R7=B1.7
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default I think it will work!

    Steve,

    You solved another one of my problems! Yes, to answer your question, I want to have a decimal number and convert that to binary. In that binary number, take each bit and it represents another number. So, within one number I extract 8 different boolean numbers. I'll try your suggestion but I do think it will work.

    Thanks,

    Chris

  6. #6
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    I see one small issue.


    For example, I know that b1=9 which is 00001011.

    If b1=9 (the decimal number), how can I let PBP know that it is actually 00001011 (the binary number).

    Or, can I simply go

    R0=B1.0
    R1=B1.1
    R2=B1.2
    R3=B1.3

Similar Threads

  1. PIC16F690 ADC question
    By matador29b in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd October 2009, 23:03
  2. Motor Control PLC with a PIC
    By sougata in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 2nd November 2006, 07:59
  3. Serial Communication again but easier i think ;)
    By Armando Herjim in forum Serial
    Replies: 0
    Last Post: - 21st June 2006, 02:50
  4. Clock connection to DS1802 from 16F877A
    By coyotegd in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd January 2006, 18:52
  5. More IF_THEN dumb questions.
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 22nd February 2005, 19:33

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