То есть с хотя бы первым уровнем оптимизации я получаю честные 8 МГц тактовой, а если поставить Оптимизация = None, то работает только на 2 МГц, что бы я не заряжал в регистры OSC и CLK.
Вот код, посмотрите пожалуйста, - может быть я что-то не так делаю?:
Код
//-------------------------------------------------------------
#include <avr/io.h>
#include <avr/cpufunc.h>
#include <avr/wdt.h>
#include <inttypes.h>
#include <util/atomic.h>
#include "pin_macros.h"
#define TP3_ON VPORT1_OUT |= PIN3_bm //
#define TP3_OFF VPORT1_OUT &= ~PIN3_bm //
//----------------- THE MAIN --------------------------------------
int main (void)
{
cli();
// SYSTEM_CLK = 8 MHz:
OSC.CTRL = 0x61; // RC8MEN & RC2MEN
while(!(OSC.STATUS & OSC_RC8MRDY_bm));
CPU_CCP = CCP_IOREG_gc; // protected by the configuration change protection mechanism
CLK.CTRL = 0x05; // 101- RC8MHZ (8MHz internal oscillator)
// PORTC:
PORTC.DIR = 0x08; // TP3
PORTC.OUT = 0x00;
// PORTD:
PORTD.DIR = 0x10; // pin4
PORTD.OUT = 0x00;
PORTCFG.CLKOUT = 0x82; // Clock output on PORTD pin4
// WDT:
CPU_CCP = CCP_IOREG_gc; // protected by the configuration change protection mechanism
WDT.CTRL = 0x27; // 4.0s
//
sei();
//
while(1)
{
TP3_ON;
wdt_reset();
TP3_OFF;
wdt_reset();
}
}
#include <avr/io.h>
#include <avr/cpufunc.h>
#include <avr/wdt.h>
#include <inttypes.h>
#include <util/atomic.h>
#include "pin_macros.h"
#define TP3_ON VPORT1_OUT |= PIN3_bm //
#define TP3_OFF VPORT1_OUT &= ~PIN3_bm //
//----------------- THE MAIN --------------------------------------
int main (void)
{
cli();
// SYSTEM_CLK = 8 MHz:
OSC.CTRL = 0x61; // RC8MEN & RC2MEN
while(!(OSC.STATUS & OSC_RC8MRDY_bm));
CPU_CCP = CCP_IOREG_gc; // protected by the configuration change protection mechanism
CLK.CTRL = 0x05; // 101- RC8MHZ (8MHz internal oscillator)
// PORTC:
PORTC.DIR = 0x08; // TP3
PORTC.OUT = 0x00;
// PORTD:
PORTD.DIR = 0x10; // pin4
PORTD.OUT = 0x00;
PORTCFG.CLKOUT = 0x82; // Clock output on PORTD pin4
// WDT:
CPU_CCP = CCP_IOREG_gc; // protected by the configuration change protection mechanism
WDT.CTRL = 0x27; // 4.0s
//
sei();
//
while(1)
{
TP3_ON;
wdt_reset();
TP3_OFF;
wdt_reset();
}
}