I have extremly stupid question, but I wasn't able to find answer to it. I am starting AVR programming and I have one question, regarding code example I've found.

int main(void)
{
    DDRA = 0xFF; // Setting all port A pins for output

for(;;)
{
    PORTA = ~0x21; // Why ~ if we want PA0 and PA5 to be High?
    _delay_ms(10000);
}

So why we need to invert 0x21? It should have High on PA0 and PA5, but if we are inverting it, shouldn't it be the opposite (all High except for PA0 and PA5)?

I have tried to search, but I haven't found any explanation. Thank you!

有帮助吗?

解决方案

The issue was with me looking only into code. You should also always check scheme to see how UC is connected.

In my case it was "inversive" way of connection, where "0" meant LED turned on.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top