How to map hardware details?

General discussion on mikroPascal for AVR.
Post Reply
Author
Message
fl
Posts: 11
Joined: 20 Dec 2006 12:21
Location: Germany

How to map hardware details?

#1 Post by fl » 20 Dec 2006 13:03

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 ?
Regards Frank

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: How to map hardware details?

#2 Post by zristic » 20 Dec 2006 13:25

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.

fl
Posts: 11
Joined: 20 Dec 2006 12:21
Location: Germany

#3 Post by fl » 20 Dec 2006 14:12

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...
Regards Frank

coldharbor
Posts: 100
Joined: 10 Nov 2005 16:37
Location: APAC

#4 Post by coldharbor » 23 Dec 2006 07:43

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

Post Reply

Return to “mikroPascal for AVR General”