Adding values one at a time and sending them serially


Results 1 to 5 of 5

Threaded View

  1. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Adding values one at a time and sending them serially

    Here's another way to do it. Fully tested.
    Code:
    Sens1 Var bit
    Sens2 Var bit
    Sens3 Var bit
    Sens4 Var bit
    Sens5 Var bit
    
    Value VAR WORD
    Idx   VAR BYTE
    Abit  VAR BIT
    
    Value = 0
    FOR Idx = 1 TO 5
        LOOKUP2 Idx-1,[Sens1,Sens2,Sens3,Sens4,Sens5],Abit
        IF Abit THEN Value = Value * 10 + Idx
    NEXT Idx
    Or, if you change the bits to an array similar to what henrik did, you can do this ...
    Code:
    Senser VAR BYTE
    Sens1 Var Senser.0
    Sens2 Var Senser.1
    Sens3 Var Senser.2
    Sens4 Var Senser.3
    Sens5 Var Senser.4
    
    Value VAR WORD
    Idx   VAR BYTE
    
    Value = 0
    FOR Idx = 1 TO 5
        IF Senser.0(Idx-1) THEN Value = Value * 10 + Idx
    NEXT Idx
    Last edited by Darrel Taylor; - 20th August 2013 at 20:59.
    DT

Similar Threads

  1. Why does this PBP statement post the wrong time values?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd November 2011, 04:10
  2. Question about sending data serially
    By FromTheCockpit in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st August 2011, 02:21
  3. Replies: 1
    Last Post: - 4th June 2010, 04:34
  4. Replies: 9
    Last Post: - 8th October 2008, 12:15
  5. it's possible to drive four max7221 serially connected?
    By lutherblissett in forum General
    Replies: 0
    Last Post: - 23rd November 2005, 19:38

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