Gast
#3314422
ATMEGA128 Ich habe die Sicherungen (Fuses) für clk_cpu gemäß dem datasheet konfiguriert.Der CPU Takt stimmt nicht wie es beschrieben wurde. Für eine externale Krystal (16000) sollte die Frequenz einen Wert von 16MHz betragen. (CKPOT:1, CKSEL:1111, Fuse Low: FF, High:99, Extended: FF, clk_cpu: 2MHz, aber es sollte 16MHz sein.) Für internalen RC-Oszillator war es ebenfalss false (CKPOT:1, CKSEL:0100, Fuse Low: F4, High:98, Extended: FF, clk_cpu: 1MHz, aber es sollte 8MHz sein.) s. Atmega datasheet pp. 40-41 Code /* configure cpu clock ts8900-m128 board */ #include <avr/io.h> #include <stdbool.h> // to use bool type #define MS_COUNTS 1000 void main(){ //led initialization DDRA=(1<<PA0);//led0 (PA0) is output PORTA=0xff;//initialize leds, led0-led7 are turned off DDRE=(1<<PE2);//enable LED driver by setting PE2, see circuit PORTE=(1<<PE2); /*F_CPU can be defined in project configuration but it is just an constant; it has no effect on the actual clock source, nor on the cpu frequency */ #ifdef F_CPU PORTA &=~(1<<PA7); //led7 on pin7 #endif //test cpu clock with led0 uint16_t ms =1000; // uint16_t i,j; bool led_on= false;//toggle led by negation while (1){ if (led_on) {PORTA&=~(1<<PA0);} //led0 is on else {PORTA|=(1<<PA0);}//led0 turn off for(i=0;i<ms;i++) { for(j=0;j<MS_COUNTS;j++){asm volatile ("nop"::);}; } led_on= !led_on; /* led0: off-on-off-on-...... a single off-on cycle is 2x10^6 (=2M) clock ticks one off-on takes 1 sec as measured by counting led switching in 1 min */ } //test cpu }