Screen compatibility

Advice on general approaches or feasibility and discussions about game design

Screen compatibility

Postby ProCoder » Sun May 25, 2014 6:57 pm

Hi another question :) I am wanting to build a gamebuino for the time until I can get the real one! But I am wondering is there any way I could possibly get this screen to work in place of the Nokia 5110 one? Here is a link to it http://www.radioshack.com/product/index ... d=12688460
ProCoder
 
Posts: 33
Joined: Sat May 24, 2014 3:34 pm

Re: Screen compatibility

Postby ripper121 » Sun May 25, 2014 7:31 pm

Yes you have only to Change the display commands.
User avatar
ripper121
 
Posts: 224
Joined: Fri Apr 04, 2014 2:02 pm
Location: Germany

Re: Screen compatibility

Postby ProCoder » Sun May 25, 2014 7:39 pm

Sorry I am very basic in this but can you possibly help me with that? I am going to go and pick it up right now.

EDIT: I have now decided to return it :P Thanks for the help though! But I felt it wasnt worth it and was not as useful of a display either.
ProCoder
 
Posts: 33
Joined: Sat May 24, 2014 3:34 pm

Re: Screen compatibility

Postby ripper121 » Mon May 26, 2014 8:27 am

Look in the Gamebuino Libary folder there is a Display.cpp.
You have to replace the display commands in it with the commands for your display.
For the first step, i would to try to init the display and set a pixel.

I think to change this functions to yours is all what is to do:

Code: Select all
void Display::begin(int8_t SCLK, int8_t DIN, int8_t DC, int8_t CS, int8_t RST) {
    din = DIN;
    sclk = SCLK;
    dc = DC;
    rst = RST;
    cs = CS;

    cursor_y = cursor_x = 0;
    textsize = 1;
    color = BLACK;
   bgcolor = WHITE;
    wrap = true;
   persistence = false;

    SPI.begin();
    SPI.setBitOrder(MSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV8); //can be set to 4 but some random pixels will start to appear on some displays
    SPI.setDataMode(SPI_MODE3);
    // set pin directions
    pinMode(din, OUTPUT);
    pinMode(sclk, OUTPUT);
    pinMode(dc, OUTPUT);
    if (rst > 0)
        pinMode(rst, OUTPUT);
    if (cs > 0)
        pinMode(cs, OUTPUT);

    // toggle RST low to reset
    if (rst > 0) {
        digitalWrite(rst, LOW);
        delay(5);
        digitalWrite(rst, HIGH);
    }

    clkport = portOutputRegister(digitalPinToPort(sclk));
    clkpinmask = digitalPinToBitMask(sclk);
    mosiport = portOutputRegister(digitalPinToPort(din));
    mosipinmask = digitalPinToBitMask(din);
    csport = portOutputRegister(digitalPinToPort(cs));
    cspinmask = digitalPinToBitMask(cs);
    dcport = portOutputRegister(digitalPinToPort(dc));
    dcpinmask = digitalPinToBitMask(dc);

    // get into the EXTENDED mode!
    command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION);

    // LCD bias select (4 is optimal?)
    command(PCD8544_SETBIAS | 0x4);

    // set VOP
    if (contrast > 0x7f)
        contrast = 0x7f;

    command(PCD8544_SETVOP | contrast); // Experimentally determined


    // normal mode
    command(PCD8544_FUNCTIONSET);

    // Set display to Normal
    command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);

    // initial display line
    // set page address
    // set column address
    // write display data

    update();
}

void Display::command(uint8_t c) {
    noInterrupts();
    digitalWrite(dc, LOW);
    if (cs > 0)
        digitalWrite(cs, LOW);
    SPI.transfer((char) c);
    if (cs > 0)
        digitalWrite(cs, HIGH);
    interrupts();
}

void Display::data(uint8_t c) {
    noInterrupts();
    digitalWrite(dc, HIGH);
    if (cs > 0)
        digitalWrite(cs, LOW);
    SPI.transfer((char) c);
    if (cs > 0)
        digitalWrite(cs, HIGH);
    interrupts();
}

void Display::setContrast(uint8_t val) {
   contrast = constrain(val, 30, 80);
    /*if (contrast > 0x7f) {
        contrast = 0x7f;
    }*/
    command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION);
    command(PCD8544_SETVOP | contrast);
    command(PCD8544_FUNCTIONSET);

}

void Display::clear(void) {
    memset(_displayBuffer, 0, LCDWIDTH * LCDHEIGHT / 8);
    cursor_y = cursor_x = 0;
}

void Display::fillScreen(uint8_t color) {
    memset(_displayBuffer, 0xFFFF, LCDWIDTH * LCDHEIGHT / 8);
}

void Display::update(void) {
    uint8_t col, maxcol, p;

    for (p = 0; p < 6; p++) {

        command(PCD8544_SETYADDR | p);

        // start at the beginning of the row
        col = 0;
        maxcol = LCDWIDTH_NOROT - 1;

        command(PCD8544_SETXADDR | col);

        digitalWrite(dc, HIGH);
        if (cs > 0)
            digitalWrite(cs, LOW);
        for (; col <= maxcol; col++) {
            SPI.transfer(_displayBuffer[(LCDWIDTH_NOROT * p) + col]);
        }

        if (cs > 0)
            digitalWrite(cs, HIGH);

    }

    command(PCD8544_SETYADDR); // no idea why this is necessary but it is to finish the last byte?
}
User avatar
ripper121
 
Posts: 224
Joined: Fri Apr 04, 2014 2:02 pm
Location: Germany


Return to Project Guidance & Game development

Who is online

Users browsing this forum: Google [Bot] and 95 guests

cron