Newhaven Display Forum

Newhaven Products => Graphic LCDs => Topic started by: Ipsum on November 30, 2014, 09:29:51 PM

Title: NHD-C160100DiZ-FSW-FBW w/PIC18F47J53
Post by: Ipsum on November 30, 2014, 09:29:51 PM
Hi,

I normally don't make these posts but was having a bit of trouble driving this display and figured maybe someone could help. Basically, I am having trouble displaying anything at all on the LCD. I am using the initialization routine found in the datasheet for the NHD-C160100DiZ-FSW-FBW and trying to write the all pixels on instruction to turn the display black.

There is I2C communication since the LCD is pulling the line low in the ack clock pulse after every byte. I can also tell that the oscillator turns on. What I want to know is there some command that I am missing that will display anything at all on the LCD?
Code: [Select]
//LCD.c
#include <xc.h>
#define _XTAL_FREQ 8000000
#include "I2C_BB.h"
#define SLAVE_ADDRESS 0x7E
#define COM_SEND 0x00
#define DATA_SEND 0x40

void init_lcd(void)
{
    I2C_ST();
    I2C_OUT(SLAVE_ADDRESS);
    I2C_OUT(0x00);
    I2C_OUT(0x48); //partial display duty ratio
    I2C_OUT(0x64); // 1/100 duty
    I2C_OUT(0xA0); //ADC select
    I2C_OUT(0xC8); //SHL select
    I2C_OUT(0x44); //initial Com0 register
    I2C_OUT(0x00); //scan from Com0
    I2C_OUT(0xAB); //OSC on
    I2C_OUT(0x26); //
    I2C_OUT(0x81); //set electronic volume
    I2C_OUT(0x15); //vopcode=0x1C
    I2C_OUT(0x56); //set 1/11 bias
    I2C_OUT(0x64); //3x
    __delay_ms(50);
    __delay_ms(50);
    __delay_ms(50);
    __delay_ms(50);
    I2C_OUT(0x2C); //
    I2C_OUT(0x66); //5x
    __delay_ms(50);
    __delay_ms(50);
    __delay_ms(50);
    __delay_ms(50);
    I2C_OUT(0x2E); //
    __delay_ms(10);
    I2C_OUT(0x2F); //power control
    I2C_OUT(0xF3); //bias save circuit
    I2C_OUT(0x00); //
    I2C_OUT(0x96); //frc and pwm
    I2C_OUT(0x38); //external mode
    I2C_OUT(0x75); //
    I2C_OUT(0x97); //3frc, 45 pwm
    I2C_OUT(0x80); //start 16-level grayscale settings
    I2C_OUT(0x00); //
    I2C_OUT(0x81); //
    I2C_OUT(0x00); //
    I2C_OUT(0x82); //
    I2C_OUT(0x00); //
    I2C_OUT(0x83); //
    I2C_OUT(0x00); //
    I2C_OUT(0x84); //
    I2C_OUT(0x06); //
    I2C_OUT(0x85); //
    I2C_OUT(0x06); //
    I2C_OUT(0x86); //
    I2C_OUT(0x06); //
    I2C_OUT(0x87); //
    I2C_OUT(0x06); //
    I2C_OUT(0x88); //
    I2C_OUT(0x0B); //
    I2C_OUT(0x89); //
    I2C_OUT(0x0B); //
    I2C_OUT(0x8A); //
    I2C_OUT(0x0B); //
    I2C_OUT(0x8B); //
    I2C_OUT(0x0B); //
    I2C_OUT(0x8C); //
    I2C_OUT(0x10); //
    I2C_OUT(0x8D); //
    I2C_OUT(0x10); //
    I2C_OUT(0x8E); //
    I2C_OUT(0x10); //
    I2C_OUT(0x8F); //
    I2C_OUT(0x10); //
    I2C_OUT(0x90); //
    I2C_OUT(0x15); //
    I2C_OUT(0x91); //
    I2C_OUT(0x15); //
    I2C_OUT(0x92); //
    I2C_OUT(0x15); //
    I2C_OUT(0x93); //
    I2C_OUT(0x15); //
    I2C_OUT(0x94); //
    I2C_OUT(0x1A); //
    I2C_OUT(0x95); //
    I2C_OUT(0x1A); //
    I2C_OUT(0x96); //
    I2C_OUT(0x1A); //
    I2C_OUT(0x97); //
    I2C_OUT(0x1A); //
    I2C_OUT(0x98); //
    I2C_OUT(0x1E); //
    I2C_OUT(0x99); //
    I2C_OUT(0x1E); //
    I2C_OUT(0x9A); //
    I2C_OUT(0x1E); //
    I2C_OUT(0x9B); //
    I2C_OUT(0x1E); //
    I2C_OUT(0x9C); //
    I2C_OUT(0x23); //
    I2C_OUT(0x9D); //
    I2C_OUT(0x23); //
    I2C_OUT(0x9E); //
    I2C_OUT(0x23); //
    I2C_OUT(0x9F); //
    I2C_OUT(0x23); //
    I2C_OUT(0xA0); //
    I2C_OUT(0x27); //
    I2C_OUT(0xA1); //
    I2C_OUT(0x27); //
    I2C_OUT(0xA2); //
    I2C_OUT(0x27); //
    I2C_OUT(0xA3); //
    I2C_OUT(0x27); //
    I2C_OUT(0xA4); //
    I2C_OUT(0x2B); //[14]
    I2C_OUT(0xA5); //
    I2C_OUT(0x2B); //
    I2C_OUT(0xA6); //
    I2C_OUT(0x2B); //
    I2C_OUT(0xA7); //
    I2C_OUT(0x2B); //
    I2C_OUT(0xA8); //
    I2C_OUT(0x2F); //
    I2C_OUT(0xA9); //
    I2C_OUT(0x2F); //
    I2C_OUT(0xAA); //
    I2C_OUT(0x2F); //
    I2C_OUT(0xAB); //
    I2C_OUT(0x2F); //
    I2C_OUT(0xAC); //
    I2C_OUT(0x32); //
    I2C_OUT(0xAD); //
    I2C_OUT(0x32); //
    I2C_OUT(0xAE); //
    I2C_OUT(0x32); //
    I2C_OUT(0xAF); //
    I2C_OUT(0x32); //
    I2C_OUT(0xB0); //
    I2C_OUT(0x35); //
    I2C_OUT(0xB1); //
    I2C_OUT(0x35); //
    I2C_OUT(0xB2); //
    I2C_OUT(0x35); //
    I2C_OUT(0xB3); //
    I2C_OUT(0x35); //
    I2C_OUT(0xB4); //
    I2C_OUT(0x38); //
    I2C_OUT(0xB5); //
    I2C_OUT(0x38); //
    I2C_OUT(0xB6); //
    I2C_OUT(0x38); //
    I2C_OUT(0xB7); //
    I2C_OUT(0x38); //
    I2C_OUT(0xB8); //
    I2C_OUT(0x3A); //
    I2C_OUT(0xB9); //
    I2C_OUT(0x3A); //
    I2C_OUT(0xBA); //
    I2C_OUT(0x3A); //
    I2C_OUT(0xBB); //
    I2C_OUT(0x3A); //
    I2C_OUT(0xBC); //
    I2C_OUT(0x3C); //
    I2C_OUT(0xBD); //
    I2C_OUT(0x3C); //
    I2C_OUT(0xBE); //
    I2C_OUT(0x3C); //
    I2C_OUT(0xBF); //
    I2C_OUT(0x3C); //end grayscale settings
    I2C_OUT(0x38); //
    I2C_OUT(0x74); //
    I2C_OUT(0xAF); //display on
    I2C_OUT(0xA5); //DISPLAY ALL ON
    I2C_SP();
}
Code: [Select]
//I2C_BB.c
#include "I2C_BB.h"
#include <xc.h>
#include <delays.h>

