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?
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
}
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.
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
}