Button function

General discussion on mikroC.
Post Reply
Author
Message
ascomm
Posts: 129
Joined: 30 Mar 2005 18:28
Location: Finland

Button function

#1 Post by ascomm » 26 Jul 2005 18:48

Code: Select all

void blinking()
{
   GPIO.F1 = 0;
   Delay_ms(800);
   GPIO.F1 = 1;
   Delay_ms(200);
}

void poweroff()
{
   GPIO.F1 = 0;
}

void powersaving()
{
   GPIO.F1 = 0;
   Delay_ms(8);
   GPIO.F1 = 1;
   Delay_ms(4);
}

void bright()
{
   GPIO.F1 = 0;
   Delay_ms(4);
   GPIO.F1 = 1;
   Delay_ms(8);
}

void main(void)
{
  unsigned short b;

  TRISIO = 1;
  CMCON = 7;
  ANSEL = 0;

  GPIO.F1 = 0;

  b = 0;

  while (1)
  {

    if (Button(&GPIO, 0, 5, 0) && b < 3)
    {
      b++;
    }
    else if(Button(&GPIO, 0, 5, 0) && b == 3)
    {
      b=0;
    }

    if (b==3) blinking();
    if (b==2) powersaving();
    if (b==1) bright();
    if (b==0) poweroff();

    /*switch (b)
    {
      case 0: poweroff();  break;
      case 1: bright(); break;
      case 2: powersaving();  break;
      case 3: blinking(); break;
      default: asm nop;
    } */
  }
}

Is there someting wrong with this program because it doesn't react button presses at all?
Can I use Button with same port which has output functions?

Charlie
Posts: 2744
Joined: 01 Dec 2004 22:29

#2 Post by Charlie » 26 Jul 2005 18:50

Hi ascomm,

You might try to have the ANSEL and the trisio settings at the Beginning of your code.
Regards Charlie M.

ascomm
Posts: 129
Joined: 30 Mar 2005 18:28
Location: Finland

#3 Post by ascomm » 27 Jul 2005 17:37

CharlieM wrote:You might try to have the ANSEL and the trisio settings at the Beginning of your code.
Doesn't help... :?
Program runs just the blinking() function constantly. Or I think it is running that because the RA1 is blinking but nothing else happens.
char *signature;
signature = "MikroC Pro and EasyPIC 2";

Post Reply

Return to “mikroC General”