Code:
#include <avr/io.h>
#include <stdint.h>
// #define F_CPU 2000000UL // <- damit komm ich auf die 8s
#include <util/delay.h>
int main(){
CLKSEL0 |= (1 << EXTE); // CKSEL0.EXTE = 1; // Enable_external_clock();
while ( (CLKSTA & (1 << EXTON)) == 0 ){} // while (CLKSTA.EXTON != 1); // while (!External_clock_ready());
CLKSEL0 |= (1 << CLKS); // CLKSEL0.CLKS = 1; // Select_external_clock();
CLKPR = 0b10000000; // Unterschiedliche Einstellungen des Prescalers wirken sich nicht aus.
CLKPR = 0b10000000;
uint8_t aPLLCSR = PLLE;
aPLLCSR |= PLLP0; // Damit sollten die 16MHz halbiert werden-
PLLCSR |= aPLLCSR; // PLLCSR.PLLE = 1; // Enable_pll();
CLKSEL0 &= ~(1 << RCE); // CLKSEL0.RCE = 0; // Disable_RC_clock();
while ( (PLLCSR & (1 << PLOCK)) == 0){} // while (PLLCSR.PLOCK != 1); // while (!Pll_ready());
USBCON &= ~(1 << FRZCLK); // USBCON.FRZCLK = 0; // Usb_unfreeze_clock();
DDRB=1;
while(1) {
for (uint8_t i=0; i<5; i++){ // 5x1s -> 5s
PORTB=0;
_delay_ms(500);
PORTB=1;
_delay_ms(500);
}
for (uint8_t i=0; i<30; i++){ // 30x 0,1s -> 3s
PORTB=0;
_delay_ms(50);
PORTB=1;
_delay_ms(50);
}
} // Insgesamt 8s, aber es dauert ca. 64s
}
Lesezeichen