I just noticed this thread. I've been trying to do something similar for the past couple of days, and it works if you define the pointer correctly. First, if I use < int* ptr = &PORTB; > I don't get a warning, I get a compile time error.
Secondly, use of the proper pointer works correctly - ie, all of the forms in loop() set the proper bit, and turn on the Led.
// UNO uses PortB.5 for the Led.
#define ledPIN 13
//int* ptr = &PORTB;
volatile uint8_t* ptr = &PORTB;
Serial.print(", PORTD: ");
// the following 8 forms all turn on the Led.
//*ptr |= 0b100000;
*ptr |= 1 << 5;
//PORTB |= 0x20;
//PORTB |= 0b100000;
//PORTB |= 1 << 5;
Thirdly, what I don't understand about this is that PORTB and PORTD do not print out correctly using Serial.print(). Here are the results of the above program, so ???
PORTB: 0, PORTD: 0
I also found the pointer method to be incredibly slow, for some unknown reason, so ???? on that too.http://forum.arduino.cc/index.php?topic=181482.msg1347130#msg1347130