Arduino with ATmega328 issue with PORTB |= _BV(PB5);

Hi,

I found something strange with the ATmega328. I have a Arduino with 328 and one with the 1280. The following test i found on the internet verifies Ok when the board is set to Arduino mega 1280 in Arduino 0022. But the same program has a problem with line PORTB |= _BV(PB5);
when set Arduino … w/ATmega328 in Arduino 0022.
Tried some other board settings in Arduino 0022 and ATmega8 Atmega168 and ATmega2560 verify correctly without any error.
Is this a program issue in Arduino software?

void setup()
{
Serial.begin(9600);
}
void loop()
{
int initial = 0;
int final = 0;
initial = micros();
for(int i = 0; i < 500; i++)
{
digitalWrite(13,HIGH);
digitalWrite(13,LOW);
}
final = micros();
Serial.print(“Time for digitalWrite(): “);
Serial.print(final-initial);
Serial.println(””);

initial = micros();
for(int i = 0; i < 500; i++)
{
PORTB |= _BV(PB5);
PORTB &= ~_BV(PB5);

}
final = micros();
Serial.print("Time for true c command: ");
Serial.print(final-initial);
while(1);
}

For some reason the bit names are different:
io.h:
#elif defined (AVR_ATmega328P)

include <avr/iom328p.h>

#elif defined (AVR_ATmega2560)

include <avr/iom2560.h>

iom328p.h:
#define PORTB _SFR_IO8(0x05)
#define PORTB0 0
#define PORTB1 1
#define PORTB2 2
#define PORTB3 3
#define PORTB4 4
#define PORTB5 5
#define PORTB6 6
#define PORTB7 7

iom2560.h:
#include “iomxx0_1.h”

iomxx0_1.h:
#define PORTB _SFR_IO8(0x05)
#define PB7 7
#define PB6 6
#define PB5 5
#define PB4 4
#define PB3 3
#define PB2 2
#define PB1 1
#define PB0 0

Hi John and the other readers,

Tested it in the program and Yes it verifies correctly when using PORTB5 instead of PB5.
So when using a ATmega328 arduino board the direct port name should be PORTB0 - PORTB7

Tested it in Arduino 1.0 RC2 and same problem/solution with ATmega328 boards.

Tested the same program with "Wiring" and there it is verifying correct with PB5 and on all other Arduino boards too.

The io.h file and al its subsidiaries are part of AVRLIB which comes with the compiler so it's probably out of the direct control of the Arduino team.

Perhaps one of the Arduino includes could have something like:

#if undefined(PORTB0)
#define PORTB0 PB0
#endif