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
Define a varaible as a port or pin - input/output
-
- Posts: 23
- Joined: 04 Jul 2006 03:47
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
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
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.MustardMan wrote:Defines are much easier to understand, and deal with. However, I can't get this sort of thing to work in mikroPascal.
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.
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.
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.
-
- Posts: 23
- Joined: 04 Jul 2006 03:47
@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
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
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.
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.
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.
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.
Symbols in BASIC workaround
See My other post for a workaround. Very Simple
http://www.mikroe.com/forum/viewtopic.p ... 73faa95e52
Hope this Helps
Neil
http://www.mikroe.com/forum/viewtopic.p ... 73faa95e52
Hope this Helps
Neil
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;
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;