The Wooden Menace: Software

Program Download:

Main C File

Software Overview
           The software for this project is too complex for me to explain well in one sitting. So I'll go over two parts of the code which may not be as easy to understand because of their relationship to the hardware.

/*Begin Controller Data Polling*/
PORTDbits.RD1 = 1; //Clock Up
PORTDbits.RD3 = 1; //Take Input
PORTDbits.RD1 = 0; //Clock Down
PORTDbits.RD3 = 0;
//Algorithm for capturing input
PORTDbits.RD1 = 1;
    //Clock Up
PORTDbits.RD1 = 0;
    //Clock Down
c_val += PORTDbits.RD2;
    //Add Input to our integer
  c_val = c_val << 1;
/**End Controller Data Polling**/
Controller Input Polling
           The controller used in this project has two HEF4021BT chips inside of it which take input from buttons being pressed. The routine seen in the code is called a 'Bit Banging' procedure. 'Bit Banging' is when you simulate the clock through your own digital device to get the given input. A standard SPI could have been used with much more ease. I didn't figure this out until afterward.
           Looking at the code, RD1 simulates the clock. RD3 tells the controller to take input of all the buttons at once, then the input taken is clocked out bit by bit into an integer called c_val.
#pragma code InterruptVectorHigh=0x08
          //interrupt pointer address
void InterruptVectorHigh (void)
_asm      //assembly code starts
goto InterruptHandlerHigh
          //interrupt control
_endasm   //assembly code ends
#pragma code
#pragma interrupt InterruptHandlerHigh
          //end interrupt control

Interrupt Handling
           The interrupt handler itsself is too complicated to describe well in this short little html page. So I'll just look at the interrupt control. If you have questions about the interrupt handler feel free to ask me about it in the forums.
           The interrupt controller is set at high priority 0x08. We then define a goto statement in assembly for the function name of the interrupt handler, in our case: InterruptHandlerHigh. Once the interrupt control is correctly implemented interrupts will be sent to the interrupt handler where you can do whatever is necessary depending on the type of interrupt.

Software: Parting Words
           There is much more to the software that I'd love to explain, however it's just not possible in this simple & short write up. I encourage you to look at the actual code available for download as the comments within it should be enough to guide you through the flow of the program.