/****************************************************************************** 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: when you turn the encoder one way, the motor shoudl go forward, at a variable speed when you turn the encoder the other way, the motor shoudl go backward, at a variable speed center is stopped, goes up as you get away from center when it rolls over, it will suddenly switch directions *******************************************************************************/ /****************************| INCLUDGEABLES |********************************/ #include #include "global.h" #include "rprintf.h" #include "lcd.h" /*****************************| DEFINIATIONS |********************************/ #define OUTPUT 1 #define INPUT 0 /*****************************| 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 ((PINA & 0x03) == 3) { rprintf("No buttons down"); } else if (PINA & 0x01) { rprintf("Button 1 down"); } else if (PINA & 0x02) { rprintf("Button 2 down"); } else { rprintf("Both buttons down"); } } } //------------------------| FUNCTIONS |------------------------