Author Topic: [NHD-0420CW-Ax3] Start my display in C language  (Read 1221 times)

arrgon

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
    • View Profile
[NHD-0420CW-Ax3] Start my display in C language
« on: February 20, 2018, 09:14:04 AM »
Hi,

I try to debug my code but when I initialize the start of my function about the display, it not work and I don't know how to do it.

First of all I have my main part that start my display management :

Code: [Select]
/**
 * \brief Entry point of the program
 */

/**
 * @brief Initializations done after parameters loading
 */
void initializations(void)
{
mainOledDisplay();
}

int main (void)
{
   
    periphInitMain();

    gpioInit();

    initializations();

    while (TRUE)
    {
        ethernetPeriodicProcess();
        taskProcess();
    }

}


Then I have my code part of the display :
Code: [Select]


 /* The circuit:
  *
  * OLED pin 1 (Vss)          pin ground
  * OLED pin 2 (VDD)          pin 3.3V
  * OLED pin 3 (REGVDD)       to Vss ground
  * OLED pin 4 (SA0)          to Vss ground   (to assign I2C address 0x3D, connect to VDD 3.3V)
  * OLED pin 5 and 6          to Vss ground
  * OLED pin 7 (SCL)          pin SCL (7=D0)
  * OLED pin 8 and 9 (SDAin,SDAout) pin SDA  (9=D2; 8=D1)
  * OLED pin 10 to 15         to Vss ground (14=D7; 13=D6; 12=D5; 11=D4; 10=D3)
  * OLED pin 16 (/RES)        pin Reset or VDD 3.3V
  * OLED pin 17 (BS0)         to Vss ground
  * OLED pin 18 (BS1)         to VDD 5V
  * OLED pin 19 (BS2)         to Vss ground
  * OLED pin 20 (Vss)         to Vss ground
  */

/**********************/
/****** includes ******/
/**********************/
#include "oledDisplay.h"
#include "../gpio.h"

/**
 * @brief SUBROUTINE: PREPARES THE TRANSMISSION OF A COMMAND
 *
 * @param[in] commandByte    The command to be executed by the display
 */
void command(uint8_t commandByte)
{
   tx_packet[0] = 0x00; // Control Byte; C0_bit=0, D/C_bit=0 -> following Data Byte contains command
   tx_packet[1] = commandByte;
   send_packet(2); // Transmits the two bytes
}

/**
 * @brief SUBROUTINE: PREPARES THE TRANSMISSION OF A BYTE OF DATA
 *
 * @param[in] dataByte   The character to be displayed
 */
void data(uint8_t dataByte)
{
   tx_packet[0] = 0x40; // Control Byte; C0_bit=0, D/C_bit=1 -> following Data Byte contains data
   tx_packet[1] = dataByte;
   send_packet(2); // Transmits the two bytes
}

/**
 * @brief SUBROUTINE: SEND TO THE DISPLAY THE NUMBER OF BYTES STORED IN tx_packet
 *
 * @param[in] dataByte Command or bytes of data stored
 */
void send_packet(uint8_t byteStored)
{
   uint8_t index = 0; // Bytes index

   I2C_DeInit(I2CM_MODULE);
   I2C_GenerateSTART(I2CM_MODULE, ENABLE);
   I2C_SendData(I2CM_MODULE, SLAVE2W);
   I2C_Send7bitAddress(I2CM_MODULE, SLAVE2W, I2C_Direction_Transmitter);
   /*  Wire.beginTransmission(SLAVE2W); */ // Begin the transmission via I2C to the display with the given address

   for(index=0; index<byteStored; index++) // One byte at a time
   {
  i2cmWrite(SLAVE2W, 2, tx_packet[index]);
   /* Wire.write(tx_packet[index]); */  // queue bytes for transmission

   }

   I2C_ReceiveData(I2CM_MODULE);
   I2C_GenerateSTOP(I2CM_MODULE, ENABLE);
   /*  Wire.endTransmission(); */  // Transmits the bytes that were queued
}

/**
 * @brief SUBROUTINE: DISPLAYS THE FOUR STRINGS, THEN THE SAME IN REVERSE ORDER
 */
void output(void)
{
   uint8_t row = 0;        // Row index
   uint8_t column = 0;    // Column index

   command(0x01);                     // Clears display (and cursor home)
   softDelay(2);                      // After a clear display, a minimum pause of 1-2 ms is required

   for (row=0; row<ROW_N; row++)   // One row at a time
   {
      command(new_line[row]);         // moves the cursor to the first column of that line
      for (column=0; column<COLUMN_N; column++) // One character at a time
      {
         data(TEXT[row][column]);     // displays the corresponding string
      }
   }
   softDelay(2000);                   // Waits, only for visual effect purpose

   for (row=0; row<ROW_N; row++)      // One row at a time
   {
      command(new_line[row]);         // moves the cursor to the first column of that line
      for (column=0; column<COLUMN_N; column++) // One character at a time
      {
         data(TEXT[3-row][column]);   // displays the correspondig string (in reverse order)
      }
   }
}

