Page 1 of 1
Names in Button(...)
Posted: 13 Jan 2013 17:35
by Toenne
I'm new in testing MikropascalAVR and as far as I can see there is a way to give pins names:
Code: Select all
var Sw_1 : sbit at PORTC5_bit; // Pin C.5 = Switch1
var Sw_1_Direction : sbit at DDC5_bit; // Pin C.5 = Switch1
...
Sw_1_Direction := 0; // Switch1 = input
Sw_1 := 0; // Sw_1 Pullup activated
Correct so far?
But using the button function I still have to use the pin-# ?
Would be really nice if there is a possibility to use the previously declared names for the button function too...or did I miss something?
Best regards
Toenne
Re: Names in Button(...)
Posted: 14 Jan 2013 11:29
by filip
Hi,
The Button routine can passed as a pin argument, so I suggest you using #define for this purpose, like this :
Regards,
Filip.
Re: Names in Button(...)
Posted: 14 Jan 2013 16:52
by Toenne
Hi!
#define in pascal?
And as far as I understand the button-function expects four bytes as parameters, how can two of them (Ports & Pin) been replaced by only one without error?
What I mean is an alternate function like "NamedButton(Name, time, active_state)", for this example "NamedButton(Sw_1, 10, 1)". So the first two parameters are replaced by the alias-name of the pin.
Would make life a little bit easier and make the code much better readable I think.
Best regards,
Toenne
Re: Names in Button(...)
Posted: 15 Jan 2013 09:21
by filip
Hi,
I have tried this and it works in Pascal :
Code: Select all
program Button_Test;
var Sw_1 : sbit at PORTB0_bit; // Pin B.5 = Switch1
var Sw_1_Direction : sbit at DDB0_bit; // Pin B.5 = Switch1
var oldstate : bit;
begin
Sw_1_Direction := 0; // set Button pin as input
DDRC := 0xFF; // configure PORTC as output
PORTC := 0xAA; // initial PORTC value
oldstate := 0; // oldstate initial value
while TRUE do
begin
if (Button(PINB, Sw_1, 1, 1)) then // detect logical one on RB1 pin
oldstate := 1;
if (oldstate and Button(PINB, Sw_1, 1, 0)) then
begin // detect one-to-zero transition on RB1 pin
PORTC := not PINC;
oldstate := 0;
end;
end; // endless loop
end.
Regards,
Filip.
Re: Names in Button(...)
Posted: 15 Jan 2013 16:56
by Toenne
Hi!
Thank you very much for your answer.
But in
Button(PINB, Sw_1, 1, 1) I still have to remember (or to look for) which port is it, although he's already defined in "Sw_1". A little improvement...but really only a little...
Best regards
Toenne