Go Down

Topic: Rewiring the MSUFriend 2.4 inch lcd (Read 345 times) previous topic - next topic

Sjors123

Hello,

I want to rewire my display. I came across this thread;
https://forum.arduino.cc/index.php?topic=507694.0#main_content_section

They talk about having to edit mcufriend_special.h but i dont understand how i have to edit it. Becouse it seems like i can only select analog pins and those i want to free from the lcd.

Could anyone help me with this?

Thanks in advance

david_prentice

It is quite simple.

1.  write down on paper what you want to achieve.
2.  how many pins do you need?
3.  how many are Analog?
4.  what Arduino(s) do you have?
5.  do you have soldering iron?  Protoshield or protoboard?

Compose a message and post it here.    Imagine that you are a foreign reader.   Is it clear?

I will write the SPECIAL for you.

David.

Sjors123

Sorry if i didn supply enough information..

1. I want digital pin 12 to be the lcd reset (which is now A4) and digital pin 11 to be lcd RD (which is now A0)
2. I need 3 free analog pins to be able to use i2c on Analogpin 4 and 5 and one additional to measure battery voltage.
3. See 2.
4. I've got an Arduino Duemilenove
5. Yes i have my soldering iron waiting for me.. Currently im testing it on a breadboard.

Is it realy that complicated. I cant just enter those pins in special?

And i believe the sketch uses shield.h as default do i need to edit something else to?

david_prentice

Read the how_to file.  Enable the appropriate macros: USE_SPECIAL and USE_SJORS123

Add this block to the mcufriend_special.h
Code: [Select]

#elif defined(__AVR_ATmega328P__)  && defined(USE_SJORS123)
#warning using USE_SJORS123
#define RD_PORT PORTB
#define RD_PIN  3
#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 PORTB
#define RESET_PIN  4

#define BMASK         0x03              //more intuitive style for mixed Ports
#define DMASK         0xFC              //does exactly the same as previous
#define write_8(x)    { PORTB = (PORTB & ~BMASK) | ((x) & BMASK); PORTD = (PORTD & ~DMASK) | ((x) & DMASK); }
#define read_8()      ( (PINB & BMASK) | (PIND & DMASK) )
#define setWriteDir() { DDRB |=  BMASK; DDRD |=  DMASK; }
#define setReadDir()  { DDRB &= ~BMASK; DDRD &= ~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))



I strongly advise buying a protoshield.   Do any wire re-routeing on the Protoshield.

Untested.  I typed directly into the Browser.

David.

Sjors123


Sjors123

#5
Feb 22, 2018, 03:02 pm Last Edit: Feb 22, 2018, 03:21 pm by Sjors123
I did what it says in the mcufriend_how_to but i get errors like these:

error: #elif without #if
 #elif defined(__AVR_ATmega328P__)  && defined(USE_SJORS123)

and

error: #error MCU unsupported
 #error MCU unsupported

What am i doing wrong? Any idea?

I think i've put the code in the wrong place of de Special file. But if i put it right under
#elif defined(__AVR_ATmega328P__) && defined(USE_SSD1289_SHIELD_UNO)    //on UNO
i get even more error messeges about things being redefined.
Did i have to comment out something?

david_prentice

#6
Feb 22, 2018, 03:21 pm Last Edit: Feb 22, 2018, 03:32 pm by david_prentice
Study the existing structure of mcufriend_special.h

There are list of #defines   (you should define your USE_SJORS123 here)

followed by a long #if 0 #elif #elif ... #endif block

You should just insert your #elif sequence into the existing block.

The preprocessor #elif operator is very convenient for adding / removing conditional sequences.
The #if 0 ensures that all the subsequent sequences can just start with #elif (SPECIAL_CONDITION)
an #else can catch anything that fails every #elif (CONDITION)
or the #endif just lets it fall through.

The original aim of this library was to support multiple controllers that might appear on standard Uno shields.

If you want to hack the hardware,  you must be prepared to do a bit of software homework too.

Your "goal" would be more easily achieved by doing the typical "LCD_RST" hardware mod and using A6, A7 for Analog Sensors.   (A6, A7 are available on SMT Uno clones)
 
David.

Sjors123

Oke thanks for the input. I mannaged to get it to work by uncommenting "#define SSD1289_JUMPERS 2" in Special and putting the code you gave me above:
"#elif defined(__AVR_ATmega328P__) && defined(USE_SSD1289_SHIELD_UNO)    //on UNO" so that the elif of the new code turns blue.. Which means active i guess. Sounds dumb maybe? But it works. Nice


david_prentice

#8
Feb 22, 2018, 06:17 pm Last Edit: Feb 22, 2018, 07:54 pm by david_prentice
You did not follow my advice.

Study how the conditional code works.

The condition is only true when the correct MCU is  compiled with the correct define.
If none of the special #elif conditions are true it falls through to the regular standard code in mcufriend_shield.h

David.

Edit.  This is where you put the USE_SJORS123 lines:
Code: [Select]

#define SSD1289_JUMPERS 2       //Uno Shield with VERY different pin-out to Mcufriend
// only define one "USE_XXX" macro at any time
#define USE_SJORS123
//#define USE_SSD1289_SHIELD_UNO
//#define USE_SSD1289_SHIELD_MEGA
...
#if 0
#elif defined(__AVR_ATmega328P__)  && defined(USE_SJORS123)
#warning using USE_SJORS123
#define RD_PORT PORTB
#define RD_PIN  3
#define WR_PORT PORTC
...
#elif defined(__AVR_ATmega328P__) && defined(USE_SSD1289_SHIELD_UNO)    //on UNO
#warning using SSD1289 Shield for mega328
...

Go Up