Names in Button(...)

Post your requests and ideas on the future development of mikroPascal PRO for AVR.
Post Reply
Author
Message
Toenne
Posts: 6
Joined: 13 Jan 2013 16:08

Names in Button(...)

#1 Post by Toenne » 13 Jan 2013 17:35

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-# ?

Code: Select all

Button(PINC, 5, 30, 1)
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

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Names in Button(...)

#2 Post by filip » 14 Jan 2013 11:29

Hi,

The Button routine can passed as a pin argument, so I suggest you using #define for this purpose, like this :

Code: Select all

 #define  Sw_1 PORTC5_bit
Regards,
Filip.

Toenne
Posts: 6
Joined: 13 Jan 2013 16:08

Re: Names in Button(...)

#3 Post by Toenne » 14 Jan 2013 16:52

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

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Names in Button(...)

#4 Post by filip » 15 Jan 2013 09:21

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.

Toenne
Posts: 6
Joined: 13 Jan 2013 16:08

Re: Names in Button(...)

#5 Post by Toenne » 15 Jan 2013 16:56

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

Post Reply

Return to “mikroPascal PRO for AVR Wish List”