AGXF Flashlight


Despite how much stuff I wanted to cram into one small place, the construction turned out to not be the hardest part.  Coding was.  Part of the reason coding was so difficult was that I was learning assembly language for the first time (and it was also my first programming language).  Yeah, assembly language is generally not the best language to start out with.  Luckily, there were only 35 instructions, so it was not too difficult to grasp most of the language.  Another problem was the overhead in learning the actual specifics of how the MCU operates (which is fairly important when working so closely with the special registers).  I actually spent about a month trying to learn the language to a point where I’d be able to do something more complicated.

Me, Getting a "Flashing LED" Program Working

So actually, learning the language wasn’t that hard.  What was much harder was figuring out exactly what each button would do, and how holding one button for a certain amount of time would do something, and how to get IR Receiving working, and how to get music playing through the buzzer, etc.  In general, it was really difficult to figure out a flowchart for what my program would do at all times.  I did eventually complete a flowchart (which spans 16 full pages).  If you want to see, it you can check out my incomplete documentation at the end.

Using a Camera as an Oscilloscope to View IR Pulses

Much of the code was difficult to write, but perhaps the most difficult was IR Receiving.  Coming up with a protocol for my IR Transmitting/Receiving wasn’t too difficult; I just had to figure out some simple timings.

IR Tx/Rx Protocol (top) and Carrier Frequency (bot)

The problem with receiving is that you always have to allow for error catching and a bit of leeway.  For example, there’s no way to ensure that every signal will have the exact 0.52ms pulse required for a digital “0.”  So I had to give a threshold for receiving.  It was also really annoying having to check all the loops and gotos.  I did eventually get it working with a high amount of success, but getting there took a while.

After about 2 months of coding and 5 more months of debugging, I finally completed the code.  You can see it here: OS.asm.