Hi,
I wrote some code which reads info from sd card and the purpose is that the arduino should now be able to output the 8 bits to portpins on the atmega328 from the arduino uno.
As far as I can see (I use the SPI pins for the SD reading and I also use TX and RX for some other part of the code + I might use INT0 later on) the only pins left are
PC0 AVR pin 23
PC1 AVR pin 24
PC2 AVR pin 25
PC3 AVR pin 26
PC4 AVR pin 27
PC5 AVR pin 28
PD3 AVR pin 5
PD4 AVR pin 6
PD5 AVR pin 11
PD6 AVR pin 12
PD7 AVR pin 13
PB0 AVR pin 14
I have to push the 8 bits data over 8 of these pins
Looking at the available pins, I would guess that it could be interesting to output 6 of the 8 bits on PC0->PC5 and then maybe the other 2 bits to PD6->PD7
But can somebody help me a little by saying how I could do this?
I guess I need to do something like
[pseudocode below]
IF (bit1=1) {digitalWrite(portC0pin,HIGH); // send 1}
ELSE{digitalWrite(portC0pin,LOW); // send 0}
IF (bit2=1) {digitalWrite(portC1pin,HIGH); // send 1}
ELSE{digitalWrite(portC1pin,LOW); // send 0}
IF (bit3=1) {digitalWrite(portC2pin,HIGH); // send 1}
ELSE{digitalWrite(portC2pin,LOW); // send 0}
IF (bit4=1) {digitalWrite(portC3pin,HIGH); // send 1}
ELSE{digitalWrite(portC3pin,LOW); // send 0}
IF (bit5=1) {digitalWrite(portC4pin,HIGH); // send 1}
ELSE{digitalWrite(portC4pin,LOW); // send 0}
IF (bit6=1) {digitalWrite(portC5pin,HIGH); // send 1}
ELSE{digitalWrite(portC5pin,LOW); // send 0}
IF (bit7=1) {digitalWrite(portD6pin,HIGH); // send 1}
ELSE{digitalWrite(portD6pin,LOW); // send 0}
IF (bit8=1) {digitalWrite(portD7pin,HIGH); // send 1}
ELSE{digitalWrite(portD7pin,LOW); // send 0}
But how can I quickly check if a certain bit it set or not in a byte variable ?
Also, I guess I'll better setup a faster digitalWrite then the standard arduino built in function, since I read somewhere that digitalWrite can take upto 200 cpu cycles where a direct port pin manipulation is a lot faster?
Any help, hints would be very appreciated.
Kind regards and thanks,
Bart