#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#define read_eeprom_byte(address) eeprom_read_byte ((const uint8_t*)address)
#define write_eeprom_byte(address,value) eeprom_write_byte ((uint8_t*)address,(uint8_t)value)
unsigned char l=0,m=1;
unsigned char i,j,k;
uint8_t EEMEM eeprombyte=1;
int main()
{
DDRB = 0x08;
DDRD = 0x30;
OCR0 = 255; //blue pb3
OCR1AH = 00;
OCR1AL = 255; //red pd5
OCR1BH = 00;
OCR1BL = 255; //green pd4
TCCR0 = 0x63;
TCCR1B = 0x03;
TCCR1A = 0xA1;
PORTD = 0x08; //make the PD3 input pin
GICR = (1<<INT0);
sei();
while(1);
return 0;
}
ISR(INT0_vect)
{
_delay_ms(100);
if((PIND & (1<<3))==0) //check that the intrupt is activated or not
{
l=read_eeprom_byte(eeprombyte); //store the eeprom data into variable l
l++;
write_eeprom_byte(eeprombyte,l);
if(l==4) //as we have 4 cases so when we press key again then it will
//go to case 1 autometically
write_eeprom_byte(eeprombyte,1); // save 1 to eeprom variable
switch(l)
{
case 1:
{
{
blue();
_delay_ms(200);
}
break;
}
case 2:
{
{
green();
_delay_ms(200);
}
break;
}
case 3:
{
{
red();
_delay_ms(200);
}
break;
}
case 4:
{
{
white();
_delay_ms(200);
}
break;
}
}
}
}
white(void)
{
char i=0;
OCR0 = i;
OCR1AL = i;
OCR1BL = i;
}
red(void)
{
char i=0;
OCR0 = 255;
OCR1AL = i;
OCR1BL = 255;
}
blue(void)
{
char i=20;
OCR0 = i;
OCR1AL = 255;
OCR1BL = 255;
}
green(void)
{
char i=20;
OCR0 = 255;
OCR1AL = 255;
OCR1BL = i;
}
voilet(void)
{
char i=0;
OCR0 = i;
OCR1AL = i;
OCR1BL = 255;
}