AVR GCC Toolchain

Most configuration bits are contained in device Fuse bytes. To program the fuse bits, the Fuse API is used. To use this API, include the <avr/io.h> header file, which provides everything necessary to set the AVR fuses.

To program code protection configuration bits, or lock bits, the Lockbit API is used. To use this API, include the <avr/io.h> header file.

An example using the FUSES and LOCKBITS macros is provided below. For more information on the Fuse and Lockbit APIs, see:

https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__fuse.html

https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__lock.html

Example: ATtiny861 MCU


// ATtiny817 Configuration Bit Settings

// 'C' source line config statements

#include <avr/io.h>

FUSES = {
	0x00, // WDTCFG{PERIOD=OFF, WINDOW=OFF}
	0x02, // BODCFG{SLEEP=SAMPLED, ACTIVE=DIS, SAMPFREQ=1KHz, LVL=BODLEVEL0}
	0x00, // OSCCFG{OSCLOCK=CLEAR}
	0x00, // Reserved
	0xC4, // TCD0CFG{CMPA=CLEAR, CMPB=CLEAR, CMPC=SET, CMPD=CLEAR, CMPAEN=CLEAR, CMPBEN=CLEAR, CMPCEN=SET, CMPDEN=SET}
	0xF6, // SYSCFG0{EESAVE=CLEAR, RSTPINCFG=UPDI, CRCSRC=NOCRC}
	0x00, // SYSCFG1{SUT=0MS}
	0x00, // APPEND
	0x00, // BOOTEND
};

LOCKBITS = {
	0xC5, // LOCKBIT{LB=NOLOCK}
};

The example above was generated from the Configuration Bits window (Window>Target Memory Views>Configuration Bits).

When you first open the Configuration Bits window, the data will be red, meaning you need to read from device memory. Use the “Read Configuration Bits” icon . Make any changes to the data in the window and then write changes back to the device by using the “Program Configuration Bits” icon .

To preserve your settings in code, click either the “Generate Source Code to Output” button, to put the code in the Output window for copy-and-paste into your code, or the “Insert Source Code into Editor” icon , to place the code at the cursor in an editor window.

Figure 1. Example: ATtiny817 MCU