# Issue with _delay_ms and PORT

Whenever I try to set a certain port to high, then wait some time, then set some other port to high, I get an issue where only the last value would be set. The code I import via USBASP and avrdude is:

#define F_CPU 1000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

int main(void)
{
DDRD = 0b11111111;
PORTD = 0b11111110;
_delay_ms(1000);
PORTD = 0b11111101;

while(1)
{
;
}
}


And that just sets all pin on PORTD to high except PD0, ignoring the second instruction. Moreover, if I replace that piece of code with something like this:

_delay_ms(1000);
DDRD = 0b11111111;
PORTD = 0b11111110;


It does light all the pins on the port with a one second delay. I'm using an ATmega8A and also utterly lost.

• Have you checked if the fuse bits are set for internal oscillator? Also make sure that you compile for the correct target (for avr-gcc -mmcu=atmega8 parameter should be passed). – Ashton H. Jun 28 '15 at 2:25
• Can you please re-post this question on SE Embedded System site. I think this question belongs to that site. – prasad Aug 10 '15 at 15:48
• The post is kinda old, and I cannot find the Embedded System site. Also my question is pretty closely related to EE – Nopony Aug 10 '15 at 18:02