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 (; //infinite for loop
{
volatile unsigned int i;
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
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);
}