#include <avr/io.h>
#include <avr/interrupt.h>
#define TCCR1A *(volatile char*)0x80
#define TCCR1B *(volatile char*)0x81
#define OCR1A *(volatile short*)0x88
#define TCNT1 *(volatile short*)0x84
#define TIMSK1 *(volatile char*)0x6F
#define SREG *(volatile char*)0x5F
#define PCICR *(volatile unsigned char*)0x68
#define PCMSK2 *(volatile unsigned char*)0x6D
volatile char *f_out = (volatile char*)0x31;
volatile char *k_in = (volatile char*)0x106;
void initPort();
void initTimer();
void initInterrupt();
void setup() {
initPort();
initTimer();
initInterrupt();
}
void initPort(){
volatile char *f_dir = (volatile char*)0x30;
volatile char *k_dir = (volatile char*)0x107;
*f_dir = 0xff; *k_dir = 0x00;
}
void initTimer(){
TCCR1A = 0x00; //Normal mode
TCCR1B = 0x00;
TCNT1 = 0X00; //clear timer/counter value
OCR1A = 62000; //for 1 sec
TIMSK1 = 0x02; // Output Compare A Match Interrupt Enable
TCCR1B = 0x0C; //CTC and 256 prescalar
}
void initInterrupt(){
*k_in = 0x01; //pull up
SREG = 0x80; //enable global interrupts
PCICR = 0x04; //port k pin change interupt
PCMSK2 = 0x01; //enable port k pin 0
}
ISR(TIMER1_COMPA_vect){
*f_out ^=0x01;
}
ISR(PCINT2_vect){
*f_out |= 0x02; //set bit 1
for (volatile long j = 0; j < 500000; j++);
*f_out &= ~(0x02); //clear bit 1
}
void loop() {
}