تخطي للذهاب إلى المحتوى

digitalWrite() is a function that looks up a pin number in a table, works out which port it belongs to, and sets a bit. It costs real cycles to do something the hardware does in one instruction.

// what the library does, eventually
digitalWrite(13, HIGH);

// what the hardware needs
PORTB |= (1 << PB5);

Reading the pattern

1 << PB5 builds a mask with one bit set. |= sets that bit and leaves the others alone; &= ~mask clears it. Almost all register work is those two lines in different clothes.

When it is worth it

Usually it is not. Reach for registers when you need speed inside an interrupt, or a peripheral the library does not expose — not to save four cycles in code that then spends 500 ms in delay().

digitalWrite() is a function that looks up a pin number in a table, works out which port it belongs to, and sets a bit. It costs real cycles to do something the hardwa
التقييم
0 0

لا توجد تعليقات حالياً.

لتكون أول من يترك تعليقاً.

Shopping Cart
جارٍ التحميل...