arduino pure programming part5 - external interrupt



#include <avr/io.h>
#include <avr/interrupt.h>
#define SET_BIT(X,Y) X|=1<<Y
#define CLR_BIT(X,Y) X&=~(1<<Y)
#define IS_BIT_SET(X,Y) X&(1<<Y)
#define TOGGLE_BIT(X,Y) X^=(1<<Y)

ISR(INT0_vect)
{
TOGGLE_BIT(PORTB,PB5);
}


void delaymicroseconds(unsigned long us)
{
unsigned long temp = us;
SET_BIT(TCCR0B,CS01); //Starting the timer with prescaler clock/8 which is 0.125us
while(temp != 0) {
TCNT0 = 247;
while(!IS_BIT_SET(TIFR0,TOV0));
CLR_BIT(TIFR0,TOV0);
temp--;
}

}

int main()
{
SET_BIT(DDRD,2);
SET_BIT(PORTD,2);

DDRB |= 1<<5;
PORTB &= ~(1 << PB5);
EIMSK = 1<<INT0;
EICRA = 1<<ISC01;
sei();
while (1){delaymicroseconds(3000000U);}
return 0;
}

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig