Pages: [1]   Go Down
Author Topic: Questions using Portd register!!  (Read 448 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
}
 
« Last Edit: March 05, 2013, 12:24:34 am by doaway » Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 435
Posts: 23597
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

byte i;

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 435
Posts: 23597
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess rollover would work too.

\

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 1
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 435
Posts: 23597
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

if (i==255){
Serial.println (whatever);
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: