Interrupt Exercise

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

/*

* Gccmotor_control.c
*
* Created: 30/11/2020 3PM
* Include files are initially declared for the functions used in the
various modules in the program
* Use proteus simulation software to analyze the program and write your own
observations. Use your own actuations connected to PortC with pull up resistors
* Atmega32 microcontroller used in this exercise.
*/

# define F_CPU 1000000UL

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

// calls, includes defined names for all of the SFRs on the Microcontroller
// contains two functions for causing the program to wait for certain periods of
time
// _delay_ms(xxx) (milliseconds). Note delay can also be in microseconds _delay_us
(yyy).

int i, temp;

//Interrupt Service Routine Function//

ISR(INT0_vect)
{
_delay_ms(50); // Software debouncing
control

temp=PORTC; // Save current value on


DataPort

// This for loop blink LEDs on PortC 5 times//

for(i = 0; i<5; i++)


{
PORTC=0x00;
_delay_ms(5000); // Wait 5 seconds
PORTC=0xFF;
_delay_ms(5000); // Wait 5 seconds
}

PORTC=temp; // Restore old value to


DataPort
}

int main(void)
{

DDRC=0xff; // PortC is configured as an


output and lower nibble pins made high
PORTC=0b00001111;
DDRD = DDRD & ~(1<<2); // Enable portD pd2 as input for
external interrupt INT0
PORTD=0b11111111; // Set Port pins high as
initialization

GICR=1<<INT0; // Enable INT0


MCUCR=(1<<ISC01)|(1<<ISC00); // Trigger INT0 on rising edge

sei(); // Enable Global Interrupt


/* while is executed so long as the interrupt signal is not enabled
It is for you to find out the type of outcome the program will bring.
it is worth noting that interrupt flag is enabled for any external interrupt
to be serviced.
You can have other interrupt functions but highest interrupt is INT0.
Note of interrupt vector table usage.
*/

while(1)
{

if(PORTC>= 0x80)
PORTC= 1;
else
PORTC= PORTC << 1; // Shift to the left

_delay_ms(5000); // Wait 5 seconds


}
}

You might also like