Datasheet
22 | Page
avrdude -qq -c gpio -p atmega328p -U lock:w:0x3F:m -U efuse:w:0x07:m -
U lfuse:w:0xE7:m -U hfuse:w:0xD9:m
@avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex
$(TARGET).elf: $(OBJ)
@echo [Link] $<
@$(LD) -o $@ $(OBJ) $(LDFLAGS) $(LIBS)
@avr-size $(TARGET).elf
# Generate .lst file rule
%.lst : %.o
@echo [lst] $<
@avr-objdump -h -S $<> $@
.c.o:
@echo [CC] $<
@$(CC) -c $(CFLAGS) $< -o $@
.PHONEY: clean
clean:
rm -f *.o *.elf *.hex *.lst Makefile.bak *~
Program 328
#!/bin/bash
# script to program 328p device using AVRDUDE and a hex file
if [ "$1" == "" ]; then echo Missing argument
exit 1;
fi
# if ends in .hex use full argument
# otherwise add the .hex
ext=${1:${#1}-4}
if [ "$ext" == ".hex" ]; then
/usr/bin/avrdude -c gpio -p m328p $1 -Uflash:w:$1
else
/usr/bin/avrdude -c gpio -p m328p $1.hex -Uflash:w:$1.hex
fi
Save the above code in a file called program_328 and then run "chmod 777 program_328". Use
./program_328 <hex file> to program the Atmega device.
Initial clock setup
You normally run the above command when you get a brand new device. It programs the
Atmega328 to use the external 16MHz Crystal.