I had to go over to ANSI mode with my CCS (PCH) compiler. This was because the default compiler uses case insensitive approach on object names.
After enabling the ANSI compiler I noticed that the "const" keyword no more meant "put this variable into program memory" but they were put into RAM instead. LOL - my puny PIC18F25K22 MCU did not have enough RAM ...
The solution was to apply another pragma:
#DEVICE CONST=ROM
After this the "const" variables went to ROM.. Thank You
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Sun Nov 27, 2016 7:55 pm
If you want to make the compiler case sensitive, you don't need ANSI.
Just use #case. It's in the manual.
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
Posted: Mon Nov 28, 2016 1:46 am
and the use of 'const' has also been covered many times before here.
CCS used the keyword 'const' to signify a variable held in ROM long before ANSI existed. When ANSI was designed, the same word was instead used to signify a RAM variable that was not changeable by the code. Now the PIC doesn't actually have the protections to do this, but the compiler will try to implement parts of this.
In fact #DEVICE CONST=ROM does not do quite the same as the old compiler. Quote from the readme that comes with the compilers:
Quote:
The CCS compilers traditionaly used the C keyword CONST to locate data in program memory.
ANSI uses this keyword to specify a read only data item. The version 4 compiler has a
new method of storing data in program memory for chips that allow program memory to be read.
These three storage modes may be set directly using one of the following qualifiers:
ROMI Traditional CCS method to store in ROM optimized for access from indexed arrays
ROM New method to save data in ROM optimized for when the user needs pointers to the data
_READONLY Marks the data item as read only, defaults to RAM (like ANSI wants)
By default the CONST keyword is the same as ROMI. The CONST behavior may be changed with
any of the following:
#device CONST=READ_ONLY
#device CONST=ROM
#device CONST=ROMI
So to give the same behaviour as you had without #DEVICE ANSI, you should actually use #device CONST=ROMI
Changing to ANSI also changes the default data type to 'signed'. Beware.
#device ANSI gives the following basic changes:
#device CONST=READ_ONLY
#type signed
#case
#device *=16 //You are probably running this anyway
esko
Joined: 17 Nov 2016 Posts: 12
Posted: Tue Nov 29, 2016 5:34 pm
Thanks for Your valuable time. It was well spent !
Added the 'I' to the pragma.
I am aware of the highest bit
Actually I have been coding with C so long .... practically as long as there has been C compilers around - I even coded one myself for Hitachi's Motorola 6802 clone which did not have a decent compiler at early 80's - That compiler ran on a Motorola Exorset .... and the code was tested on Motorola MEK-6802-D5...
Edit: and as there were no C compilers around I coded the C compiler with assembler. Bought my first IBM XT 5 years later.... it had a BASIC interpreter
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 vote in polls in this forum