Project 1 - Controlling a DC motor using PWM and monitoring its Running status
#include <avr/io.h> // header file for AVR
#define F_CPU 16000000 // oscillator frquency of AVR
#include <avr/interrupt.h> //header file for interrupts
#include <util/delay.h> // header file for delay
int main()
{
int a=0;
DDRB=0xFF; // assigning portB as output
DDRC=0xFF; // assigning portC as output
PORTD=(1<<3)|(1<<2); // enabling the pull up resistor
sei(); // enabling interrupt
GICR=(1<<7)|(1<<6);
while(1)
{
PORTB|=(1<<2);// portB pin_2 as output
a++;
_delay_ms(1000); // delay of 1000 milliseconds
if(a==10)
{
cli(); // after 10 iteration interrupt ends
}
}
}
ISR(INT0_vect) //vector selection
{
PORTC|=(1<<4);
}
ISR(INT1_vect)
{
PORTC&=~(1<<4);
}