Challenge

Project 1 - Controlling a DC motor using PWM and monitoring its Running status

Challenge: 5

Question

Code:

#include <avr/io.h>
#include <time.h>
#include "avr/interrupt.h"
#define F_CPU 16000000
#include <util/delay.h>

int main(void)
{

int a = 0;
DDRB = 0xFF;
DDRC = 0xFF;
PORTD=(1<<5)|(1<<4);
sei(); //enable global interrupt
GICR=(1<<7)|(1<<6);
while(1)
{

PORTB|=(1<<5); //
a++;
_delay_ms(500);
if (a==10)
{
cli(); //disable global interrupt
}
}
}

ISR(INT0_vect) //ISR for INT0
{
PORTC|=(1<<4);
}

ISR(INT1_vect) //ISR for INT1
{
PORTC &= ~(1<<4);
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.