How can I shorten this code - 16 1's and 0's into one number


Results 1 to 4 of 4

Threaded View

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


    Did you find this post helpful? Yes | No

    Default Re: How can I shorten this code - 16 1's and 0's into one number

    This is a little above my level. I see a potential problem but I'm not 100% sure. I think I can only send max word variables so the sendpacket would be 2 word variables, right? This is what my TX side looks like (I put known numbers in there for now so I know what to expect on the receiving end):

    Code:
    SENDPACKET.0[0]=1
    SENDPACKET.0[1]=1
    SENDPACKET.0[2]=1
    SENDPACKET.0[3]=1
    SENDPACKET.0[4]=1
    SENDPACKET.0[5]=0
    SENDPACKET.0[6]=1
    SENDPACKET.0[7]=0
    SENDPACKET.0[8]=1
    SENDPACKET.0[9]=1
    SENDPACKET.0[10]=1
    SENDPACKET.0[11]=1
    SENDPACKET.0[12]=1
    SENDPACKET.0[13]=0
    SENDPACKET.0[14]=1
    SENDPACKET.0[15]=0
    
    sum = SENDPACKET.0[0]+SENDPACKET.0[1]+SENDPACKET.0[2]+SENDPACKET.0[3]+SENDPACKET.0[4]+SENDPACKET.0[5]+SENDPACKET.0[6]+SENDPACKET.0[7]+SENDPACKET.0[8]+SENDPACKET.0[9]+SENDPACKET.0[10]+SENDPACKET.0[11]+SENDPACKET.0[12]+SENDPACKET.0[13]+SENDPACKET.0[14]+SENDPACKET.0[15]
    
    HSEROUT [9,sendpacket,12]
    The RX side looks like this:

    Code:
    IF RCSTA.1 = 1 THEN xfer  'USART overflow error - bad data
      HSERIN 30, xfer, [start1, sendpacket,sum]
      
      IF start1 <> 9 THEN xfer 
      
      datasum = sendpacket 
      IF datasum = sum THEN errorflag = 0   
    
     
    xfer:
    
    
      IF errorflag = 0 THEN
      high led
    
      
      
      
    B1 = SENDPACKET.0[0]
    B2 = SENDPACKET.0[1]
    B3 = SENDPACKET.0[2]
    B4 = SENDPACKET.0[3]
    B5 = SENDPACKET.0[4]
    B6 = SENDPACKET.0[5]
    B7 = SENDPACKET.0[6]
    B8 = SENDPACKET.0[7]
    B1 = SENDPACKET.0[8]
    B2 = SENDPACKET.0[9]
    B3 = SENDPACKET.0[10]
    B4 = SENDPACKET.0[11]
    B5 = SENDPACKET.0[12]
    B6 = SENDPACKET.0[13]
    B7 = SENDPACKET.0[14]
    B8 = SENDPACKET.0[15]
    
    ENDIF
    Last edited by Christopher4187; - 5th July 2012 at 23:23. Reason: Typo

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