#include #include //C is incomplete; there's no port A //B and D are 8 bit ports //AtoD is on port C int main(){ int b, b7, b6, b67, up=0, down=0, normal=1; long k, l, m, n; DDRD=0xff; DDRB=0x00; for (k=0;k<1000000;k++); // a million is approx. 8 seconds for (k=0;k<75;k++) { // begin flash LED0 75 times PORTD=0x01; // port D LEDs start out low; set to high for first time for (l=0;l<3000;l++); PORTD=0x00; for (l=0;l<3000;l++); } // end flash LED0 75 times while(1){ b=PINB; //if (lsb==0) b=0xaa; // if (lsb==128) b=0x00; b7 = (b<<7); // 0 if clear; 128 if set b67 = (b<<6); b6 = (b67)>>7; // 0 if clear; 1 if set if (b7 > 0) { // go into up mode if (normal) { PORTD=0x04; // turn on bit 2 for ">" for (k=0;k<3000;k++); // wait } up=1; normal=0; down=0; } if (b6 > 0) { // go into down mode if (normal) { PORTD=0x08; // turn on bit 3 for "<" for (k=0;k<3000;k++); // wait up=0; normal=0; down=1; } } if ((b6==0)&&(b7==0)) { // go to normal if (down) { PORTD=0x04; // turn on bit 2 for ">" up=0; normal=1; down=0; } if (up) { PORTD=0x08; // turn on bit 3 for "<" up=0; normal=1; down=0; } } } }