I was looking at the wiring_shift.h file to see how the shiftOut function worked and I thought that the use of the digitalWrite function was kind of inefficient. I read some articles a while back that said the digitalWrite function took up to fifty-something cycles to execute while setting PORTx took something like ~2 cycles to execute.. Am I wrong in thinking that it would be pretty straight forward to implement PORTx and increase the speed of the function?
Here is the code from wiring_shift.h (copied without modification)
#include "wiring_private.h"
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val)
{
int i;
for (i = 0; i < 8; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)));
else
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}
The reason I ask is because I am using a shift register to control a POV-LED display and with the addition of PWM and more LED's, I fear that the standard shiftOut function wouldn't be fast enough.
thanks in advance for any advice
Also, how do you use PORTx to set ONE pin at a time and not all eight? Something with cbi() and sbi() ?