/**
 * @brief SUBROUTINE: FILLS THE ENTIRE DISPLAY WITH THE CHARACTER "BLOCK"
 */
void blocks(void)
{
   uint8_t row = 0;                   // Row index
   uint8_t column = 0;                // Column index

   command(0x01);                     // Clear display (and cursor home)
   softDelay(2);                      // After a clear display, a minimum pause of 1-2 ms is required

   for (row=0; row<ROW_N; row++)      // One row at a time
   {
      command(new_line[row]);           // moves the cursor to the first column of that line
      for (column=0; column<COLUMN_N; column++) // One character at a time
      {
         data(0xDB);                  // displays the character 0xDB (block)
         softDelay(50);               // Waits, only for visual effect purpose
      }
      softDelay(500);                 // Waits, only for visual effect purpose
   }
}

/**
 * @brief INITIAL SETUP
 */
void setup(void)
{
//   pinMode(RES, OUTPUT);            // Initializes Arduino pin for the Reset line (optional)
//   digitalWrite(RES, HIGH);         // Sets HIGH the Reset line of the display (optional, can be always high)
   softDelay(0.2);              // Waits 200 us for stabilization purpose

   I2C_DeInit(I2CM_MODULE);
   I2C_GenerateSTART(I2CM_MODULE, ENABLE);      // Initiate the Wire library and join the I2C bus as a master

   softDelay(10);          // Waits 10 ms for stabilization purpose

   if (ROW_N == 2 || ROW_N == 4)
      rows = 0x08;                    // Display mode: 2/4 lines
   else
      rows = 0x00;                    // Display mode: 1/3 lines

   command(0x22 | rows); // Function set: extended command set (RE=1), lines #
   command(0x71);        // Function selection A:
   data(0x5C);           //  enable internal Vdd regulator at 5V I/O mode (def. value) (0x00 for disable, 2.8V I/O)
   command(0x20 | rows); // Function set: fundamental command set (RE=0) (exit from extended command set), lines #
   command(0x08);        // Display ON/OFF control: display off, cursor off, blink off (default values)
   command(0x22 | rows); // Function set: extended command set (RE=1), lines #
   command(0x79);        // OLED characterization: OLED command set enabled (SD=1)
   command(0xD5);        // Set display clock divide ratio/oscillator frequency:
   command(0x70);        //  divide ratio=1, frequency=7 (default values)
   command(0x78);        // OLED characterization: OLED command set disabled (SD=0) (exit from OLED command set)

   if (ROW_N > 2)
      command(0x09);     // Extended function set (RE=1): 5-dot font, B/W inverting disabled (def. val.), 3/4 lines
   else
      command(0x08);     // Extended function set (RE=1): 5-dot font, B/W inverting disabled (def. val.), 1/2 lines

   command(0x06);        // Entry Mode set - COM/SEG direction: COM0->COM31, SEG99->SEG0 (BDC=1, BDS=0)
   command(0x72);        // Function selection B:
   data(0x0A);           //  ROM/CGRAM selection: ROM C, CGROM=250, CGRAM=6 (ROM=10, OPR=10)
   command(0x79);        // OLED characterization: OLED command set enabled (SD=1)
   command(0xDA);        // Set SEG pins hardware configuration:
   command(0x10);        //  alternative odd/even SEG pin, disable SEG left/right remap (default values)
   command(0xDC);        // Function selection C:
   command(0x00);        //  internal VSL, GPIO input disable
   command(0x81);        // Set contrast control:
   command(0x7F);        //  contrast=127 (default value)
   command(0xD9);        // Set phase length:
   command(0xF1);        //  phase2=15, phase1=1 (default: 0x78)
   command(0xDB);        // Set VCOMH deselect level:
   command(0x40);        //  VCOMH deselect level=1 x Vcc (default: 0x20=0,77 x Vcc)
   command(0x78);        // OLED characterization: OLED command set disabled (SD=0) (exit from OLED command set)
   command(0x20 | rows); // Function set: fundamental command set (RE=0) (exit from extended command set), lines #
   command(0x01);        // Clear display
   softDelay(2);         // After a clear display, a minimum pause of 1-2 ms is required
   command(0x80);        // Set DDRAM address 0x00 in address counter (cursor home) (default value)
   command(0x0C);        // Display ON/OFF control: display ON, cursor off, blink off
   softDelay(250);       // Waits 250 ms for stabilization purpose after display on

   if (ROW_N == 2)
      new_line[1] = 0xC0;      // DDRAM address for each line of the display (only for 2-line mode)
}

