Send 10 bits of data via paralel interface

Hi,

I am trying to send 10 bit of data to an external microcontroller using parallel interface.
This means using one digital pin for every bit of data.

I know on the Atmel I could just say PORTC = XXXXXXXX with an 8 bit value, but I have two questions now:

First I would have to set two output ports, say port b and port c and place parts of the result on each port.
Second, suppose on port b I was using two pins for something else.

How would I assign each of the individual bits to a particular output pin?

For example:

I read 10 bits from the ADC. How do i select a port to send each of them?

Thanks

If you save the value from the ADC in an INT variable you can then use a combination of shifting and masking to identify each bit

for example

adcValue = analogRead(A0);
 int tempVal = adcValue;
for (byte n = 0; n < 10; n++) {
    int bitVal = tempVal & 0b0000000000000001;  // all but the rightmost bit are hidden
     // do something with bitVal
    tempVal = tempVal >> 1; // move everything one bit to the right
}

...R

Robin2:
If you save the value from the ADC in an INT variable you can then use a combination of shifting and masking to identify each bit

for example

adcValue = analogRead(A0);

int tempVal = adcValue;
for (byte n = 0; n < 10; n++) {
    int bitVal = tempVal & 0b0000000000000001;  // all but the rightmost bit are hidden
     // do something with bitVal
    tempVal = tempVal >> 1; // move everything one bit to the right
}




...R

The data source is actually a frequency measurement stored in a variable caled Frequency.

So I guess i could do

 int tempVal = Frequency
for (byte n = 0; n < 10; n++) {
    int bitVal = tempVal & 0b0000000000000001;  // all but the rightmost bit are hidden
     // do something with bitVal
    tempVal = tempVal >> 1; // move everything one bit to the right
}

But then how would I assign this data to my individual pin ports? Say pin 6,7,8,9,10,11,12,13,A0,A1 for example.

Use arrays.

byte pinArray[] = {6,7,8,9,10,11,12,13,14,15,};

for (byte n = 0; n < 10; n++) {
    int bitVal = tempVal & 0b0000000000000001;  // all but the rightmost bit are hidden
     // do something with bitVal:
     if (bitVal == 1){ digitalWrite(pinArray[n], HIGH); } 
     else {digitalWrite (pinArray[n], LOW); }
    tempVal = tempVal >> 1; // move everything one bit to the right
}

@CrossRoads, I admire your patience.

@Casemod - has this Thread anything to do with the other Thread that you have running at the moment?

...R

Robin2:
@CrossRoads, I admire your patience.

He did a nice job explaining didnt he?

Robin2:
@Casemod - has this Thread anything to do with the other Thread that you have running at the moment?

...R

Different project. I want to send some data to another microcontroller. Why the question?

casemod:
Different project. I want to send some data to another microcontroller. Why the question?

There was a lot of confusion in the other Thread and I thought if this was the same project that merging them might help on both sides.

...R