Sunday, February 8, 2009

When a nerd has a birthday

Just before my birthday this year, I found an interesting article shared on Slashdot. The article was a DIY kit for an led marquee. The project is based on something put together by a couple of MIT students that they call a "nerd kit". I thought it sounded like fun and asked for it for my birthday. It seemed like something that Marshall would enjoy participating in.
After Ruth said that she ordered it for my birthday, I looked up the parts list and downloaded a document on the micro-controller. For a while, I felt like I was in college again. I got really excited about working in assembler and dealing with interrupts! I know that there are very few people in the world that can identify with that.
The other thought that I had involved me teaching Marshall about programming. Marshall has been asking me for a long time to teach him how to write programs. I have tried several times to teach him Java, but every time I try to talk about things I get tangled in the circular dependencies. I can never seem to get a foundation on which to build. Several people at work thought it sounded crazy, but it seemed to me that the limited number of instructions on the micro-controller would make it easier to learn than Java.
Yesterday, Marshall's bantam hockey team had two games in Decatur, a 2 hour drive. Marshall and I sat in the back seat for the trip. We brought a small white board and I made up a hybrid assembler language based on my college experience with the PDP-11 and what I had seen of the instruction set for the micro-controller. In addition, we made up a magic register that would automatically decrement its value every second until it reached zero. Another register was tied to output pins on the micro-controller. Those pins could be used to drive LEDs. Having this in place, we were able to write a small program that simulated a traffic light system using the LEDs. I showed him the various registers in the CPU and how they are used. After going through the program, he seemed to understand how it worked.
After that, I taught him about interrupts and showed him how we could actually accomplish the magic by using a clock interrupt routine to cause a register decrement every second until it reaches zero. He felt comfortable with it all.
Today, we had games in Springfield. This time it was just the two of us in the car, so I wouldn't be able to draw things on a white board. I had printed out the reference pages containing the instruction set for the micro-controller. Marshall started looking at it and asking questions. I was amazed at how many times he pointed out that my "hybrid" language was wrong for the micro-controller based on what he found. At one point, he found some instructions that differentiated between signed and unsigned integers. So we spent the rest of the trip discussing how to represent negative integers in a binary system. I can remember two's complement giving some people fits in college, but Marshall picked it up fairly quickly. I thought it was impressive considering we didn't have anything to write on and the only prop we had was our fingers to represent binary digits!
On the way home, we decided that we were going to do the project where we simulate the traffic lights. The scenario will be the situation where they close down one lane of a two lane road and share the one remaining lane via a traffic light. To do so, I taught him about Finite State Machines. For our next step, we're each going to design a FSM to control the signal. Since this topic excites me, look for me to blog more about our progress!

No comments: