74HC595

We program it with the function shiftOut(), eg.shiftOut(dataPin, clockPin, MSBFIRST, 255) (255 - BIN=11111111 - all pins high). But can we program it like shiftOut(dataPin, clockPin, MSBFIRST, 11111111) to make all pins high?

What if there's no shiftOut function, how can we send binary data to the data pin?

can we program it like shiftOut(dataPin, clockPin, MSBFIRST, 11111111) to make all pins high?

add a B to show it is a binary constant - shiftOut(dataPin, clockPin, MSBFIRST, B11111111);

What if there's no shiftOut function, how can we send binary data to the data pin?

You can implement shiftOut yourself of course

from C:\Program Files (x86)\arduino-0022\hardware\arduino\cores\arduino\wiring_shift.c

void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
	uint8_t 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);		
	}
}

If you know which datapin and clockpin is used you can create a direct port version which is faster (never tried so watch timing! :slight_smile:
and you could remove the LSBFIRST test out of the loop if you know the order compile time

and do loop unrolling - footprint vs speed

(BTW The double !! is to generate 0 and 1 from int values.)

((val >> i) & 1) is concise and clear - double negatives confuse people!

you are right, ((val >> i) & 1) is more clear. Might be faster too - a few cycles per bit?.

You can propose it as an enhancement for the shift-code ...

But if it ain't broke, don't fix it...

A few cycles per bit might improve the PWM shift register library though, it might increase the number of registers you can PWM... I say its worth trying

Can also use SPI, fast hardware shiftout vs slower software shiftout.

What is the use of the clock pin? It is triggered after every shiftOut right?

Then the receiving edge knows when the datasignal is stable so it can be read.