#include "avr8.h" class Wrapper { protected: ATMEGA16 * atmega16; public: Wrapper(){ atmega16 = reinterpret_cast(0); atmega16->ddrb = 0xff; // Set PORTB to output atmega16->portb = 0xff; // Turn off LEDs atmega16->sreg = 0x80; // Enable Interrupts atmega16->gicr = 0xD0; // Enable External Interrupt 0 atmega16->timsk |= 0x01; // Enable Timer1 Overflow Interrupt atmega16->mcucr = 0x02; // Interrupt 0 generated by falling edge } ~Wrapper(){ } void handle_int0() { if(atmega16->mcucr == 0x03) { // If IRQ0 is rising edge (button released) atmega16->mcucr = 0x02; // Set IRQ0 to falling edge atmega16->portb = 0xff; atmega16->tccr0 = 0x00; // Disable TIMER0 } else { // IRQ1 is falling edge (button pressed) atmega16->mcucr = 0x03; atmega16->tccr0 = 0x04; // Start TIMER1 @ CLK/256 } } void handle_timer0() { atmega16->portb = 0x00; //0xaa } }; Wrapper wrapper; extern "C" { void __vector_1() __attribute__ ((signal));/* IRQ 0 Interrupt Handler */ void __vector_9() __attribute__ ((signal));/* Timer0 Interrupt Handler */ } void __vector_1(){ wrapper.handle_int0(); } void __vector_9(){ wrapper.handle_timer0(); } int main() { while(1) return 0; }