I use atmega168a and configure fuse on Tools > device programming > AVR dragon > fuses > (click on) CKDIV8 to set it to 8 MHz internal clock.
what piece of code do I need to add to my C code to be able to set that fuse?
如果您在外部设置保险丝,作为一个单独的步骤,您不需要任何进一步的 C 代码。
如果以编程方式设置熔断器,则无需在外部设置熔断器。现在(每个)程序在运行时决定。此代码适用于 atmega32u2:
CLKPR = 1 << CLKPCE;
// 将预分频器设置为 1
CLKPR = 0;
在这两种情况下,您都应该设置F_CPU
:
#define F_CPU 8000000ul
在您的来源中,甚至更好CFLAGS
CFLAGS += -DF_CPU=8000000ul
in your Makefile
,以便其他人知道核心频率:例如_delay_ms
in 。<util/delay.h>