#define DLAY 100
void I2C_ST(void) {
    delay(DLAY);
    SCL_HIGH();
    SDA_HIGH();
    delay(DLAY);
    SDA_LOW();
    SCL_LOW();
    delay(DLAY);
}

void I2C_SP(void) {
    delay(DLAY);
    SDA_LOW();
    SCL_LOW(); //n
    delay(DLAY);
    SCL_HIGH();
    SDA_HIGH();
    delay(DLAY);
}

char I2C_OUT(unsigned char data) {
    char bit_temp;
    delay(DLAY);
    for (bit_temp = 0; bit_temp < 8; bit_temp++) {
        if (data & 0x80)
            SDA_HIGH();
        else
            SDA_LOW();

        delay(DLAY);
        SCL_LOW();
        delay(DLAY);
        SCL_HIGH();
        delay(2*DLAY);
        data <<= 1;
        SCL_LOW();
        delay(DLAY);
    }
    SDA_HIGH();
    delay(2*DLAY);
    SCL_HIGH();
    delay(2*DLAY);
    SCL_LOW();

    while(SDA_IN){
        delay(DLAY);
        SCL_LOW();
        delay(DLAY);
        SCL_HIGH();
        delay(DLAY);
    }
    delay(DLAY);
    SCL_LOW();

    return 1;
}

