LED光立方制作全过程(二十八)
0赞Step 45Program the AVR: Set the fuse bits




The ATmega32 has two fuse bytes. These contain settings that have to be loaded before the CPU can start, like clock source and other stuff. You have to program your ATmega to use an external high speed crystal oscillator and disable JTAG.
We set the lower fuse byte (lfuse) to 0b11101111, and the high fuse byte to 0b11001001. (0b means that everything after the b is in binary).
We used avrdude and USBtinyISP (http://www.ladyada.net/make/usbtinyisp/) to program our ATmega.
In all the following examples, we will be using an Ubuntu Linux computer. The commands should be identical if you run avrdude on Windows.
- avrdude -c usbtiny -p m32 -U lfuse:w:0b11101111:m
- avrdude -c usbtiny -p m32 -U hfuse:w:0b11001001:m
Warning: If you get this wrong, you could easily brick your ATmega! If you for example disable the reset button, you won't be able to re-program it. If you select the wrong clock source, it might not boot at all.
Step 46Program the AVR with test code



Time to test if your brand new LED cube actually works!
We have prepared a simple test program to check if all the LEDs work and if they are wired correctly.
You can download the firmware test.hex in this step, or download the source code and compile it yourself.
As in the previous step, we use avrdude for programming:
- avrdude -c usbtiny -p m32 -B 1 -U flash:w:test.hex
-c usbtiny specifies that we are using the USBtinyISP from Ladyada -p m32 specifies that the device is an ATmega32 -B 1 tells avrdude to work at a higher than default speed. -U flash:w:test.hex specifies that we are working on flash memory, in write mode, with the file test.hex.