/**
 * @brief MAIN PROGRAM
 */
void mainOledDisplay(void)
{
output();          // Execute subroutine "output"
softDelay(2000);   // Waits, only for visual effect purpose
    blocks();          // Execute subroutine "blocks"
    softDelay(2000);   // Waits, only for visual effect purpose
}

I do not know how to operate my display

The code seems correct?

Thanks a lot and sorry for my english  :P !

Ted_M

  • Administrator
  • Jr. Member
  • *****
  • Posts: 44
  • Karma: 3
    • View Profile
Re: [NHD-0420CW-Ax3] Start my display in C language
« Reply #1 on: February 21, 2018, 09:15:38 AM »
Hi Arrgon,

Below are the commands necessary to initialize the display.  Additional support code can be found in our datasheet:
http://www.newhavendisplay.com/specs/NHD-0420CW-AW3.pdf
 
More example code can also be found on our Github site:

https://github.com/NewhavenDisplay/NHD_US2066
 

Code: [Select]
void init()
{
RES = 1;                 //reset HIGH inactive
delayms(1);            //delay
command(0x2A);    //function set (extended command set)
command(0x71);    //function selection A
data(0x00);            // disable internal VDD regulator (2.8V I/O). data(0x5C) = enable regulator (5V I/O)
command(0x28);    //function set (fundamental command set)
command(0x08);    //display off, cursor off, blink off
command(0x2A);    //function set (extended command set)
command(0x79);    //OLED command set enabled
command(0xD5);    //set display clock divide ratio/oscillator frequency
command(0x70);    //set display clock divide ratio/oscillator frequency
command(0x78);    //OLED command set disabled
command(0x09);    //extended function set (4-lines)
command(0x06);    //COM SEG direction
command(0x72);    //function selection B
data(0x00);           //ROM CGRAM selection
command(0x2A);    //function set (extended command set)
command(0x79);    //OLED command set enabled
command(0xDA);   //set SEG pins hardware configuration
command(0x10);    //set SEG pins hardware configuration
command(0xDC);   //function selection C
command(0x00);    //function selection C
command(0x81);    //set contrast control
command(0x7F);    //set contrast control
command(0xD9);    //set phase length
command(0xF1);    //set phase length
command(0xDB);    //set VCOMH deselect level
command(0x40);    //set VCOMH deselect level
command(0x78);    //OLED command set disabled
command(0x28);    //function set (fundamental command set)
command(0x01);   //clear display
command(0x80);   //set DDRAM address to 0x00
command(0x0C);   //display ON
delayms(100);       //delay
}

Please let me know if you have any questions.
« Last Edit: February 21, 2018, 09:25:08 AM by Ted_M »

arrgon

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
    • View Profile
Re: [NHD-0420CW-Ax3] Start my display in C language
« Reply #2 on: February 21, 2018, 10:05:26 AM »
Thank you so much for your help.

I know and I use the datasheet. thanks anyway.

Github : For my code the problem is that I have to use it without all the arduino's functions wire.begin etc...  I only have to control it in i2c and not in spi as in the example provided.

that's why I do not know how to do.
Thanks a lot.

Ted_M

  • Administrator
  • Jr. Member
  • *****
  • Posts: 44
  • Karma: 3
    • View Profile
Re: [NHD-0420CW-Ax3] Start my display in C language
« Reply #3 on: May 21, 2018, 11:18:12 AM »
Hi Arrgon,

Have you been able to resolve this issue?

 

Blank Display on NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM

Started by SteveCBoard Character LCDs

Replies: 3
Views: 7859
Last post May 13, 2014, 12:04:36 AM
by SteveC
NHD‐C12864A1Z‐FSW‐FBW‐HTT display clears after draw

Started by EdAverillBoard Graphic LCDs

Replies: 6
Views: 9581
Last post November 07, 2014, 08:25:20 AM
by Michael_L
NHD‐4.3‐480272EF‐ATXL#‐CTP | FAN5333 | BBB | Nothing on the Display

Started by Alias_AliasBoard TFTs

Replies: 1
Views: 6679
Last post September 25, 2015, 03:09:24 PM
by Paul_B
Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 15291
Last post July 10, 2014, 08:46:06 AM
by Michael_L
NHD-0420DZW-AG5 - Display "sometimes" shows only 2 lines

Started by stylonurusBoard OLEDs

Replies: 5
Views: 9099
Last post June 18, 2014, 10:09:49 AM
by Michael_L