unsigned char I2C_IN(char NACK) {
    char bit_temp;
    unsigned char data;

    SDA_HIGH();

    for (bit_temp = 0; bit_temp < 8; bit_temp++) {
        data <<= 1;

        SCL_HIGH();

        if (SDA_IN)
            data |= 1;

        SCL_LOW();
    }

    if (NACK == 1)
        SDA_LOW();
    else
        SDA_HIGH();

    SCL_HIGH();

    SCL_LOW();
    SDA_LOW();

    return data;
}

void delay(unsigned int time) {
    unsigned int t;
    for (t = 0; t < time; t++) {
        Nop();
    }
}

void delay2(unsigned int time) {
    unsigned int t;
    for (t = 0; t < time; t++) {
        __delay_ms(20);
    }
}
Code: [Select]
//I2C_BB.h
#ifndef _I2C_BB_H
#define _I2C_BB_H
#include <xc.h>

void Init_I2C(void);
unsigned char I2C_IN(char NACK);
char I2C_OUT(unsigned char data);
void I2C_SP(void);
void I2C_ST(void);

void delay(unsigned int time);
void delay2(unsigned int time);

#define SCL_HIGH() (SCL = 1)
#define SDA_HIGH() (SDA = 1)
#define SDA_LOW() (SDA = 0,SDA_IN=0)
#define SCL_LOW() (SCL = 0,SCL_IN=0)

#define SCL     TRISBbits.TRISB4
#define SDA     TRISBbits.TRISB5
#define SCL_IN  PORTBbits.RB4
#define SDA_IN  PORTBbits.RB5

#endif


Here is my setup (sorry about the really terrible wire coloring and layout red and black take turns plugging into power)

http://imgur.com/a/gLTKp


Any help is appreciated! Thanks!
Title: Re: NHD-C160100DiZ-FSW-FBW w/PIC18F47J53
Post by: Michael_L on December 02, 2014, 08:38:18 AM
Are you issuing a hard reset when you initialize the display?  Take a look at the code below that we use for one of our testers and try and use these initialization values and sequence.  Also note the hard reset at the beginning:

