How to Make (Almost) Anything
How to Make (Almost) Anything
Week 5: Microcontroller Programming
Monday, October 19, 2009
This week, the assignment was to add a button (between an empty pin on the microcontroller and ground) to a small board design given to us and alter the code for it (both in assembly and in C) to make it respond when the button was pressed. The group that I worked with produced code to make the light on the board turn on when the button that we added to the board is pressed. I’ll explain the basic concepts of what we did.
The first thing that must be done when creating a program like the one that we made is to ensure that the LED and button pins are set for input and output, respectively. This is accomplished by setting the appropriate bits in the Data Direction Register for the port that they are located on. This information can be found in the data sheet of the microcontroller. In the assembly program, this is accomplished by using the sbi and cbi instructions to set or clear the bits in the register directly. In the C program, bit math is used to OR the register with the desired bit directions for the pins in a small macro at the top of the program.
You can download the assembly program here.
You can download the C program here.
********************INCOMING MESSAGE FROM THE FUTURE********************
I will allow people to download a .zip file of the schematic, circuit board, and firmware from the future using this link. Take it easy on the traffic though; trans-temporal bandwidth isn’t cheap.
Oh yeah, and don’t go to the food truck for lunch on Tuesday. Trust me.
**************************TRANSMISSION END******************************
One day I’m going to learn that starting a project the night before it is due usually isn’t a great idea, no matter how simple I think it’s going to be.