# Makefile for compiling and uploading C programs to AVR chips # stolen from the avr-gcc-examples # http://guerila.com # choose your chip CPU=atmega8 P= -p m8 #CPU=atmega16 #P= -p m16 #CPU=attiny45 #P= -p t45 # parallel port device. You may have to `modprobe ppdev', and/or # give your user permissions to use the parallel port by adding # your user name to the group the device file is writeable for. D= -P /dev/parport0 # choose the avr-gcc GCC=avr-gcc # compiling any .c file to any .o file %.o: %.c $(GCC) -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -mmcu=$(CPU) -Wa,-adhlns=$(<:.c=.lst) -I. -c $< -o $@ # any .o to any .elf %.elf: %.o $(GCC) $< -Wl,-Map=$(<:.o=.map),--cref -mmcu=$(CPU) -o $@ # finally, .elf to .hex %.hex: %.elf avr-objcopy -O ihex -R .eeprom $< $@ # maybe, if the kernel's parrallel port is a module and not auto-loaded modprobe: su -c "modprobe ppdev" # erases the chip erase: avrdude $P $D -c stk200 -e #uisp -dprog=stk200 -dlpt=/dev/parport0 --erase # uisp alternative # reads the fuse bits from the chip to the files hfuse.read and lfuse.read readfuse: avrdude $P $D -c stk200 -U hfuse:r:hfuse.read:r -U lfuse:r:lfuse.read:r ###### BE CAREFUL WITH THE FUSE BITS -- you may lock your device ###### # sets the fuse bits to 0xd9e1, the factory default of the ATMEGA8 # THIS IS NOT THE DEFAULT FOR ANY OTHER AVR! Read the datasheets. fusestd: avrdude $P $D -c stk200 -U hfuse:w:0xd9:m -U lfuse:w:0xe1:m # sets the fuse bits to 0xc9ef, enabling my external Quartz oscillator # at 4 MHz, according to the datasheet. (ATMEGA8 ONLY!) fuseosc: avrdude $P $D -c stk200 -U hfuse:w:0xc9:m -U lfuse:w:0xef:m # additional target to upload a hex file -- does NOT generate an .up file %.up: %.hex avrdude $P $D -c stk200 -e -U flash:w:$< #uisp -dprog=stk200 -dlpt=/dev/parport0 --upload if=$<