It is currently 22 Apr 2018 13:31

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 26 May 2017 08:32 
Offline

Joined: 26 May 2017 08:23
Posts: 5
Using mikroPascal PRO for PIC Ver 7.1.0

Trying to use a variable to index a const array and it doesn't work whereas using
a constant as the index works fine ? Very strange.

Example:

const ZZ : array[1..12] of real = (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);

procedure ZZ_Out;
var
I :integer;
txt :array[23] of char;
begin
I := 2;
// Access the array with a variable "I".
FloatToStr_FixLen(ZZ[I], txt, 6);
UART1_Write_Text(txt); // Outputs "0.0000" <-- not in the array at all

// Access the array with a constant "2".
FloatToStr_FixLen(ZZ[2], txt, 6);
UART1_Write_Text(txt); // Outputs "2.0000" <-- correct array item
end;


Top
 Profile  
 
PostPosted: 26 May 2017 10:02 
Offline
mikroElektronika team
User avatar

Joined: 15 Jan 2016 12:50
Posts: 1717
Hi,

Welcome to the MikroE forum.

I'm sorry, but I couldn't reproduce the same behavior,
in both cases printed values were the same.

I have also tried to pass through all array with
index variable and it was working.

But I have tried your code with PIC18F45K22, which MCU are you using?

Kind regards,
Lana


Top
 Profile  
 
PostPosted: 26 May 2017 16:57 
Offline

Joined: 26 May 2017 08:23
Posts: 5
I'm using a PIC18F26K40


Top
 Profile  
 
PostPosted: 29 May 2017 14:03 
Offline
mikroElektronika team
User avatar

Joined: 15 Jan 2016 12:50
Posts: 1717
Hi,

I'm sorry because of this inconvenience,
I have forwarded this issue to our developers.

Meanwhile, you can set at the beginning of the program
NVMREG bits, you can try:

program UART;

const ZZ : array[1..12] of real = (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);

procedure ZZ_Out;
    var
    I :integer;
    txt :array[23] of char;
    begin
    I := 2;
    FloatToStr_FixLen(ZZ[I], txt, 6);
    UART1_Write_Text(txt); // Outputs "2.0000"
    UART1_Write(13);
    UART1_Write(10);

    // Access the array with a constant "2".
    FloatToStr_FixLen(ZZ[2], txt, 6);
    UART1_Write_Text(txt); // Outputs "2.0000" <-- correct array item
    UART1_Write(13);
    UART1_Write(10);
end;

begin
    NVMREG0_bit := 0;
    NVMREG1_bit := 1;
    ANSELC := 0;                              // Configure PORTC pins as digital

    UART1_Init(9600);
    delay_ms(100);
    ZZ_Out;
end.


Kind regards,
Lana


Top
 Profile  
 
PostPosted: 30 May 2017 05:36 
Offline

Joined: 26 May 2017 08:23
Posts: 5
Thanks so much Lana :D

The "NVMREG0_bit" fix did the trick.
Array access is working fine now.

In addition, it also solved a problem I was having with
the ByteToHex and LongWordToHex functions. They were
writing blanks into the associated txt array instead of
filling it with hex characters. They're working normally now.

Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: