PortD problem

Hi,
I am doing a electronic project for an class I’m taking. The professor only allowed to use Arduino Digital Pins as a counter. It’s connect to a DAC0832. Using 8 bits.

What I want to do is quite simple. I want the 8 digital pins (Binary) go from 0 to 255 then from 255 to 0 .
What’s happening is that they are setting high till 255 then it’s going back directly to 0. It’s not decreasing from 255 to 0. What’s wrong in this code?

void setup() {
  
   DDRD = 255;
 }

void loop() {
  
  PORTD++;
  delay(1000);
  if ( PORTD == 255){
    while ( PORTD != 0 ){
      PORTD--;
      delay(1000);
      }
  }
}

You are not showing us all the code.

It's not decreasing from 255 to 0. What's wrong in this code?

Why do you think it is not decreasing?

void setup() {
  Serial.begin(9600);
   DDRD = 255;
 }

void loop() {
  
  PORTD++;
  delay(100);
  Serial.println(PORTD);
  if ( PORTD == 255){
    while ( PORTD != 0 ){
      PORTD--;
      Serial.println(PORTD);
      delay(100);
      }
  }
}

cattledog: Why do you think it is not decreasing?

void setup() {
  Serial.begin(9600);
   DDRD = 255;
 }

void loop() {     PORTD++;   delay(100);     if ( PORTD == 255){     while ( PORTD != 0 ){       PORTD--;       Serial.println(PORTD);       delay(100);       }   } }

The wave I am gettting in the output. It only goes up till 255 then suddenly go back to zero. I think the problem may be somewhere else . I'm simulating with proteus. The code seems ok , right?

I think the problem may be somewhere else . I'm simulating with proteus. The code seems ok , right?

The serial printout patched into your code shows numbers going up and down..