/******************************************************************************
Title:    encoder -> PWM
Author:   rue_mohr
Date:     Aug 19 2005
Software: AVR-GCC 3.3 
Hardware: atmega32
  
                         ATmega32 - 40 PIN DIP LAYOUT FOR DECODER AND PWM - 
                                      _______________________
                                      [ 1]PB0         PA0[40] <- up button
                                      [ 2]PB1         PA1[39] <- down button
                                      [ 3]PB2         PA2[38] 
                                      [ 4]PB3         PA3[37] 
                                      [ 5]PB4         PA4[36] 
                                      [ 6]PB5         PA5[35] 
                                      [ 7]PB6         PA6[34] 
                                      [ 8]PB7         PA7[33] 
                             RESET -> [ 9]RST        AREF[32] <- +5V VCC
                            5V VCC -> [10]VCC         GND[31] <- GROUND
                            GROUND -> [11]GND        AVCC[30] <- +5V VCC
                       16 MHZ XTAL -> [12]XTAL1       PC7[29] -> LCD DATA 7
                       16 MHZ XTAL -> [13]XTAL2       PC6[28] -> LCD DATA 6
                                      [14]PD0         PC5[27] -> LCD DATA 5
                                      [15]PD1         PC4[26] -> LCD DATA 4
                                      [16]PD2         PC3[25] -> LCD E  
                                      [17]PD3         PC2[24] -> LCD RS 
                                      [18]PD4         PC1[23] -> LCD RW 
                                      [19]PD5         PC0[22]                  
                                      [20]PD6         PD7[21]  
                                      ______________________                         


what this should do:
it should tell you what buttons went down.

to test this properly, 
  push down button 1 and hold it,   "button 1 went down"
  push button 2 and let it up       "butotn 2 went down"
  let up button 1                   "butotn 2 went down"

buttons shoudl be wired

                  +5V
                  |
              1K resistor
                  |
gnd------button---o---PortA
    
*******************************************************************************/
 
/****************************| INCLUDGEABLES |********************************/
 
#include<avr/io.h>
#include "global.h"
#include "rprintf.h"
#include "timer.h"
#include "lcd.h"
/*****************************| DEFINIATIONS |********************************/
  
#define OUTPUT             1
#define INPUT              0

#define IsHigh(BIT, PORT)    ((PORT & (1<<BIT)) != 0)
#define IsLow(BIT, PORT)     ((PORT & (1<<BIT)) == 0)
#define SetBit(BIT, PORT)     PORT |= (1<<BIT)
#define ClearBit(BIT, PORT)   PORT &= ~(1<<BIT)

// which bit the buttons are on (porta)
#define Button1         0
#define Button2         1
 
/*****************************| VARIABLES |********************************/
 
 
/************************| FUNCTION DECLARATIONS |*************************/
 
 
/****************************| CODE... |***********************************/
 
int main (void)  {

  char buttonStat, oldButtonStat;
  char changes;

  lcdInit();                  // initialize LCD on PortC        
  rprintfInit(lcdDataWrite);  // direct printf output to LCD
  lcdClear();                 // Clear LCD
	        
  DDRA = (INPUT << PA0)|(INPUT << PA1)|(INPUT << PA2)|(INPUT << PA3)|(INPUT << PA4)|(INPUT << PA5)|(INPUT << PA6)|(INPUT << PA7);
// port B for lcd  
  DDRC = (INPUT << PC0)|(INPUT << PC1)|(INPUT << PC2)|(INPUT << PC3)|(INPUT << PC4)|(INPUT << PC5)|(INPUT << PC6)|(INPUT << PC7);
  DDRD = (INPUT << PD0)|(INPUT << PD1)|(INPUT << PD2)|(INPUT << PD3)|(INPUT << PD4)|(INPUT << PD5)|(INPUT << PD6)|(INPUT << PD7);        
 
  lcdGotoXY(0,0); // Char 1, LCD Line 2
 //        12345678901234567890
  rprintf("Hello world.        ");
  
  while(1);
}
    
//------------------------| FUNCTIONS |------------------------
 
