why using port d is not a switch at the same time atmega328p

Viewed 23
#define F_CPU 16000000L // Specify oscillator frequency
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
    DDRD = 0xFF;// set PortD for output
    PORTD= 0x00;

    
    while(1)
    {
        
        PORTD =0xAA; // set 7th bit to LOW
        _delay_ms(1000);
        PORTD =0x55; // set 7th bit to HIGH
        _delay_ms(1000);
    }
}

The current situation is that at the same time, only four LEDs are turned on, four LEDs are turned off, and eight LEDs are switched on and off at the same time. All eight are placed in the pins of ddrd. How to do

0 Answers
Related