Array problems

2013-05-10
2013-06-08
  • Jim giordano

    Jim giordano - 2013-05-10

    Arrays look simple enough, but there's something I'm obviously missing.  I took the code right out of the help and tried to print out some elements, but they all come out zero.

    The code:

    Dim TestVar(10)
    TestVar = 1, 2, 3, 4, 5, 6, 7, 8, 9
    tst1 = TestVar(1)
    tst2 = TestVar(2)
    tst3 = TestVar(3)
    

    The results:

    TESTVAR EQU 1479
    ;Dim TestVar(10)
    ;TestVar = 1, 2, 3, 4, 5, 6, 7, 8, 9
        movlw   low TESTVAR
        movwf   FSR0L
        movlw   high TESTVAR
        movwf   FSR0H
    ;tst1 = TestVar(1)
        movlw   low(TESTVAR+1)
        movwf   AFSR0
        movlw   high(TESTVAR+1)
        movwf   AFSR0_H
        movf    INDF0,W
        movwf   TST1
    ;tst2 = TestVar(2)
        movlw   low(TESTVAR+2)
        movwf   AFSR0
        movlw   high(TESTVAR+2)
        movwf   AFSR0_H
        movf    INDF0,W
        movwf   TST2
    ;tst3 = TestVar(3)
        movlw   low(TESTVAR+3)
        movwf   AFSR0
        movlw   high(TESTVAR+3)
        movwf   AFSR0_H
        movf    INDF0,W
        movwf   TST3
    

    What's the secret to getting arrays to work?

     
  • Jim giordano

    Jim giordano - 2013-05-10

    Also, I forgot to mention, I printed out some other variables before and after trying to print out tst1,tst2,and tst3.  The others printed out properly, tst1-3 were all zero.

     
  • Jim giordano

    Jim giordano - 2013-05-14

    Obviously, I didn't provide enough information about the problem, so

    I've narrowed down my problem with arrays.

    If I assemble this program-

    #chip 12F683, 4
    Dim TestVar(5)
    TestVar = 1, 2, 3, 4
    tst2 = TestVar(2)
    

    Then, in the asm file I get-

        ORG 5
    BASPROGRAMSTART
    ;Call initialisation routines
        call    INITSYS
    ;Start of the main program
    ;Dim TestVar(5)
    ;TestVar = 1, 2, 3, 4
        movlw   low TESTVAR
        movwf   FSR
        movlw   4
        movwf   INDF
        incf    FSR,F
        movlw   1
        movwf   INDF
        incf    FSR,F
        movlw   2
        movwf   INDF
        incf    FSR,F
        movlw   3
        movwf   INDF
        incf    FSR,F
        movlw   4
        movwf   INDF
    ;tst2 = TestVar(2)
        movlw   low(TESTVAR+2)
        movwf   FSR
        movf    INDF,W
        movwf   TST2
    

    and everything is good.

    If I change to the chip I am actually working on-

    #chip 16f1939, 4
    Dim TestVar(5)
    TestVar = 1, 2, 3, 4
    tst2 = TestVar(2)
    

    then I get

        ORG 0
        goto    BASPROGRAMSTART
        ORG 4
        retfie
    ;********************************************************************************
    ;Start of program memory page 0
        ORG 5
    BASPROGRAMSTART
    ;Call initialisation routines
        call    INITSYS
    ;Start of the main program
    ;Dim TestVar(5)
    ;TestVar = 1, 2, 3, 4
        movlw   low TESTVAR
        movwf   FSR0L
        movlw   high TESTVAR
        movwf   FSR0H
    ;tst2 = TestVar(2)
        movlw   low(TESTVAR+2)
        movwf   AFSR0
        movlw   high(TESTVAR+2)
        movwf   AFSR0_H
        movf    INDF0,W
        movwf   TST2
    

    As you can see, the array is not initialized with the values as it was in the first program, so something is wrong with the compiler or the 16f1939 chipdata file the compiler uses.

    Trying several chips in the chipdata folder-

    everything I tried in the 16f series worked up to and including 16f946.

    Starting with 16f1454, trying several at random, none seemed to work.

    In other words, anything from this year, (dated 3/25/2013), is not working.

     
  • Jim giordano

    Jim giordano - 2013-05-24

    Bump.    So, has this problem been recognized by someone?   Is it on someone's to do list?  Did I screw up the first post so bad that the problem was misunderstood and being ignored?  Should I try to find what's causing the problem in the compiler myself?  Is anyone out there?

     
  • lhatch

    lhatch - 2013-06-08

    I would have done it this way.

    chip 12F683, 4

    Dim TestVar(5)
    TestVar(1) = 1
    TestVar(2) = 2
    TestVar(3) = 3
    TestVar(4) = 4
    tst2 = TestVar(2)

    or

    for i = 1 to 4
    TestVar(i) = i
    next

    Never tried TestVar and a list of numbers myself.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks