Showing posts with label external. Show all posts
Showing posts with label external. Show all posts

Sunday, July 6, 2008

Testing external interrupt INT0 on tiny13

Tiny 13 have an external interrupt "INT0" on PB1, We have created a test project on avr-gcc to have a quick testing on the INT0.



#include <avr/io.h>
#include <avr/interrupt.h>
#include "pin_macros.h"

unsigned char led=0;

ISR(INT0_vect) {
if (led){
b0_high;
led = 0;
} else {
b0_low;
led = 1;
}
}

int main (void)
{
b1_input; //switch
b0_output; //led output

MCUCR = 1<<isc01; //set INT0 as falling edge trigger

GIMSK = 1<<INT0; //enable INTO in global interrupt mask


sei(); //enable interrupt

while(1) {
;; //interrupt do the rest
}
}



B1 is connected to a switch, and B0 is connected to a LED.
When B1 is pressed, it would toggle the LED On or Off.

Download the whole project : http://labs.bitartist.org/test_int0.tar.gz

Reference:
http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html