Problem with Incrementing Array Elements

Discuss about beta versions of mikroBasic
compiler.
Post Reply
Author
Message
xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

Problem with Incrementing Array Elements

#1 Post by xor » 03 Jul 2006 22:58

Using 18F2550 (48MHz) with configs same as HID example, the following code fails in actual PORTB output and in the Debugger. Only the first element of the array increments correctly:

Code: Select all

dim pos as byte
dim _s as byte[8]
main:
  LATA = 0
  LATB = 0
  TRISA = 0
  TRISB = 0
  ADCON1 = 15
  For pos = 0 To 7
    _s[pos] = 255         ' array initalization only
  Next pos
  While true
     For pos = 0 To 7
        LATA = pos
        inc(_s[pos])
        LATB = _s[pos]
        delay_ms(200)
     Next pos
  Wend
end.
Converting the incrementing value to a single variable and re-inserting into the array works:

Code: Select all

dim pos, old as byte
dim _s as byte[8]
  LATA = 0
  LATB = 0
  TRISA = 0
  TRISB = 0
  ADCON1 = 15
  For pos = 0 To 7
    _s[pos] = 255           ' array initialization only
  Next pos
  While true
     For pos = 0 To 7
        LATA = pos
        old = _s[pos]
        inc(old)
        _s[pos] = old
                             ' inc(_s[pos])
        LATB = _s[pos]
        delay_ms(200)
     Next pos
  Wend
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Problem with Incrementing Array Elements

#2 Post by zristic » 04 Jul 2006 07:59

Must be something ugly. We will fix it, thanks.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#3 Post by jpc » 13 Jul 2006 11:39

as i tested the first code as provided by xor on 4013 i encountered a few problems of which one might be serious and not only limited to basic.
First there seems to be a problem with the definition file for 4013 , LATA, TRISA and PORTA are not declared ???
Then , more serious is the fact that at least in debugger something is terribly wrong when using delay , it overwrites the _s[] array , something i found some time ago to happen in Pascal : http://www.mikroe.com/forum/viewtopic.php?t=6014
Needs attention , seems related to delay library

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#4 Post by xor » 13 Jul 2006 11:52

The following compiles fine. It's a form that mB smartly and usually converts to INCF in assembler.

Code: Select all

_s[pos] = _s[pos] + 1              ' inc(_s[pos])
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

Post Reply

Return to “mikroBasic Beta testing”