This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Interrupts

I would like to do the next thing.

If I use P9.1 like as general input I'd like to do some operations when this input is set. How can I do it?

I have try that:

void hello(void) {
printf("Hello, willow\n");
}


void main(void)
{
MAIN_vInit();

while (1)
{
if (P9_P0) {
hello();
}
}
}


With this example I'm wrong because hello repeats so many times until P9.0 is reset. I don't want do that, I would like to do this only one time and I'm thinking to do hello like an interrupt but I don't know how.

  • Please follow the instruction for posting code, so that you get a legible layout:

    void main(void)
    {
       MAIN_vInit();
    
       while (1)
       {
          if (P9_P0) {
             hello();
          }
       }
    }
    "hello repeats so many times until P9.0 is reset."

    Of course it does - you have it inside a while(1) loop!

    while(1) is an infinite loop - it just repeats forever until the power goes off!


    "I would like to do this only one time"

    You just need a flag that you set when you've done it once.
    (you also need to decide what will cause the flag to be cleared - that's your homework for today).

  • Thanks so much.

    I don't know about posting code instructions. Thanks so much again.