Need help with pushbutton on atmega8
Pushbutton wired directly from VCC to PORT7D.


There's one problem. When the button is pushed, the input is high. When the button is released, the input is floating. This is bad.

Configure the internal pullup on the pin, and then tie the button to ground. The input will be low when the button is pushed, and high when released.


if( (PORTD &amp; (1&lt;&lt;PORTD7)) == 1)



And there's two more. The input value is on PINx, not PORTx. And that equality check is erroneous.

if (PIND &amp; _BV(PD7))