#include "avr8.h" class RRInterrupt_KeyBoard { private: AT90S * at90s; int count; // Timer/Counter0 Overflow counter public: RRInterrupt_KeyBoard () { AT90S * at90s = reinterpret_cast(0); //at90s->ddrb = 0xff; // configure as output asm ("out 0x17, %0" : : "r" (0xff)); //at90s->portb = 0xff; // turn all leds off asm ("out 0x18, %0" : : "r" (0xff)); //at90s->ddrd = 0x0; // configure as input asm ("out 0x11, %0" : : "r" (0x00)); //at90s->sreg |= 1<<7; // Global Interrupt enable asm ("out 0x3f, %0" : : "r" (0x80)); //at90s->gimsk |= 1<<6; // External Interrupt Request 0 enable asm ("out 0x3b, %0" : : "r" (0x40)); //at90s->timsk |= 1<<1; // Timer/Counter0 Overflow Interrupt enable asm ("out 0x39, %0" : : "r" (0x02)); //at90s->mcucr |= 0xfe; // the falling edge of INT0 generates an interrupt request asm ("out 0x35, %0" : : "r" (0xfe)); count = 0; } void handleIRQ0 () { count = 0; if (at90s->mcucr == 0xfe) { //at90s->tccr0 = 0x05; // start Timer/Counter0 with prescale CK/1024 asm ("out 0x33, %0" : : "r" (0x05)); //at90s->mcucr |= 0xff; // the rising edge of INT0 generates an interrupt request asm ("out 0x35, %0" : : "r" (0xff)); } else { //at90s->mcucr |= 0xfe; // the falling edge of INT0 generates an interrupt request asm ("out 0x35, %0" : : "r" (0xfe)); //at90s->tccr0 = 0x0; // stop Timer/Counter0 asm ("out 0x33, %0" : : "r" (0x00)); //at90s->portb |= 1<<2; // turn off led 2 asm ("out 0x18, %0" : : "r" (0x04)); } } void handleTimer0Overflow () { count++; if (count == 35) { //at90s->portb &= ~(1<<2); // turn on led 2 asm ("out 0x18, %0" : : "r" (0xfb)); //at90s->tccr0 = 0x0; // stop Timer/Counter0 asm ("out 0x33, %0" : : "r" (0x00)); } } }; RRInterrupt_KeyBoard rri_kb; int main() { while(1) {} return 0; } extern "C" { void EXT_INT0 (void) SIGNAL; void TIM0_OVF (void) SIGNAL; } void EXT_INT0 (void) { rri_kb.handleIRQ0(); } void TIM0_OVF (void) { rri_kb.handleTimer0Overflow(); }