News:

Let's find out together what makes a PIC Tick!

Main Menu

Variable as Code, may not be addressable?

Started by keytapper, Jul 31, 2022, 11:14 AM

Previous topic - Next topic

keytapper

I was trying something that a the first compiling didn't give any glitch (like line 17 in following example).
But if I try to get data out of a flash array (like line 16), perhaps I'm completely out of the path.
Device = 16F887
Xtal   20
' LCD assignment
Declare LCD_DTPort PORTB
Declare LCD_Interface 4
Declare LCD_RSPin PORTB.2
Declare LCD_ENPin PORTB.3
Declare LCD_Lines 2

Dim myCode As Code = As Byte 56,88,104,112
Dim var1 As Byte                    ' temporary variable
Dim dummy As Byte

Cls
For var1 = 0 To SizeOf myCode
'   dummy =  mycode[var1]
    dummy = dummy | mycode[var1]
    Print At 1,1, Dec dummy
Next var1
This example would demonstrate that the ORed variable will not issue an error, but the commented line will.
For the OR case the address of the first variable is given and read, as we may see on the assembled result, but if it's expected to add an indexing I think that it should take a different approach, like a lookup table will.
Error at Line [16]      In file [X:\\test.Bas]  *** Unrecognised, Illegal or Unresolvable characters found ' [VAR1] '! ***
Ignorance comes with a cost

top204

To read from flash memory tables, use the CReadX or PtrX commands.

They are not arrays, so they cannot be accessed directly. They are a different, and better, method of implementing flash memory tables instead of CData.

keytapper

OK, accepted this fact. So I putted a Lread instead of the indexing, the resulting difference for the assembler is very little, maybe the index addition can be made under the hood by the compiler. The only thing is to know the size of the variable, whether is a byte or a different cast.

Anyway, I'm glad for the point, then I could fix my source.
Ignorance comes with a cost