Problem With external interrupt of Attiny84

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my purpose is to use external interrupt pin. I hooked up button to PB2 in Attiny84, I want to just turn an LED ON when a button is pressed

I can't figure out what's the problem .. any help please ?

there is my code for interruption

void interupt(){

        MCUCR=(0<<ISC01)|(1<<ISC00);
        GIMSK=(1<<INT0);
}

ISR(INT0_vect){

        PORTA = PORTA&~(1u<<7);
}

int main(void){

        DDRA=0b10111100;
        PORTA=0B10110100;
        interupt();
        sei();
        while(1);{}
}

 

 

 

Last Edited: Tue. Dec 26, 2017 - 09:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So what does happen when you press the button?

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, and for completeness...

 

1) How have you hooked up your button?

2) How have you hooked up your LED?

3) How have you proved that your controller is being programmed with your code correctly?

4) How have you proved that your controller is running your code?

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please post a schematic or at least a picture of your setup.

 

Jim

 

Mission: Improving the readiness of hams world wide : flinthillsradioinc.com

Interests: Ham Radio, Solar power, futures & currency trading - whats yours?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I press the button Nothing happened, the LED does not turn ON

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can find the schematic in the attachment file

 

Thank you

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you Brian for your reply,

to respond your first and second questions I post a schematic of my project.

For your third and fourth questions : There is no error happened when I passed my code to my controller,

I tested it with a simple code that reads the state of the button (High or Low) and turn the Led ON or OFF following the state of the button and it worked fine.

The problem happened when I switch to working with interrupt, I don't know why it doesn't work.

Last Edited: Wed. Dec 27, 2017 - 10:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your code sets pa7 low in the isr - this turns the led off according to your schematic.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The code is a "one shot". As soon as the condition happens once that is it and nothing else will change from there on. You might want to consider having the interrupt toggle state. Or perhaps when the event occurs set a flag and when the code in a main while loop sees the flag set it starts a delay after which it switches the LED state back.