Embeded Programming aka Hello AVR.C
This week was theoretically a low week on actual physical making as we moved to program our boards from here to do what we wanted them to do. For mine I wanted to use the button as a counter and use the LEDs (I put on two) to display the count in binary. Thus both off for 0, one on for 1, the other for 2 and both for 3. Adapting the code in C from Neil's example was pretty straightforward. I simply mashed together Neil and Rob Hart's examples and used an int variable as a counter to hold the count mod for and then turn on the various lights in a switch statement according to the count. This was very intuitive for me as I have done a bunch of coding in the past. The one thing I want to do but didn't have time to figure out, is factor out many of the #defines and helper funtions into a util.c file and then simply include utils.h and have a much cleaner and simpler main file. This will also allow me to continuously build up libraries of code from which I can use on all of my programs. It's been a long time since I codede in C and I never really did Makefiles so I will need to investigate this more. For now my current file can be found here with makefile here.
Of course nothing in this class goes perfectly smoothly and while I could get the code to complie I could not get it to set the fuses -- it kept timing out. Time to debug! It turns out my programmer has decided to stop working. I will have to debug this later! Meanwhile using the avrisp2 I was able to successfully program my board! Unfortunately it wasn't working as I expected. I addded some debug prints from the serial connections and was able to determine that the chip was receiving the high and low signals from the button but for some reason wasn't changin the buttons appropriately. I decided to comment out all of the serial code and then whamo the buttons started working. I will have to debug this more later but there is some sort of collision going on where the serial port setting and the button setting is conflicting. But now I can blink the lights!
Of course things are never super simple and I need to code up a debouncer to get this counter to really work as the button actually calculates a bunch of button presses each time you press it so it cycles faster than you can perceive unfortunately! I'll keep you posted if I figure out some debounce code! See week 9 where I hope to be able to tackle this!Back