I am reading the Adafruit_TFTLCD library source code and saw this line. I realize the PORTD is read
then assigned partially with some bits in d, then written to the port.
I wonder whether that would overwrite the values on UART and other pins not used by the LCD and cause race condition with other part of the sketch?
One related question. If I need one of the GPIO pins used by the LCD and don't care much about the color resolution. Can I just mask out the d[0] on the PORTB assignment?
// Write 8-bit value to LCD data lines
#define write8inline(d) { \
PORTD = (PORTD & B00101111) | ((d) & B11010000); \
PORTB = (PORTB & B11010000) | ((d) & B00101111); \
WR_STROBE; } // STROBEs are defined later
You can use the Serial pins. A Terminal will show complete garbage when you write data to the TFT.
The bootloader might have difficulties unless you ensure the TFT is not selected.
If you don't care about the Serial, write will win. However read will almost always fail.
Several TFT Shields and Libraries use D0-D7 for the data bus. Your Shield is designed to use D8,D9, D2-D7.
David,
thank you david_prentice.
I believe the second question is not able to work becuase the parallel pins carry both command and data.
Still wondering about the first question, does compiler make the whole line a single clock cycle and deprive other codes the chance to write?
PORTD = (PORTD & B00101111) | ((d) & B11010000);
You must connect all 8 data bus pins and all 5 control pins and 3.3V pin and 5V pin and GND.
God provides all the female header sockets on your Arduino. The corresponding male pins mate with them.
PORTD = (PORTD & B00101111) | ((d) & B11010000);
The Compiler will generate the appropriate ASM code to satisfy your valid C statement. It will probably be about 5 ASM instructions. Why do you care? I certainly don't.
Yes, if you want to do SPECIAL wiring, you must edit lines like in your example.
David.
the reason i ask is when the uart sends or receives a bit during that 5 instructions, the LCD code may overwrite that bit and cause a failure in uart. I am wondering whether compiler does some mitigations on the small compilers, which may be different from the arm compilers i use?