# Direct port manipulation on ATMEGA8

For some reason seems that while compiling for ATmega8, direct port manipulation commands, that were working fine on the 328, are simply ignored.

I am still able to use DPM for other things like setting up timers and internal pull ups.

Here’s an example of what i had to do:

`````` if /*(!(PIND &= (1<<PD4)))*/
{
if ((a <= 65535) && (a>30))
a=a-10;
delay(5);
Serial.print(a);
Serial.print("   ");
Serial.println ((float) 7812/a);
}
//Serial.println(a);

if //(!(PIND &= (1<<PD5)))
{
if ((a >= 0) && (a <65500))
a=a+10;
delay(5);
Serial.print(a);
Serial.print("   ");
Serial.println (float(7812/a));
}
``````

Any ideas what the problem might be!?

``````if  (!(PIND &= (1<<PD4))
``````

You almost certainly want that to be “PIND & (1<<PD4)” (no “=” sign.) Having the = sign will cause the PIND register to be written with the masked value, which behaves differently on the mega328 (toggles the output value) than it does on the mega8 (where it’s supposed to be a read-only register, so you’d read it again, without the masking?)

Brilliant tip, Thank you!