Strange const behavior

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Strange const behavior

#1 Post by LGR » 21 Nov 2011 22:03

I'm working on an ST7565 project, that I intend to put on Libstock when I'm done. In order to keep it readable, I want to be able to declare a constant array of byte thusly:

Code: Select all

const  // Opcodes

V0Ratio             : byte = 0x20; // Add 0-7 for different values
EVRegSet            : byte = 0x00; // Add 0-63 for different contrasts
BoosterRatioReg2X4X : byte = 0x00; // Use in conjunction with BoosterRatioMode
BoosterRatioReg5X   : byte = 0x01; // Use in conjunction with BoosterRatioMode
BoosterRatioReg6X   : byte = 0x03; // Use in conjunction with BoosterRatioMode
ColumnAdressSet     : byte = 0x10; // To create...
BoffVRoffVFoff      : byte = 0x20; // Power controller settings
BoffVRoffVFon       : byte = 0x21;
BoffVRonVFoff       : byte = 0x22;
BoffVRonVFon        : byte = 0x23;
BonVRoffVFoff       : byte = 0x24;
BonVRoffVFon        : byte = 0x25;
BonVRonVFoff        : byte = 0x26;
BonVRonVFon         : byte = 0x27;
DisplayStartLineSet : byte = 0x40; // Arithmetically add line number to this
EVModeSet           : byte = 0x81;
ADCSelectNormal     : byte = 0xA0;
ADCSelectReverse    : byte = 0xA1;
LCDBiasSet1         : byte = 0xA2; // See ST7565R manual
LCDBiasSet2         : byte = 0xA3;
AllPixOn            : byte = 0xA4;
AllPixOff           : byte = 0xA5;
DisplayNormal       : byte = 0xA6;
DisplayReverse      : byte = 0xA7;    
CMDDispOff          : byte = 0xAE;
CMDDispOn           : byte = 0xAF;
PageAdressSet       : byte = 0xB0; // Arithmetically add page number to this
CommonOutModeSel1   : byte = 0xC0;
CommonOutModeSel2   : byte = 0xC8;
ReadModifyWrite     : byte = 0xE0; // See RMW command, and how it works with
ENDlcd              : byte = 0xEE; // END command
Resetlcd            : byte = 0xE2;
NOP                 : byte = 0xE3;
BoosterRatioMode    : byte = 0xF8;

const displaytech   : array[20] of byte =
(DisplayStartLineSet,
ADCSelectNormal,
CommonOutModeSel2,
DisplayNormal,
LCDBiasSet1, 0x2F,
BoosterRatioMode, 0x00,
BonVRonVFon,
EVModeSet, 0x04,
0xAC,
EVRegSet,
CMDDispOn, 
NOP, NOP, NOP, NOP, NOP, NOP);
The last declaration (displaytech) doesn't compile. The compiler says that there are too many arguments. I count 20. Am I missing something?
If you know what you're doing, you're not learning anything.

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

Re: Strange const behavior

#2 Post by filip » 22 Nov 2011 11:35

Hi,

The NOP is a built-in identifier, associated to asm nop, and therefore it shouldn't be used as an identifier name.
The compiler also shouldn't allow the constant declaration with NOP being constant identifier, which we will fix.

Regards,
Filip.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Strange const behavior

#3 Post by LGR » 22 Nov 2011 17:43

That fixed it. Is there an easy way to get a list of all reserved identifiers for a given chip?
If you know what you're doing, you're not learning anything.

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

Re: Strange const behavior

#4 Post by janni » 22 Nov 2011 18:12

Those are declared in definition *.mpas file for a given processor.
There's also a list of reserved keywords in Help. NOP is not present there as it's a routine - unfortunately it's also omitted in built-in routines list.

When in doubt, one may always invoke Code Assistant to check whether an identifier is not already used (place cursor on doubted identifier and press Ctrl+Space).

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Strange const behavior

#5 Post by LGR » 22 Nov 2011 18:27

I noticed that certain built-in routines that are simple ASM commands (such as RESET) aren't documented. All of these should be listed in the documentation under built-in commands.
If you know what you're doing, you're not learning anything.

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

Re: Strange const behavior

#6 Post by janni » 22 Nov 2011 19:31

Actually, RESET and Clrwdt are listed in built-in routines, only NOP somehow got lost.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Strange const behavior

#7 Post by LGR » 22 Nov 2011 19:48

And of course, NOP is also an instruction for the ST7565. So we have yet another potential type of conflict. This is why I decided that ALL variables in this library will start with "ST". Now watch this conflict with some device made by ST (which the ST7565 isn't).

I already had a conflict with "WR" as a name for a pin. :evil:
If you know what you're doing, you're not learning anything.

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

Re: Strange const behavior

#8 Post by filip » 23 Nov 2011 11:09

Hi,

Thank you janni for this suggestion, we will add it to the Help file.

Regards,
Filip.

Post Reply

Return to “mikroPascal PRO for PIC32 General”