NHD-0420CW With PIC32MX Controller

Comments

6 comments

  • Paul_B

    Hello Docmur,

    Thank you for reaching out, can you please post your full pin-out.

    Based on the configuration you listed below it would appear that you have forgotten to Gnd BS0-BS2 (MPU interface pin selection).

    Next, your LCD init function does not appear to be complete. I recommend taking a look the the following example Arduino code for that particular display.

    https://github.com/NewhavenDisplay/NHD_US2066

    Hope this helps!

    0
  • docmur

    Hey Paul
    Thanks for your reply. 

    I've attached the schematic of how we hooked up the LCD, BS0-3 are grounded.


    Image: http://postimg.org/image/rg78l29gp/
    Below is my full init routine:

    void init_lcd(void)
    {
        LCD_SS_TRIS = 0;
        LCD_SS = 1;

        delay_10us(10000);
        LCD_SS = 0;

        writeSPI1(0x2A); //function set (extended command set)
        writeSPI1(0x71); //function selection A
        writeSPI1(0x03); // disable internal VDD regulator (2.8V I/O). data(0x5C) = enable regulator (5V I/O)
        writeSPI1(0x28); //function set (fundamental command set)
        writeSPI1(0x08); //display off, cursor off, blink off
        writeSPI1(0x2A); //function set (extended command set)
        writeSPI1(0x79); //OLED command set enabled
        writeSPI1(0xD5); //set display clock divide ratio/oscillator frequency
        writeSPI1(0x70); //set display clock divide ratio/oscillator frequency
        writeSPI1(0x78); //OLED command set disabled
        writeSPI1(0x09); //extended function set (4-lines)
        writeSPI1(0x06); //COM SEG direction
        writeSPI1(0x72); //function selection B
        writeSPI1(0x00); //ROM CGRAM selection
        writeSPI1(0x2A); //function set (extended command set)
        writeSPI1(0x79); //OLED command set enabled
        writeSPI1(0xDA); //set SEG pins hardware configuration
        writeSPI1(0x10); //set SEG pins hardware configuration
        writeSPI1(0xDC); //function selection C
        writeSPI1(0x10); //function selection C
        writeSPI1(0x81); //set contrast control
        writeSPI1(0x7F); //set contrast control
        writeSPI1(0xD9); //set phase length
        writeSPI1(0xF1); //set phase length
        writeSPI1(0xDB); //set VCOMH deselect level
        writeSPI1(0x40); //set VCOMH deselect level
        writeSPI1(0x78); //OLED command set disabled
        writeSPI1(0x28); //function set (fundamental command set)
        writeSPI1(0x01); //clear display
        writeSPI1(0x80); //set DDRAM address to 0x00
        writeSPI1(0x0F); //display ON
        LCD_SS = 1;
        delay_10us(10000);

    }

    void output()
    {
        int i;
        writeSPI1(0x01); //clear display
        writeSPI1(0x02); //return home

        for(i=0;i<20;i++)
        {
            writeSPI1(0x1F); //write solid blocks
        }

        writeSPI1(0xA0); //line 2
        for(i=0;i<20;i++)
        {
            writeSPI1(0x1F); //write solid blocks
        }

        writeSPI1(0xC0); //line 3
        for(i=0;i<20;i++)
        {
            writeSPI1(0x1F); //write solid blocks
        }

        writeSPI1(0xE0); //line 4
        for(i=0;i<20;i++)
        {
            writeSPI1(0x1F); //write solid blocks
        }
    }

    unsigned char writeSPI1(unsigned char byte ){
        /* Make sure the module has been configured */
        if( spi1Config == false ){
            /* Configure the bus -- It's not configured -- */
            init_spi1();
        }
        /* Write the byte to the buffer */
        SPI1BUF = byte;
        /* Wait for the transmission to complete */
    #ifndef __SIMULATION
        while( !SPI1STATbits.SPIRBF);
    #endif
        /* Clear the buffer by reading it - REQUIRED! */
        return SPI1BUF;
    }
     
     
    0
  • Paul_B

    Excellent, thank you for the clean wiring diagram  

    The good news is that your wiring is correct, the issue must be within your code.
    Your initialization appears to be correct, I suspect the problem is how your SPI is configured.

    SPI Example:

    case 2:   
                  temp = 0xF8;
                  for(i=0;i<8;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((temp&0x80)>>7==1)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    temp = temp << 1;
                    digitalWrite(SCLK, HIGH);
                  }
     
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((c&0x01)==1)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    c = c >> 1;
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    digitalWrite(SDIN, LOW);
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((c&0x01)==1)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    c = c >> 1;
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    digitalWrite(SDIN, LOW);
                    digitalWrite(SCLK, HIGH);
                  }
                  break;
      }

    If you have an oscilloscope on hand I highly recommend checking your data lines and posting some screen shots.

    0
  • docmur

    Done give me a second :-)

    Clock Signal Isolated

    http://postimg.cc/image/fy50lsesv/ 

    Data Signal Isolated

    http://postimg.cc/image/h8f71y4yb/ 

    Clock and Data

    http://postimg.cc/image/5epyma6zp/e82e3a85/ 

    Clock and Data Single Byte

    http://postimg.cc/image/a2f4nh2kd/ 

    Clock and SS

    http://postimg.cc/image/wkq9616vz/ 

    Data and SS

    http://postimg.cc/image/hf1nutk4h/ 

    And finally What I was sending to grab the images

        LCD_SS = 0;
        writeSPI1(0x01); //clear display
        writeSPI1(0x02); //return home
        writeSPI1(0x1F);
        LCD_SS = 1;

    0
  • richardms

    Hi Docmur,

    I'm experiencing something very similar (and it's very frustrating!) - did you get any further?

    Regards
    Richard

    0
  • richardms

    It's OK, found the problem. I was sending the sync byte lsb first, as well as the data.

    0

Please sign in to leave a comment.