/* ATmega32 - 40 PIN DIP LAYOUT FOR LCD- _______________________ [ 1]PB0 PA0[40] [ 2]PB1 PA1[39] [ 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 encoder 1 [16]PD2 PC3[25] -> LCD E encoder 2 [17]PD3 PC2[24] -> LCD RS [18]PD4 PC1[23] -> LCD RW [19]PD5 PC0[22] not connected [20]PD6 PD7[21] ______________________ */ #include #include #include #include "global.h" #include "rprintf.h" #include "lcd.h" #include "timer.h" void setupEncoder(void); void updatePos(void); int position; // note that this is signed unsigned char oldstate; // for quadrature decoding int main(void) { // initialize the timer system timerInit(); // initialize LCD on PortC lcdInit(); // direct printf output to LCD rprintfInit(lcdDataWrite); lcdClear(); setupEncoder(); sei(); while (1) { // PORTA = position >> 8; // example use of the result // try sending it to an lcd! lcdGotoXY(0,1); rprintf("Pos - %d ",position); } } void setupEncoder() { // clear position position = 0; // we need to set up int0 and int1 to // trigger interrupts on both edges MCUCR = (1<> 2); // update oldstate position += offsets[temp]; // update position if (position == 2016) position = 0; if (position == -1) position = 2016; // if (position == 2016) position = 0; //rues first thought // if (position == 16384) position = 2016; }