Code: [Select]
void C160100DiZ_Init(void)
{
GPIO_WriteBit(GPIOC, RES, Bit_RESET);
graphic_delay(10);
GPIO_WriteBit(GPIOC, RES, Bit_SET);
GPIO_SetBits(GPIOC, CS1);
GPIO_SetBits(GPIOC, nRD);
GPIO_SetBits(GPIOC, RS);
GPIO_SetBits(GPIOC, nWR);
ST7528i_Start();
ST7528i(Slave);
ST7528i(Send_Command);
ST7528i(0x48); //set partial display duty
ST7528i(0x64);
ST7528i(0xA0); //ADC: normal
ST7528i(0xC8); //SHL: COM reverse
ST7528i(0x40); //set initial display line
ST7528i(0x00); //set initial display line = 0x00
ST7528i(0x44); //set initial COM0 register
ST7528i(0x00);
ST7528i(0xAB); //start oscillator
ST7528i(0x26); //select regulator resistor ratio
ST7528i(0x81); //set electronic volume
ST7528i(0x1C); //contrast value
ST7528i(0x56); //select LCD bias
ST7528i(0x64); //select DC-DC step-up
graphic_delay(2000);
ST7528i(0x2C); //set power control
ST7528i(0x66); //select DC-DC step-up
graphic_delay(2000);
ST7528i(0x2E); //set power control
graphic_delay(2000);
ST7528i(0x2F); //set power control
ST7528i(0xF3); //bias power save
ST7528i(0x00); //bias power save
ST7528i(0x96); //select FRC and PWM mode
ST7528i(0x38); //mode set
ST7528i(0x75); //mode set (FR and BE)

ST7528i(0x80); //begin Gray Scale level settings
ST7528i(0x00);
ST7528i(0x81);
ST7528i(0x00);
ST7528i(0x82);
ST7528i(0x00);
ST7528i(0x83);
ST7528i(0x00);
ST7528i(0x84);
ST7528i(0x06);
ST7528i(0x85);
ST7528i(0x06);
ST7528i(0x86);
ST7528i(0x06);
ST7528i(0x87);
ST7528i(0x06);
ST7528i(0x88);
ST7528i(0x0B);
ST7528i(0x89);
ST7528i(0x0B);
ST7528i(0x8A);
ST7528i(0x0B);
ST7528i(0x8B);
ST7528i(0x0B);
ST7528i(0x8C);
ST7528i(0x10);
ST7528i(0x8D);
ST7528i(0x10);
ST7528i(0x8E);
ST7528i(0x10);
ST7528i(0x8F);
ST7528i(0x10);
ST7528i(0x90);
ST7528i(0x15);
ST7528i(0x91);
ST7528i(0x15);
ST7528i(0x92);
ST7528i(0x15);
ST7528i(0x93);
ST7528i(0x15);
ST7528i(0x94);
ST7528i(0x1A);
ST7528i(0x95);
ST7528i(0x1A);
ST7528i(0x96);
ST7528i(0x1A);
ST7528i(0x97);
ST7528i(0x1A);
ST7528i(0x98);
ST7528i(0x1E);
ST7528i(0x99);
ST7528i(0x1E);
ST7528i(0x9A);
ST7528i(0x1E);
ST7528i(0x9B);
ST7528i(0x1E);
ST7528i(0x9C);
ST7528i(0x23);
ST7528i(0x9D);
ST7528i(0x23);
ST7528i(0x9E);
ST7528i(0x23);
ST7528i(0x9F);
ST7528i(0x23);
ST7528i(0xA0);
ST7528i(0x27);
ST7528i(0xA1);
ST7528i(0x27);
ST7528i(0xA2);
ST7528i(0x27);
ST7528i(0xA3);
ST7528i(0x27);
ST7528i(0xA4);
ST7528i(0x2B);
ST7528i(0xA5);
ST7528i(0x2B);
ST7528i(0xA6);
ST7528i(0x2B);
ST7528i(0xA7);
ST7528i(0x2B);
ST7528i(0xA8);
ST7528i(0x2F);
ST7528i(0xA9);
ST7528i(0x2F);
ST7528i(0xAA);
ST7528i(0x2F);
ST7528i(0xAB);
ST7528i(0x2F);
ST7528i(0xAC);
ST7528i(0x32);
ST7528i(0xAD);
ST7528i(0x32);
ST7528i(0xAE);
ST7528i(0x32);
ST7528i(0xAF);
ST7528i(0x32);
ST7528i(0xB0);
ST7528i(0x35);
ST7528i(0xB1);
ST7528i(0x35);
ST7528i(0xB2);
ST7528i(0x35);
ST7528i(0xB3);
ST7528i(0x35);
ST7528i(0xB4);
ST7528i(0x38);
ST7528i(0xB5);
ST7528i(0x38);
ST7528i(0xB6);
ST7528i(0x38);
ST7528i(0xB7);
ST7528i(0x38);
ST7528i(0xB8);
ST7528i(0x3A);
ST7528i(0xB9);
ST7528i(0x3A);
ST7528i(0xBA);
ST7528i(0x3A);
ST7528i(0xBB);
ST7528i(0x3A);
ST7528i(0xBC);
ST7528i(0x3C);
ST7528i(0xBD);
ST7528i(0x3C);
ST7528i(0xBE);
ST7528i(0x3C);
ST7528i(0xBF);
ST7528i(0x3C); //end Gray Scale level settings

ST7528i(0x38); //mode set
ST7528i(0x74); //mode set (FR and BE)
ST7528i(0xAF); //display ON
ST7528i_Stop();
}
Title: Re: NHD-C160100DiZ-FSW-FBW w/PIC18F47J53
Post by: Ipsum on December 03, 2014, 10:59:35 AM
I modified my program so that the reset line is held low for 10ms and then brought high right before the initialization is written. It still doesn't seem to display anything, but I have a few questions.

What is nRD, RS, and nWR in this code segment you gave me? Are these lines to the LCD? I know chip select needs to be pulled low, but I don't know what lines those other bits would be.
Code: [Select]
GPIO_SetBits(GPIOC, nRD);
GPIO_SetBits(GPIOC, RS);
GPIO_SetBits(GPIOC, nWR);

Is there some kind of minimum communication clock rate? Am I ok running this at 10k Hz? Do I need to finish sending the init sequence in some number of seconds?

Thanks!
Title: Re: NHD-C160100DiZ-FSW-FBW w/PIC18F47J53
Post by: Michael_L on December 04, 2014, 03:17:10 PM
Please disregard those lines of code, there are simply left there from other code snippets from another initialization sequence.  Those pins don't connect to anything on this display.
The ST7528 datasheet does not give a minimum for I2C clock frequency, only a max of 400kHz.  Therefore, I would think you can communicate at any speeds lower than that, even as low as 10kHz.  Is there any way to try, say, 100kHz with your setup?  Also, what value pullups are you using?  Can you try 10kΩ? Is it possible to make your I2C lines shorter?