Go Down

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

#### doaway

##### Mar 05, 2013, 06:20 amLast 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

Do you have any idea?  Thanks

void setup {
DDRD = B11111111;

}

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

#### Arrch

#1
##### Mar 05, 2013, 06:27 am
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

#2
##### Mar 05, 2013, 06:55 am
Thanks, but how to increment the portd value in the loop ?

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

#### Arrch

#3
##### Mar 05, 2013, 08:04 am

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

#4
##### Mar 05, 2013, 08:09 am

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 ?

#5
##### Mar 05, 2013, 08:16 am
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.

#6
##### Mar 05, 2013, 08:21 am

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.

#7
##### Mar 05, 2013, 08:26 am
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

#8
##### Mar 07, 2013, 07:38 pm

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.

#9
##### Mar 08, 2013, 03:40 am
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