Go Down

Topic: Questions using Portd register!! (Read 601 times) previous topic - next topic

doaway

Mar 05, 2013, 06:20 am Last Edit: Mar 05, 2013, 06:24 am by doaway Reason: 1
Hi all, I want to  write a data to a memory with different addresses.  From B00000000 to B11111111 in order.

How can I use portd to change the address with every 50ms? or other way ?

If I manually write PORTD from 00000000 to 11111111, it will take 2 days to be done, and I can not do any thing during the delay because I need

to read the data back from different addresses after writing.

Do you have any idea?  Thanks

void setup {
DDRD = B11111111;

}

void loop{
PORTD = B00000000;
delay(50); // ???
PORTD = B00000001;
.
.
.
.
PORTD = B11111111;
}

Arrch

I'm not sure where this "2 days" comes into play; incrementing PORTD every 50 mS will take about 13 seconds to complete.

Start with the Blink Without Delay example. Every time the if statement fires, increment a variable and assign the value of the variable to PORTD.

doaway

Thanks, but how to increment the portd value in the loop ?

if(currentMillis - previousMillis > 50) {
     previousMillis = currentMillis;
     PORTD = ??
}

Arrch


Thanks, but how to increment the portd value in the loop ?

if(currentMillis - previousMillis > 50) {
     previousMillis = currentMillis;
     PORTD = ??
}


How do you normally increment a variable?

doaway



Thanks, but how to increment the portd value in the loop ?

if(currentMillis - previousMillis > 50) {
     previousMillis = currentMillis;
     PORTD = ??
}


How do you normally increment a variable?


i = i +1 , but the number is a binary number not a integer. how to increment a binary number ?

CrossRoads

byte i;

i=i+1;
PORTD = i;
if (i==255){i=0;}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Cookies


if (i==255){i=0;}


Why not let it overflow back to 0 on its own? That code will also skip 0, unless that's what you want.

CrossRoads

I guess rollover would work too.

\

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

doaway


byte i;

i=i+1;
PORTD = i;
if (i==255){i=0;}


Thanks, if I want the program stop when PORTD = B11111111, do not what it run over and over, because I need to println data.


CrossRoads

if (i==255){
Serial.println (whatever);
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy