Constants in Flash

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Constants in Flash

#1 Post by arco » 27 Apr 2020 12:15

At the moment I use a 16F1709. I want to define a constant in flash memory on a designated position.
The compiler only allows defining a byte constant and then cripples it by adding 0x34.. in front of it...
How do I use the full 14 bits as constant value?
(I now have to edit the hexfile manually; an annoying job...)

Code: Select all

Const MyConst As Byte[1] = (0xAA) Org 0x1FFF
This gives 0x34AA in stead of 0x00AA...
Last edited by arco on 16 Oct 2020 12:42, edited 1 time in total.
Regards,

Peter.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Constant in Flash

#2 Post by filip » 04 May 2020 07:57

Hi,

The PIC16F has only readable ROM, so the compiler inserts 0x34 in front of each byte, which is RETWL that returns the value into W register.

Regards,
Filip.

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Re: Constant in Flash

#3 Post by arco » 04 May 2020 10:06

Modern 16F's can read/write flash, so it would be a big advantage if all 14 bits could be used. (the RETLW has no use at all in this case)
As said: editing the hexfile everytime is quite annoying...
Regards,

Peter.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Constant in Flash

#4 Post by filip » 05 May 2020 06:58

Hi,

We are using this approach according to the datasheet, chapter 3.2.1 READING PROGRAM MEMORY AS DATA - RETLW Instruction.

Also, there is another approach suggested - Indirect Read with FSR, but we implemented the first one.

Regards,
Filip.

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Re: Constant in Flash

#5 Post by arco » 16 Oct 2020 08:58

Still no solution for entering full 14 bits in flash constants. I *NEED* that functionality.
Even in simple assembly it's no problem (DW directive), so how do I do it in Mikrobasic???

Assembly directives like ORG, DATA and DW don't seem to be allowed inline.
Not sure because there is no help in the helpfile for assembly.
(asked for that years and years ago. Only help is how to use ASM/END ASM)

So how do I enter a 14 bit value into flash at compile time?
How do I create a 'real' contants word array without half of it being filled with useless 0x34???
A word now is needlessly spread across 2 flash words doubling the used memory.
(and I use large constants tables and so also waste a lot of memory)

Is there a way to store 'raw' data in flash?
(I can't imagine I have to write my own software to edit the hexfile after compile to do the most basic things???)
Regards,

Peter.

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Re: Constants in Flash

#6 Post by arco » 17 Oct 2020 10:31

There also is a bug in the compiler, the 'Used rom' info is incorrect sometimes.
If I use:

Code: Select all

  Const MyConst As Byte[100] = (1,2,3,...99,100)
then used rom count is + 100 words as expected. If I use:

Code: Select all

  Const MyConst As Byte[100] = (1,2,3,...99,100) Org 0x1000
then used rom count doesn't change at all???

Seems that the compiler is confused by the ORG directive...
Regards,

Peter.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Constants in Flash

#7 Post by janni » 17 Oct 2020 14:29

You need to use the array in code or linker may omit it. Something like this convinces linker that the array is needed without producing any code:
Lo(MyConst[0])

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Re: Constants in Flash

#8 Post by arco » 17 Oct 2020 14:49

janni wrote:
17 Oct 2020 14:29
You need to use the array in code or linker may omit it. Something like this convinces linker that the array is needed without producing any code:
Lo(MyConst[0])
I know... (also very irritating... :( )
But regardless, constants arrays with org directive are not counted with used rom or statistics.

It would be nice if the compiler didn't strip anything from the sourcecode if you choose Optimization level 0.
(just compile 'as is')
At least leave declared constants at fixed positions alone, because that's never done without a reason.

I find it also very annoying that you can't write a 'raw' 14 bit value to a flash location...
(the compiler always adds a useless RETLW/0x34 and splits it up in 2 words...)
I now have a lot of extra work editing the hexfile after compile.
Regards,

Peter.

Post Reply

Return to “mikroBasic PRO for PIC General”