Control I/O register without library

Hello. Could someone tell me why the following does not work on Uno? Thanks.

voidmain(void)
{
uint8_t* DDRB = (uint8_t*) 0x04;
uint8_t* PORTB = (uint8_t*) 0x05;
*DDRB |= 0x01; // Set bit 0 of port B to output direction
for (;:wink: //infinite for loop
{
volatile unsigned int i;

*PORTB ^= 0x01; // Toggle B0 using exclusive-OR

i= 50000; // Delay
do(i--);
while(i!= 0);
}
}

for (;:wink: //infinite for loop
The compiler doesn't like smiley faces. Maybe try a frowny face, instead.

Could someone tell me why the following does not work on Uno?

The code is incomplete, please post your whole code (and please use the # button to tag it properly)

Have you read - http://www.arduino.cc/en/Reference/PortManipulation - ??

DDRB and PORTB are predefined if you redeclare them the probably won't do what you want it to do...

Hi Rob,

Thanks for the # advice. This is my whole code and I am stuck in getting it to work after seeing these error message.

sketch_aug28a.cpp: In function 'int main()':
sketch_aug28a:2: error: expected unqualified-id before 'volatile'
sketch_aug28a:2: error: expected `)' before 'volatile'
sketch_aug28a:2: error: expected `)' before 'volatile'
sketch_aug28a:2: error: expected initializer before 'volatile'
sketch_aug28a:3: error: expected unqualified-id before 'volatile'
sketch_aug28a:3: error: expected `)' before 'volatile'
sketch_aug28a:3: error: expected `)' before 'volatile'
sketch_aug28a:3: error: expected initializer before 'volatile'
sketch_aug28a:4: error: invalid type argument of 'unary *'
sketch_aug28a:9: error: invalid type argument of 'unary *'
int main(void)
{
	uint8_t* DDRB = (uint8_t*) 0x04;
	uint8_t* PORTB = (uint8_t*) 0x05;
	*DDRB |= 0x01; // Set bit 0 of port B to output direction
	for (;;) //infinite for loop
	{
		volatile unsigned int i;
		
		*PORTB ^= 0x01; // Toggle B0 using exclusive-OR
		
		i= 50000; // Delay
		do(i--);
		while(i!= 0);
	}
}

Why do you have a main() function, IFAIK this is already defined elsewhere when using the Arduino environment.

Stick this lot into setup() or loop().

also lose all the redefinition's of DDRB/PORTB. I think the preprocessor is converting them to numbers (the register IO addresses) so you wind up with something like this

uint8_t* 0x13 = (uint8_t*) 0x04;


Rob

PORTB isn't a pointer, don't dereference it.

This somewhat simplified version works on my Uno, flashing the D13 LED on and off:

void setup () {
  DDRB |= 0x20; // Set bit 5 of port B to output direction
}

void loop ()
{
  PORTB ^= 0x20; // Toggle B5 using exclusive-OR
  delay (200);
}

Thanks, Nick and Graynomad. I got what I need to move on.