]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/main.c
Programmable Z180 clock, clock command
[z180-stamp.git] / avr / main.c
index e4c98b8bd8f1fcfb730a649300f484c0b03b686e..65622ccfe5316d11d8cb5908809218bb397508c6 100644 (file)
@@ -77,8 +77,8 @@ void setup_avr(void)
        MCUCR = _BV(JTD);
        MCUCR = _BV(JTD);
 
-       /* disable unused periphels */
-       PRR0 = _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRADC);
+       /* disable unused peripherals */
+       PRR0 = _BV(PRTIM0) | _BV(PRADC);
        PRR1 = _BV(PRTIM5) | _BV(PRTIM4) | _BV(PRTIM3) |
                _BV(PRUSART3) | _BV(PRUSART2) | _BV(PRUSART1);
 
@@ -92,9 +92,10 @@ void setup_avr(void)
 
        /* Timer */
 
-       OCR1A = F_CPU / 8 / 1000 - 1; // Timer1: 1000Hz interval (OC1A)
-       TCCR1B = 0b00001010;
-       TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt
+       OCR2A = F_CPU / 256 / 1000 - 1; /* Timer2: 1000Hz interval (OC2A) */
+       TCCR2A = (0b10 << WGM20);       /* CTC Mode */
+       TCCR2B = (0b110 << CS20);       /* Prescaler 256 */
+       TIMSK2 = _BV(OCIE2A);           /* Enable TC2.oca interrupt */
 }
 
 static