
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

// 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
}