Docsity

Interrupt Handling in AVR Microcontrollers: Changing Duty Cycle with INT0 Interrupt, Exercises of Microprocessors

Toggle sidebar
bg1
// ***********************************************************
// Project: Understanding Interrupts
//
// Module description: To change the Duty cycle of an output pulse with
interrupt
// ***********************************************************
#include <avr\io.h> // Most basic include files
#include <avr\interrupt.h> // Add the necessary ones
#include <avr\signal.h> // here
int lo_time= 70;
int hi_time= 30;
int tmp;
// Define here the global static variables
//
// Interrupt handler example for INT0
//
SIGNAL(SIG_INTERRUPT0)
{
tmp=hi_time;
hi_time=lo_time;
lo_time=hi_time;
}
// ***********************************************************
// Main program
int main(void)
{
_SEI() //sets global int
DDRB = (1<<DDB1) // sets PB1 as output.
MCUCR|=0x03; //defines interrupt when int0 is low.
GICR|=1<<6; //enables int0 // enables int0 interrupt
while(1)
{
PORTB=0x02; // setting high at PB1
for(int i=0;i<hi_time;i++); //Busy loop for High time
PORTB=0x00; // setting LOW at PB1
for(int i=0;i<lo_time;i++); //Busy loop for LOW time
}
}
docsity.com

Partial preview of the text

Download Interrupt Handling in AVR Microcontrollers: Changing Duty Cycle with INT0 Interrupt and more Exercises Microprocessors in PDF only on Docsity!

// Project: Understanding Interrupts // // Module description: To change the Duty cycle of an output pulse with interrupt // ***********************************************************

#include <avr\io.h> // Most basic include files #include <avr\interrupt.h> // Add the necessary ones #include <avr\signal.h> // here int lo_time= 70; int hi_time= 30; int tmp;

// Define here the global static variables //

// Interrupt handler example for INT // SIGNAL(SIG_INTERRUPT0) { tmp=hi_time; hi_time=lo_time; lo_time=hi_time;

}

// *********************************************************** // Main program

int main(void) { _SEI() //sets global int DDRB = (1<<DDB1) // sets PB1 as output. MCUCR|=0x03; //defines interrupt when int0 is low. GICR|=1<<6; //enables int0 // enables int0 interrupt while(1) { PORTB=0x02; // setting high at PB for(int i=0;i<hi_time;i++); //Busy loop for High time PORTB=0x00; // setting LOW at PB for(int i=0;i<lo_time;i++); //Busy loop for LOW time

}

docsity.com