Hi - I'm attempting to program an AVR so that through a computer (through the serial port) one can easily control how fast it turns on and turns off a single pin. This actually has a use (it will be used by a grad student doing some research in nano EDM [electro discharge machining]). I haven't been able to test it, so I don't have the slightest clue if it works or not.
Essentially the entire design of it is that when you first turn on the AVR, it initializes a couple basic things (enables timers, sets portc as an output, initializes the stack, etc.) and then it waits for a command from the serial port, analyzes it, and uses it to set the parameters of the timer and to enable/disable all interrupts (thus enabling/disabling the timer ISRs). The computer attached can also request certain parameters if needs be.
It's written in lovely AVR assembler by yours truly. The only thing I was able to test was the timer part of the code, as I could simulate that with AVR Studio. (though strangely enough I think I found a couple bugs with AVR Studio 4, as sometimes it would behave differently than other times - even though I hadn't changed anything...)
The code between the computer and the AVR is fairly simple. Each message is one byte long. If it's a command, the first set of 4 bits is the command, the second set of 4 bits is the parameter (or 0x0 if it doesn't need a parameter). Before a second byte can be sent (say when sending the high and then low byte of one of the timer compares) the receiver (AVR/computer) must give the transmitter (computer/AVR) permission. This was done as the UART on the AT90S8515 can only hold one byte at a time. I may move this code to a different avr eventually - but the AT90S8515 is the only AVR I've ever worked with, so I decided to go with it, even though it's discontinued.
Anyways - the serial communication part of the code is 100% untested so I'm not even sure if any of it works. All I know is that it compiles ok :)
Most of the code is commented. The stuff that isn't is mostly redundant stuff that I thought was fairly self explanatory.
Sorry for writing so much - I gotta work on that! Here's the assembler file, let me know if you have trouble downloading it:
Thanks!
-Michael Noone