Define a varaible as a port or pin - input/output

Post your requests and ideas on the future development of mikroPascal.
Post Reply
Author
Message
GVHecke
Posts: 77
Joined: 28 May 2005 09:42
Location: Belgium

Define a varaible as a port or pin - input/output

#1 Post by GVHecke » 10 Jan 2007 08:00

The ability to to defeine a varaible as a port? So that one can work with logical names in the code instead of working with ports and pins in all of the code?

For example, something ike this:

....
var
MyVar1 : PORTB;
MyVar2 : PORTC.1;
begin
....
end;

As discussed in topic: http://www.mikroe.com/forum/viewtopic.php?p=44155#44155

MustardMan
Posts: 23
Joined: 04 Jul 2006 03:47

#2 Post by MustardMan » 20 Feb 2007 06:45

Perhaps 'variable' is not the correct word, as you can alter the contents of a variable at run time.
eg: AutoclaveTemperature := PORTA.0
and later on in the code...
AutoclaveTemperature := PORTA.1

Do you mean 'constant'... ?
AutoclaveTemperature = PORTA.0

Or do you really mean 'define' (such as done with embeddedC)...
#define AutoclaveTemperature PORTA.0

Defines are much easier to understand, and deal with. However, I can't get this sort of thing to work in mikroPascal.

MM

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

#3 Post by zristic » 20 Feb 2007 09:07

MustardMan wrote:Defines are much easier to understand, and deal with. However, I can't get this sort of thing to work in mikroPascal.
Defines work in Pascal in different way. However, we work on extending the define directive in order that you can use it to make aliases, as GVHecke wished.
ANSI C, for example, has the define directive which can be used for aliases. We will extend mikroPascal (and mikroBasic) to support this language structure too.

GVHecke
Posts: 77
Joined: 28 May 2005 09:42
Location: Belgium

#4 Post by GVHecke » 20 Feb 2007 10:51

Actually both should be possible, variable and constant.

Constant should be used if you only need to read the value from the port.
Variable should be used when you do not only want to read the value from the port but also need to change the value of it.

For example:
========
procedure Test( const Key: PORTA );
procedure Test( var Key: PORTA );

An example where these can be usefulle. Say you need to design a menu on the screen and you have an up, down, select and cancel button. You give the menu items to the function, together with the up, down, cancel and select key. In this way it would be much more handy to design menus since you would be able to pass all information to one general function that returns the result for the drwan menu. --> Button handling in menu function and if an item is selected, this is returned by the function what needs to be done.

MustardMan
Posts: 23
Joined: 04 Jul 2006 03:47

#5 Post by MustardMan » 21 Feb 2007 02:55

@zristic

I really look forward to that feature!

It is extremely useful for setting up I/O (and other things) for a particular device, such that the code is "easily" ported to another device, or even the same device with different pinouts (eg: develop on a 40 pin DIP for a final device of 44 pin QFP).

I.E. what embedded programmers have been doing for years - I thought it would have been one of the first things implemented!!

Cheers, and thanks for the reply (wasn't really expecting one!)
MM

GVHecke
Posts: 77
Joined: 28 May 2005 09:42
Location: Belgium

#6 Post by GVHecke » 21 Feb 2007 13:57

You are welcome for the reply and indeed I hope as well that this feature will be implemented very soon, because this is indeed not a nice to have feature, but a really basic NEEDED one.

This would indeed make it possible to more easily create libraties. And they should do this for a complete port and for the individual pins of the port.

The more repies we get n this item, the more people ask for it and the more I can hope we can motivate MP to implement this feature.

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

#7 Post by zristic » 21 Feb 2007 14:38

GVHecke wrote:I can hope we can motivate MP to implement this feature.
It is not about he motivation, it is about the lack of time.
We will give our best to implement it in the new release, but I cannot promise for sure.

GVHecke
Posts: 77
Joined: 28 May 2005 09:42
Location: Belgium

#8 Post by GVHecke » 21 Feb 2007 15:45

I understand, let me rephrase then> I never said there was a lack of motivation. Maybe a problem literally translated from dutch.

To motivate someone to do something in Dutch means that you try to have him do something.

So I hope ME will find the time to implement this. Like I said before, I think this is a fundamental item. I would really love this is MikroPascal (and for the users of C and basis, in their development environment as well). This is not a nice to have, but really a MUST have.

This would really easen the life of every MikroPascal developer. This would give us the aibility to make real reusable code.

Neil
Posts: 10
Joined: 10 Dec 2006 20:43
Location: South Africa

Symbols in BASIC workaround

#9 Post by Neil » 09 Sep 2007 09:22

See My other post for a workaround. Very Simple

http://www.mikroe.com/forum/viewtopic.p ... 73faa95e52

Hope this Helps

Neil

GVHecke
Posts: 77
Joined: 28 May 2005 09:42
Location: Belgium

#10 Post by GVHecke » 04 Oct 2007 08:48

This is a work around to be able to assig a variable for a port. But still you will have something like Myvar, which wil represent the port, so basically nothing has changed.

What I want to do for example is pass a port as a variable in a function or procedure. So that I am able to write port independent code. If you have multiple inputs (each a port for axample) and each imput is electrocally the same, this could be very handy.

for example:

function IsStateOK( const PortToCheck: Port ) : boolean;
procedure UpdateState( const PortIn: Port; var PortOut : Port ) : boolean;


The same applies also por fpins of a port:

function IsStateOK( const PortToCheck: PortPin ) : boolean;
procedure UpdateState( const PortIn: PortPin; var PortOut : PortPin ) : boolean;

Post Reply

Return to “mikroPascal Wish List”