Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - cbrun17

Pages: [1]
1
OLEDs / Interfacing NHD-0420CW-AY3 to PIC controller via I2C
« on: May 04, 2017, 10:43:51 AM »
I am trying to write a library for use in MikroC environment and I have to say the datasheet for the NHD-0420CW-AY3 is the most confusing. I'm sure this is due to my limited experience with these type of displays but unfortunately the example provided in the datasheet is not very helpful to me.

One example of difficulty is creating a function for contrast.

Here is my code:
Code: [Select]
void LCD_Contrast(short level)
{
        if (level < 1 || level > 255) level = 127;  //default to 127 if out of range
        I2C1_Start();
        I2C1_Wr(_I2C_ADDRESS);
        // ***Do I need to enter the function level here first? i.e. extended command set.***
        I2C1_Wr(0x81);
        I2C1_Wr(0x28);
        I2C1_Wr(level);
        Delay_us(500);
        I2C1_Stop();
        Delay_ms(5);
}
The question here is, do I also need to define the function level command prior to defining the contrast control?

Also, I am unable to figure out how to specify row/column for writing data. This is the big issue for me!!
The code I typically use to output string information to a I2C LCD is:

//************************Define display position*************************************
Code: [Select]
void LCD_Set_Pos(short line, short col)
{
        short ln;
 
      //default to line 1 if value passed is out of range

      if (line < 1 || line > 4) line = 1;

      //default to column 0  if value passed is out of range

      if (col < 1 || col > _LCD_WIDTH ) col = 0;

        I2C1_Start();
        I2C1_Wr(_I2C_ADDRESS);
        I2C1_Wr(0x45); //Set cursor
        switch (line)
        {
                case 1:
                    ln = 0x80;
                    break;
                case 2:
                    ln = 0xA0;
                     break;
                case 3:
                    ln = 0xC0;
                    break;
                case 4:
                    ln = 0xE0;
                                       
        }
        I2C1_Wr(ln + (col-1));
        Delay_us(100);
        I2C1_Stop();
}


//************************StringSize definition*************************************
Code: [Select]
unsigned int StringSize(char* InString)
{
    unsigned int StrSize;
    char StrByte;
   
    StrSize = 0;
    StrByte = InString[StrSize];
    while( StrByte != '\0' )
    {
        StrSize++;
        StrByte = InString[StrSize];

    }
    return StrSize;

}

Then
// *************Passing standard text to display**************************************
Code: [Select]
void LCD_Line_Out(short line, short col, char* info)
{
    short size;
    short ccount;
    //default to line 1 if value passed is out of range
    if (line < 1 || line > 4) line = 1;
    //default to column 1  if value passed is out of range
    if (col < 1 || col > _LCD_WIDTH ) col = 0;
    size =  StringSize(info);
    LCD_Set_Pos(line, col);
    for (ccount = 0; ccount < size; ccount++)
        LCD_Chr_Out_CP(info[ccount]);       
}

Most of the struggle I have is understanding the relationship of some of the commands such as "set SEG pins hardware configuration" and "Entry Mode".

I know these are a lot of questions but I hope someone can provide some direction for me.

Thank you in advance.

Chris

Pages: [1]