

Using the defines statements like this allows us to only need to modify 3 easy-to-find lines if we move the LED to a different I/O pin or use a different AVR. We use defines to declare our button and LED's ports and pins. The function we'll be using, is _delay_ms(). The library util/delay.h contains some routines for short delays. #include // header to enable delay function in program It simply defines the constants for all your pins, ports, special registers, etc. io.h will determine the CPU you're using (which is why you specify the part when compiling) and in turn include the appropriate IO definition header for the chip we're using. The first include file is part of avr-libc and will be used in pretty much any AVR project you work on.

#endif #include // header to enable data flow control over pins. #define F_CPU 16000000UL // telling controller crystal frequency (16 MHz AVR ATMega328P) In this case it is used by the delay routines to determine how to calculate time delays. The first few lines we have some compiler defines.į_CPU defines the clock frequency in Hertz and is common in programs using the avr-libc library.

If you don’t have Atmel Studio, you should download and install it.
