/******************************************************************************
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 are down.
buttons shoudl be wired

                  +5V
                  |
              1K resistor
                  |
gnd------button---o---PortA
    
*******************************************************************************/
 
/****************************| INCLUDGEABLES |********************************/
 
#include<avr/io.h>
#include "global.h"
#include "rprintf.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)  {

  lcdInit();                  // initialize LCD on PortC        
  rprintfInit(lcdDataWrite);  // direct printf output to LCD
  lcdClear();                 // Clear LCD
  lcdGotoXY(0,0);	      // LCD Line 1 , Character 1
  rprintf("Button test R1"); 	

        
  DDRA = (INPUT << PA0)|(INPUT << PA1)|(INPUT << PA2)|(INPUT << PA3)|(INPUT << PA4)|(INPUT << PA5)|(INPUT << PA6)|(INPUT << PA7);
  DDRB = (OUTPUT << PB0)|(INPUT << PB1)|(INPUT << PB2)|(OUTPUT << PB3)|(INPUT << PB4)|(INPUT << PB5)|(INPUT << PB6)|(INPUT << PB7);
  DDRD = (INPUT << PD0)|(INPUT << PD1)|(INPUT << PD2)|(INPUT << PD3)|(INPUT << PD4)|(INPUT << PD5)|(INPUT << PD6)|(OUTPUT << PD7);        

 
  while(1) {
      lcdGotoXY(0,1); // Char 1, LCD Line 2

      if (0) { 
      } else if (IsLow(Button1, PINA) & IsLow(Button2, PINA)) {
         rprintf("Both buttons down"); 
      } else if (IsLow(Button1, PINA)) {
         rprintf("Button 1 down    ");
      } else if (IsLow(Button2, PINA)) {
         rprintf("Button 2 down    ");
      } else {
         rprintf("No buttons down  ");
      }      
   }
}
    
//------------------------| FUNCTIONS |------------------------
 
