There has to be an easier way!


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Chris,
    I think you are missing the point of exactly how PB and the PIC store any variable. When a variable is stored, it is stored as a binary number in a byte-wide file register.
    Simple example:

    Code:
    B1  VAR  BYTE
    B1 = 172
    Now, this is oversimplified, but this is what is happening. The compiler :
    1)Allocates a register in memory for B1
    2)Generates Assemby code to Store "10101100" in that register
    3)Remembers that any time you reference that variable again, it will actually be referencing the allocated register, and the value therein.


    Now, lets add some more code:
    Code:
    R0  VAR  BIT
    R1  VAR  BIT
    '...
    R7 VAR BIT
    
    R0 = B1.0
    R1 = B1.1
    '...
    R7 = B1.7
    Now the compiler looks for a specific bit in the file register for B1, and assigns the value of that bit to the variable.

    That Help?

    Steve

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


    Did you find this post helpful? Yes | No

    Default

    Actually, Steve (Mister e) understood what I was referring to. Here is the long story. I have a 16F870 monitoring 16 inputs and I am sending the status of all inputs wirelessly to a 18F4550. Then, the 18F4550 outputs the status through USB into VB6. Anyway, because of my limitation in PBP, I can't send word variables wirelessly so I am sending 4 bytes which covers the 16 inputs. On the transmitter side, my code looks like this...it's a portion of the code...and don't forget, it may not be efficient because I am not very proficient in PBP.

    if PORTA.5=0 THEN
    B1=0
    ELSE
    B1=1
    ENDIF
    if PORTA.2=0 THEN
    B2=0
    ELSE
    B2=1
    ENDIF
    if PORTA.1=0 THEN
    B3=0
    ELSE
    B3=1
    ENDIF
    if PORTA.0=0 THEN
    B4=0
    ELSE
    B4=1
    ENDIF
    C1=(B1*1)+(B2*2)+(B3*4)+(B4*8)

    This was the easy part. One the receiver side, it looks like this:

    in1=c1.0
    in2=c1.1
    in3=c1.2
    in4=c1.3

    And then from here it sends the data to VB6. I wasn't aware that PBP stored the numbers as binary and that is where my confusion was. When sending the numbers over the data link, it is simply sent as (C1=9) or (C1=15), not (c1=%00001011). Furthermore, I never knew that you can use a c1.0 or c1.3 to take a portion of the number.

    Previously, I was sending 4 bytes for each specific number so it was taking 96 bytes (when you include the start and end bit) to update all 16 inputs. Now, it only takes 6 bytes to send that data.

    Thanks to all who helped.

    Chris

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Wink Think simple ...

    Quote Originally Posted by Christopher4187


    if PORTA.5=0 THEN
    B1=0
    ELSE
    B1=1
    ENDIF
    if PORTA.2=0 THEN
    B2=0
    ELSE
    B2=1
    ENDIF
    if PORTA.1=0 THEN
    B3=0
    ELSE
    B3=1
    ENDIF
    if PORTA.0=0 THEN
    B4=0
    ELSE
    B4=1
    ENDIF
    C1=(B1*1)+(B2*2)+(B3*4)+(B4*8)

    Chris
    > Hi, Christopher

    > Let's do :

    > C1 = PORTA & % 00100111
    > C1.3 = C1.5 : C1.5 = 0
    > C1 = C1 REV 4

    That's all !!!

    See manual $ 4.10 and 4.17.11 ...

    Alain
    Last edited by Acetronics2; - 27th May 2006 at 12:40.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Another Option - although more lines of code, this compiles to less code space -

    temp var byte
    C1 var byte

    C1=0 ; set C1 to 0
    temp=PORTA ; in case PORTA changes while “processing”
    C1.0=temp.5
    C1.1=temp.2
    C1.2=temp.1
    C1.3=temp.0

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    or this

    temp var byte
    C1 var byte

    C1=0 ; set C1 to 0
    temp=PORTA ; in case PORTA changes while “processing”
    if temp.5=1 then C1.0=1
    if temp.2=1 then C1.1=1
    if temp.1=1 then C1.2=1
    if temp.0=1 then C1.3=1

    Paul

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