Go Down

Topic: Nokia LCD shield & Arduino Mega via software S (Read 1 time) previous topic - next topic

Inopia

Sep 25, 2009, 12:38 am Last Edit: Sep 25, 2009, 12:39 am by niels.brouwers Reason: 1
Hi all,

I recently got one of those nifty color LCD screen shield from nuelectronics, and was disappointed to find out it didn't work out of the box because the SPI pins on the Arduino Mega are at a different location. I found some hardware rewiring hacks but I felt a pure software fix would be more elegant.

So I fixed the library so that it makes use of software SPI, using pins 10, 11, 12 and 13 for SS, MOSI, MISO and SCK respectively. I'm pleased to say it works like a charm.

Basically you'll need to go into PCF8833.h and redefine the pins so that it reads:

Code: [Select]

#define LCD_CS(x)           PORTB = (x)? (PORTB|(1<<PB4)) : (PORTB&~(1<<PB4))
#define LCD_CLK(x)          PORTB = (x)? (PORTB|(1<<PB7)) : (PORTB&~(1<<PB7))
#define LCD_DATA(x)         PORTB = (x)? (PORTB|(1<<PB5)) : (PORTB&~(1<<PB5))
#define LCD_RESET(x)        PORTH = (x)? (PORTH|(1<<PH6)) : (PORTH&~(1<<PH6))
#define LCD_BACKLIGHT(x)    PORTH = (x)? (PORTH|(1<<PH5)) : (PORTH&~(1<<PH5))


Then in PCF8833.c change the SendColor and SendLCD functions to read

Code: [Select]


void SendLcd_color(unsigned char color)
{
     unsigned char i;

     LCD_DATA(LCDData); // set up first bit as command or data

     LCD_CLK(0); // Pull Clock LOW
     LCD_CLK(1); // Pul Clock HIGH

     // clock over the byte
     for (i=0; i<8; i++)
     {
           LCD_DATA(color & 0x80);
           color <<= 1;

           LCD_CLK(0); // Pull Clock LOW
           LCD_CLK(1); // Pul Clock HIGH
     }
}

void SendLcd(unsigned char type, unsigned char dat)
{
     unsigned char i;

     LCD_DATA(type); // set up first bit as command or data
     LCD_CS(0); // Enable device CS

     LCD_CLK(0); // Pull Clock LOW
     LCD_CLK(1); // Pul Clock HIGH

     // clock over the byte
     for (i=0; i<8; i++)
     {
           LCD_DATA(dat & 0x80);
           dat <<= 1;

           LCD_CLK(0); // Pull Clock LOW
           LCD_CLK(1); // Pul Clock HIGH
     }

     LCD_CS(1);
}


This was a quick hack and it's late so I may have messed up somewhere, but I think this should do it.

Cheers,

- Niels


TeamMCS

Well done, I wish NuElectronics would take this onboard. They're good on the hardware side but piss poor on the software side.

I may try this for the black+white version

Go Up