Reassign tft pin

Hi, i really don't understand how to change lcd_d1 from 9 to 12 on my arduino tft
I really don't understand the code on mcufriend_shield.h

I found this default code but i don't understand how to jump the pin 9 to the 12.
Please help me, i really would like to understand.

#elif defined(__AVR_ATmega328P__)       //regular UNO shield on UNO
#define RD_PORT PORTC
#define RD_PIN  0
#define WR_PORT PORTC
#define WR_PIN  1
#define CD_PORT PORTC
#define CD_PIN  2
#define CS_PORT PORTC
#define CS_PIN  3
#define RESET_PORT PORTC
#define RESET_PIN  4

#define DMASK         0x03
#define NMASK         ~DMASK
#define write_8(x)    { PORTB = (PORTB & NMASK) | ((x) & DMASK); PORTD = (PORTD & DMASK) | ((x) & NMASK); }
#define read_8()      ( (PINB & DMASK) | (PIND & NMASK) )

#define setWriteDir() { DDRB = (DDRB & NMASK) | DMASK; DDRD = (DDRD & DMASK) | NMASK;  }
#define setReadDir()  { DDRB = (DDRB & NMASK) & NMASK; DDRD = (DDRD & DMASK) & DMASK;  }
#define write8(x)     { write_8(x); WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; dst = read_8(); RD_IDLE; }
#define READ_16(dst)  { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

#define PIN_LOW(p, b)        (p) &= ~(1<<(b))
#define PIN_HIGH(p, b)       (p) |= (1<<(b))
#define PIN_OUTPUT(p, b)     *(&p-1) |= (1<<(b))

Welcome. Thanks for using code tags. Please take another look at the forum instructions and try again. That is not nearly enough information.

God invented Shields for a reason.

You plug a Shield into a Uno, Leo, Mega, Due, Nucleo, ...
All the signals connect correctly. You have a reliable mechanical combination too !

Why do you want to re-assign LCD_D1 signal ?
It means that you have to cut pins from the display shield.

If you have a valid reason, I will write the appropriate SPECIAL for you. This goes into the "mcufriend_special.h" file and not the "mcufriend_shield.h" (which is intended for plug-in shields)

David.

So in fact i need to re-assign LCD_D1 because it's PWM pin and i need 3 of them..
So far i got 2 PWM pins but i really need a third one.
The 9 would be perfect because i already use the 10 and 11 but any other PWM pin would be fine for me.

I've linked the shield to the arduino uno with small wires altough it's recommended to connect the shorter way.

That would be really nice if you could write me a special but if you could help me understand how it works that would be great, anyway if it's too hard to explain shortly, i would understand if you don't wan't to teach me.

Have a great day.

Unfortunately not.

Not sure about the others yet, but on the UNO, pins 3,5 and 6 are PWM capable. That's 3 PWM.

Re #6. Look at the mega328P datasheet for OCnx pins.
PD3
PD5
PD6
PB0
PB1
PB2

Re #5. Uno, Leo, Mega, Due, Nucleo, ... all have header sockets that receive the Display Shield. (Or any standard Uno Shield)
That is why Shields were invented.

David.

Then you should specify, "most display shields". Because, some display shields, and many other types of shield will not work on all of those boards.

In many cases, certain pins are assigned differently, have different internal CPU functions, and/or operate on different voltages.

A TFT with an 8-bit databus needs those 4 functions to write or read 8-bits to the appropriate port pins.

In an ideal world, you could reserve a full Port e.g. PORTA on a Mega2560

#define write_8(x)    { PORTA = (x); }
#define read_8()      ( PINA)

#define setWriteDir() { DDRA = 0xFF;  }
#define setReadDir()  { DDRA = 0x00;  }

Because the Uno uses PD0, PD1 for Serial, you have to use PB0-PB1 and PD2-PD7 for the 8-bit bus. And use the appropriate bit masks e.g.

#define DMASK         0x03    //0b00000011
#define NMASK         ~DMASK  //0b11111100

Other Arduinos have different Port pins on the Arduino headers. Which is why the Mega2560 macros are so complicated (and SLOW).

DMASK and NMASK are historic names. BMASK and DMASK would be more intuitive.

David.

Ok, that clearly helped me understanding some parts of the code but if i understand i'm forced to use specific pins on the uno? Or i could change the PB0 to PB4 ?
I don't understand how it could be possible with a mask. I tried to modify these but that's not working.

You asked for 3 other PWM pins. I showed you them, but haven't seen any comment from you...

Yes i saw that but i don't understand why it should help me, i already know that those are PWM but the Shield is using them. So in any case i need to change one of them.

Yes, you understand that.
Yes, I understand that.
No, aarg does not understand that.

Edit mcufriend_special.h
#define USE_BLUEHOWL_UNO
Insert this conditional block :

#elif defined(__AVR_ATmega328P__) && defined(USE_BLUEHOWL_UNO)
//LCD pins  |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST|
//AVR   pin |PD7|PD6|PD5|PD4|PD3|PD2|PB4|PB0| |PC0|PC1|PC2|PC3|PC4|
//UNO pins  |7  |6  |5  |4  |3  |2  |12 |8  | |A0 |A1 |A2 |A3 |A4 |
#define RD_PORT PORTC
#define RD_PIN  0
#define WR_PORT PORTC
#define WR_PIN  1
#define CD_PORT PORTC
#define CD_PIN  2
#define CS_PORT PORTC
#define CS_PIN  3
#define RESET_PORT PORTC
#define RESET_PIN  4

#define BMASK         B00010001
#define DMASK         B11111100

#define write_8(x) {                          \
        PORTD = (PORTD & ~DMASK) | ((x) & DMASK); \
        PORTB = (PORTB & ~BMASK) | ((x) & 0x01) | (((x) & 0x02) << 3);} // STROBEs are defined later

#define read_8()   ((PIND & DMASK) | (PINB & 0x01) | ((PINB & 0x10) >> 3))

#define setWriteDir() { DDRD |=  DMASK; DDRB |=  BMASK; }
#define setReadDir()  { DDRD &= ~DMASK; DDRB &= ~BMASK; }


#define write8(x)     { write_8(x); WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; dst = read_8(); RD_IDLE; }
#define READ_16(dst)  { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

#define PIN_LOW(p, b)        (p) &= ~(1<<(b))
#define PIN_HIGH(p, b)       (p) |= (1<<(b))
#define PIN_OUTPUT(p, b)     *(&p-1) |= (1<<(b))

Follow the how_to rules for using a SPECIAL.

Untested.

David.

1 Like

Thank you so much you made my day, it's working perfectly, i figured out how to use a special and this worked perfectly.
I really thank you. :grinning_face_with_smiling_eyes: