Help Needed with arrays


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Posts
    1

    Default Help Needed with arrays

    Hi i need help to set up an array of 26 bits and cycle through them like:

    arrayadat = %1010101011111111000000001 - this obviosley causes a overflow error, The Max Possible seems to be 16bits (Word ???)
    I've tried breaking it down into 3 seperate Bytes and 2 bits but then i fail on the bad token thing below.

    I have tried Defineing it as : arraydat VAR Bit(26), and as a Word,

    For C = 0 to 25
    IF arraydat.(C) = 1 then <-----This gives a bad token,
    Gosub ONE
    Else
    Gosub Zero
    EndIf
    Next C
    Any help would be appriciated, Its been a while since i've used pbp so i'm a little dusty. I seem to remember getting somthing similar to this working some time ago. I'm using PBP 2.60 with a PIC 16F877A @20Mhz

    Many thanks Chris

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

    Default Re: Help Needed with arrays

    Hi Chris,
    Have you read Melanies excellent primer on the subject?

    Basically like you have it but IF arraydat.0(C) = 1 then....

    /Henrik.

  3. #3
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Help Needed with arrays

    Chris

    The following compiles OK

    Norm
    Code:
      '4520
      @ __CONFIG _CONFIG1H, _OSC_XT_1H
      @ __CONFIG _CONFIG2L, _BOREN_ON_2L
      @ __CONFIG _CONFIG2H, _WDT_ON_2H
      @ __CONFIG _CONFIG3H, _MCLRE_ON_3H & _PBADEN_OFF_3H
      @ __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    
      DEFINE OSC 4
    
      CLEAR
      sSEROUT_PIN VAR PORTC.1
      sBAUD CON 19697  '3313 = INVERTED 300   USE 19697 = 300   16416 = 19200 BAUD
    
      arraydat VAR BIT(26)
      C VAR BYTE
      '***********************************************
      GOTO START
    
      ONE:
      SEROUT2 sSEROUT_PIN,sBAUD,["sub ONE",13]
      RETURN
    
      ZERO:
      SEROUT2 sSEROUT_PIN,sBAUD,["sub ZERO",13]
      RETURN
    
      START:
      PAUSE 1000
    
      SerOut2 sSEROUT_PIN,sBAUD,["START",13]
      PAUSE 100
    
      MAIN:
    '  arrayadat = %01010101011111111000000001
      arraydat[0] = 1
      arraydat[1] = 0
      arraydat[2] = 0
      arraydat[3] = 0
      arraydat[4] = 0
      arraydat[5] = 0
      arraydat[6] = 0
      arraydat[7] = 0
      arraydat[8] = 0
      arraydat[9] = 1
      arraydat[10] = 1
      arraydat[11] = 1
      arraydat[12] = 1
      arraydat[13] = 1
      arraydat[14] = 1
      arraydat[15] = 1
      arraydat[16] = 1
      arraydat[17] = 0
      arraydat[18] = 1
      arraydat[19] = 0
      arraydat[20] = 1
      arraydat[21] = 0
      arraydat[22] = 1
      arraydat[23] = 0
      arraydat[24] = 1
      arraydat[25] = 0
    
      FOR C = 0 TO 25
        IF arraydat[C] = 1 THEN
          Gosub ONE
        Else
          Gosub Zero
        EndIf
      NEXT C
    
    '  goto main
      SEROUT2 sSEROUT_PIN,sBAUD,["END",13]
      END

Similar Threads

  1. Arrays calling Arrays
    By MOUNTAIN747 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th January 2011, 06:15
  2. Two dimensional arrays?
    By ralfmayr in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th March 2010, 17:41
  3. How are arrays used?
    By NO2K in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st June 2007, 15:33
  4. pins in arrays?
    By scorpion in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th September 2005, 08:18
  5. storing arrays and reading arrays
    By Yue in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 5th March 2004, 22:03

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