void init_port();
void init_timer();
void setup() {
volatile long i;
int j=0;
init_port();
init_timer();
Serial.begin(9600);
while(1)
{
for(i=0; i<1000000; i++);
Serial.println(j,DEC);
j++;
}
}
void init_timer(){
volatile char *Timer1_TCCR1A = 0x80;
volatile char *Timer1_TCCR1B = 0x81;
volatile short *Timer1_TCNT1 = 0x84;
volatile short *Timer1_OCR1A = 0x88;
volatile char *Timer1_TIMSK1 = 0x6F;
*Timer1_TCCR1A = 0;
*Timer1_TCCR1B = 0;
*Timer1_TCNT1 = 0;
*Timer1_OCR1A = 60000; // compare match register 16MHz/256/2Hz 31250
*Timer1_TCCR1B = 0x0C; // CTC mode & 256 prescaler
*Timer1_TIMSK1 = 0x02; // enable timer compare interrupt
}
void init_port()
{
volatile char *portd_dir = (volatile char *)0x2A;
*portd_dir = 0x10;
}
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
volatile char *portd_data = (volatile char *)0x2B;
*portd_data ^= 0x10;
}
void loop() {
}