06 // PóniLó morZe - MCU programming |
This week the assignment was simple: redesign a PCB by adding an LED and Button, and program it so they do something cool. My design is Póniló morZe - a Morse encoder, which converts characters reaching it over the serial port to blinks of light. |
The process is simple but requires quite a few steps:
|
My program can be viewed here. Most MCU programs are quite easy to understand: first you setup all the ports and pins and their directions and properties, like the pull-up resistor that needs to be switched on if a button is connected. Then the programs goes to a Coma, where it can recover from when an interrupt arrives that is generated when a Serial event happens (a character arrives from the Serial line). If no interrupt is present you cannot even read a button periodically, because the whole program is concentrated on reading a serial value. Thus we like interrupts. |
Some important revelations: PROJECT=hello.ftdi.44.echo SOURCES=$(PROJECT).c MMCU=attiny44 F_CPU = 20000000 CFLAGS=-mmcu=$(MMCU) -Wall -Os -DF_CPU=$(F_CPU) $(PROJECT).hex: $(PROJECT).out avr-objcopy -j .text -O ihex $(PROJECT).out $(PROJECT).c.hex;\ avr-size --mcu=$(MMCU) --format=avr $(PROJECT).out $(PROJECT).out: $(SOURCES) avr-gcc $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES) program: $(PROJECT).hex avrdude -p t44 -c usbtiny -U flash:w:$(PROJECT).c.hex programfuses: $(PROJECT).hex avrdude -p t44 -c usbtiny -U lfuse:w:0x7E:mTo compile your code type (in the directory of your source): >> make To upload your program type: >> make program To program the fuse bits type: >> make programfuses Now you are using the 20Mhz crystal which is very precise and fast. |
|
www.flickr.com
|