Microcontrollers and stuff A blog by Derk Vedelaar


JY-MCU 3208 lattice clock

I bought the jy-mcu 3208 lattice clock from dealextreme. It is a matrix display that features a ht1632c display driver and am atmega8 microprocessor. To be able to program the processor i also bought an usbasp dongel on ebay (something similar to this one).

I didn't do much with microprocessors other than the arduino, empty atmega's on which i flashed the arudino bootloader and my previous post. So, this had to change. I figured it all out (at least, i think so) and am writing this post mostly for my own reference.

Lets start with creating backups from everything that is now on the mcu. I am a windows user and to do anything wit the mcu you need winavr. Download and install it. To download the code from the device i used the following command:

avrdude -c usbasp -p m8 -v -B8 -U flash:r:jymcu.flash.i:i

The -c option tells what programmer is used (mine is a usbasp programmer as this one was the cheapest i could find). The -p option tells the kind of microprocessor. The -B option tells the microprocessor how long to wait between each phase of programming the chip. The smaller the faster, i chose 8 because i saw a lot of other people do this on the internet (good reason, huh?) and i guess it will make the chance on faults smaller. Now, the -U parameter is the most interesting. It is built like this:


Memory type can be eeprom, flash, hfuse, lfuse or lock. Format can be a, b, d, h, i, o, r or s. I personally like i the most. So, this is what i ran, to have a full backup:

avrdude -c usbasp -p m8 -v -B8 -U flash:r:jymcu.flash.i:i
avrdude -c usbasp -p m8 -v -B8 -U eeprom:r:jymcu.eeprom.i:i
avrdude -c usbasp -p m8 -v -B8 -U hfuse:r:jymcu.hfuse.i:i
avrdude -c usbasp -p m8 -v -B8 -U lfuse:r:jymcu.lfuse.i:i
avrdude -c usbasp -p m8 -v -B8 -U lock:r:jymcu.lock.i:i

Now, lets put some new code on the device. There are some people that wrote already something for this device:
DrJones on dealextreme
vogelchr (not tested, added after I broke my 3208)

I used DrJones code to start with. To compile it I did the following:

avr-gcc -Os -std=c99 -mmcu=atmega8 -o clockmtx.elf clockmtx.c
avr-objcopy -O ihex clockmtx.elf clockmtx.hex

It will output a .elf file and a .hex file. The .hex file is suitable for programming on the device. To program it to the device i did the following:

avrdude -c usbasp -p m8 -v -B8 -U flash:w:clockmtx.hex:i

Allright. Now that this code works, i wanted to change the fuses a little bit, to change it from 1mhz to 8mhz. I used this fuse calculator to calculate the correct value. It seems that the lfuse default value is 0xE1, which means 1mhz, and the calculator gave me 0xE4 for 8hmz. Changing the fuse took me a little bit of playing but this seemed to be working:

avrdude -c usbasp -p m8 -v -B8 -U lfuse:w:0xE4:m

A little test program that flashes the leds really fast showed that it had worked.

That's about it so far.

Posted by Derk