PortB not working for Pin8 and Pin9

Hi all.

I trying to use PortB to write to Pin8-13, as described in the documentation:

This simple code, will make Pin 10,11,12,13 flash:

void setup(void)
{
	DDRB = B11111111;
}

void loop(void)
{
	PORTB = B11110000;
	delay(1000);

	PORTB = B00000000;
	delay(1000);
}

This works! :slight_smile:
Now I want to make Pin 8 and Pin 9 flash as well, so I modify the code in the mail loop to:

PORTB = B11111100;   % <=== Notice the change
delay(1000);

PORTB = B00000000;
delay(1000);

Nothing changes :frowning:
When using DigitalWrite, Pin 9 and 10 are working just fine.

What can be wrong?
I'm using Arduino Mega.

PORTB = B11111100;  % <=== Notice the changeHave you got the order of the bits the wrong way round ?
Should that be

PORTB = B00111111;   % <=== Notice the change

Nope :slight_smile:
I have also verified that, by flipping all the pins high. I really don't understanding what could cause this.

According to Arduino port mapping Arduino digital pin 8 maps to PB0 and digital pin 8 maps to PB1

Where are bits 0 and 1 in B00111111 ?

This is what I have tried:

void setup(void)
{
	// Set portB as output.	
	DDRB = B11111111;
}

// Main
void loop(void)
{
	PORTB = B11111111;
	delay(1000);

	PORTB = B00000000;
	delay(1000);
}

Only pin 10, 11, 12 and 13 is working as expected. Pin 8 and 9 is not switching between high and low.
As stated in the original post "PORTB = B11110000" makes pin 13, 12, 11 and 10 go high. That seems to be the opposit of the documentation you found. If changing to "PORTB = B00110000", then only pin 11 and 10 are high.

********** EDIT **********
Hmm... So for the Arduino Mega, port B is:

PB 0 => Pin 53
PB 1 => Pin 52
PB 2 => Pin 51
PB 3 => Pin 50
PB 4 => Pin 10
PB 5 => Pin 11
PB 6 => Pin 12
PB 7 => Pin 13

I guess that is my issue... :slight_smile:

So for the Arduino Mega,

Now you tell us.....