Classes > Embedded programming
For this class I wanted to use the hello world board as an output of some data coming from the serial port. Thinking on it's output devices (led and serial), I thought of using the LED to blink the morse code of the character coming from the serial port.
First, in order to test the board, I wrote a simple program in ASM (using the AVRA assembler), that turns on the LED when you press the button. The code is available at the electronics design documentation.
Then I started writing code for my exercise. At the begginning I was using serial code from the hello.bus example and it worked fine, but I wanted to have a RX buffer and to have a function to check if there is data waiting at the serial port (like you can do with hardware uart). So I rewrote my library to use input interrupts. So when the state of the RX pin changes, an interrupt raises, and then I can check for the start bit, read the input byte, and store it in the buffer. Then a serial_available() function just has to check for bytes stored in the buffer to see if we have something ready to read. The size of the buffer can be adjusted by a define.
Then for the morse code, there's a simple lookup table that translates dots and dashes to bytes. The idea is simple, if the LSB of that number is 1, dash, if it's 0 dot, then divide the number by two and repeat until we got integer 1 and stop. For the spacing and timing, standard morse code convention is used, speed is in words per minute (WPM), so length of a dot is 1200/WPM, lenght of a dash is 3*dot, space between symbols is equal to one dot, space between letters is equal to three dots and between words is equal to seven dots.
Files: