Hi,
it's good coding practice to hide hardware details, for example using a constant like "KeypadPort" instead of "PortC" to get reusable code where hardware details can be mapped at one point instead of doing search-n-replace in all units if hardware changes for some reason.
const
KeypadPort = PortC;
gives a "Syntax error". What is the correct syntax in mikroPascal 4.0.0.0 ?
How to map hardware details?
How to map hardware details?
Regards Frank
Re: How to map hardware details?
I am afraid such language structure is not defined in Pascal. We are working on finding a solution for this, even for the price of extending the Pascal standard. If you have some suggestions, you are welcome to introduce them here.
Well, it shouldn't be too difficult. As far as I can see in your hardware definition files (ATmegaXX.apas), there are two cases to handle:
1.) Constant declarations like
PORTC0 = 0; // Port C Data Register bit 0
IMHO there is no violation in Pascal language definition if the compiler assigns "MyPortName = PORTC0;" within constant declaration, because it's an assignment of a constant to a constant. This was even possible in one of the first Pascal compilers written by Ammann, Nori and Jacobi at the Eidg. Technische Hochschule CH-8096 Zuerich in the early days of micro computers.
2.) Variable declarations like
PORTC: byte; absolute 0x28; volatile; register;
BTW: The keywords "absolute, volatile and register" aren't listed in your "mikroPascal Quick Reference Guide".
In this case language definitions _are violated_ if PORTC would be used within a constant declaration. In modern compilers on personal computers this may be handled by a construct like
const
MyPortName : PortType = PORTC;
but as I'm just starting to evaluate your compiler, I'm not in the position to suggest the best way to implement this case. It would be interesting to hear some other opinions...
1.) Constant declarations like
PORTC0 = 0; // Port C Data Register bit 0
IMHO there is no violation in Pascal language definition if the compiler assigns "MyPortName = PORTC0;" within constant declaration, because it's an assignment of a constant to a constant. This was even possible in one of the first Pascal compilers written by Ammann, Nori and Jacobi at the Eidg. Technische Hochschule CH-8096 Zuerich in the early days of micro computers.
2.) Variable declarations like
PORTC: byte; absolute 0x28; volatile; register;
BTW: The keywords "absolute, volatile and register" aren't listed in your "mikroPascal Quick Reference Guide".
In this case language definitions _are violated_ if PORTC would be used within a constant declaration. In modern compilers on personal computers this may be handled by a construct like
const
MyPortName : PortType = PORTC;
but as I'm just starting to evaluate your compiler, I'm not in the position to suggest the best way to implement this case. It would be interesting to hear some other opinions...
Regards Frank
-
- Posts: 100
- Joined: 10 Nov 2005 16:37
- Location: APAC
Hi Frank,
This gets brought up on the PIC forum every now and then, too. The current solutions, until there is an official one, are, as you noted, use a constant with the absolute, register, volatile qualifiers, or use a pointer (@MyPort). In addition, using a constant for the bit, makes the code even more readable and portable (LCD_CTL.STROBE) within the current architecture.
Cheers, -ch
This gets brought up on the PIC forum every now and then, too. The current solutions, until there is an official one, are, as you noted, use a constant with the absolute, register, volatile qualifiers, or use a pointer (@MyPort). In addition, using a constant for the bit, makes the code even more readable and portable (LCD_CTL.STROBE) within the current architecture.
Cheers, -ch