Skip to content

Instantly share code, notes, and snippets.

@kichMan
Last active April 21, 2018 10:37
Show Gist options
  • Save kichMan/4e4769e90efa7ca6752d793ba001ed62 to your computer and use it in GitHub Desktop.
Save kichMan/4e4769e90efa7ca6752d793ba001ed62 to your computer and use it in GitHub Desktop.
Project build for ATmega
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
int main (void)
{
DDRB |= _BV(PB5);
PORTB &= ~_BV(PB5);
while (1)
{
if (PINB & (1 << PB5)) {
PORTB &= ~_BV(PB5);
} else {
PORTB |= _BV(PB5);
}
_delay_ms(500);
}
return 0;
}
MCU=m168p
MMCU=atmega168pa
DEVICE=avrisp2
.PHONY: all flash build download clean
all: build
flash: build download clean
build:
avr-gcc -g -Os -mmcu=$(MMCU) -c main.c && avr-gcc -g -mmcu=$(MMCU) -o main.elf main.o && avr-objcopy -j .text -j .data -O ihex main.elf main.hex
download:
avrdude -p $(MCU) -c $(DEVICE) -U flash:w:main.hex
clean:
@rm -v *.hex *.o *.elf
erase:
avrdude -p $(MCU) -c $(DEVICE) -e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment