Complex type to simple type error in array extraction

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
dangerous
Posts: 748
Joined: 08 Mar 2005 16:06
Location: Nottinghamshire, UK

Complex type to simple type error in array extraction

#1 Post by dangerous » 25 Oct 2017 13:17

Hello,

In am trying to write a series of bytes to an EEprom, so I need to extract a single byte at a time from an array.

As an example I am trying to use the code below:

Code: Select all

typedef str as char[64]
Const DStor as str [64] = ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!£"")
Const E_addr = 0xA0           '24C08 base address.

dim L_add, H_add,             'sub addresses
    d_cnt,                    'position counter
    b_cnt,                    'byte counter
    I2_Add                    'actual address byte to send
      as byte
'dim Dstor as str[64]
      
      
Sub function Get_add() as byte
    'returns Base address plus hi byte of subaddress shifted left one bit.
     result = (E_addr) OR ((H_add and 0x0F) <<1)
end sub
Sub procedure Send_I2C_dat()
       I2_Add = Get_add()   'gets upper byte of  sub address into I2Caddress
       I2C1_Start()
       I2C1_wr(I2_Add)
       I2C1_WR(L_add)       'start address
       for b_cnt = 0 to 15
 ******  I2C1_wr(Dstor[d_cnt])     'gets data & writes to EEprom ***********
          inc (d_cnt)
       next i
       I2C1_stop()
       do
         nop
       loop until I2C_is_idle() = 1   'wait for write
I get the error "Complex type to Simple type" at the line starred above ******. (d_cnt is declared elsewhere, and simply counts the position in the array. B_cnt counts 16 bits for a page write.

I have tried declaring the data as Char and string but get the same error.
I have tried making the Dstor a variable and loading it with the same string.



The manual suggests that this is OK:
dim s as string[5]
' ...
s = "mik"
' s[0] is char literal "m"
' s[1] is char literal "i"
' s[2] is char literal "k"
' s[3] is zero
' s[4] is undefined
' s[5] is undefined

but I seem unable to get a specific character from the array to write.

Any help would be appreciated.

dangerous
Posts: 748
Joined: 08 Mar 2005 16:06
Location: Nottinghamshire, UK

Re: Complex type to simple type error in array extraction

#2 Post by dangerous » 25 Oct 2017 14:38

May have answered my own problem.

By changing the array to:

Code: Select all

Const DStor as Char[64] = ("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F",
                           "G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V",
                           "W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l",
                           "m","n","o","p","q","r","s","t","u","v","w","x","y","z","!","£")
it now complies.
Presumably as I2C1_wr needs a byte not a char to write.
Wears the fingers out doing the "X",............... bit 64 times

Post Reply

Return to “mikroBasic PRO for AVR General”