Author Topic: NHD-0216K1Z  (Read 422 times)

lakin

  • Newbie
  • *
  • Posts: 3
  • Karma: 1
    • View Profile
NHD-0216K1Z
« on: July 20, 2017, 09:05:58 AM »
I can display one letter, but debugging my program I'm sending more characters than aren't displayed.  Using PIC16F886.  I'm using code close to what I read on this forum.  I've enclosed the code, doing something wrong.
The initialization is copied from code on the forum.  Also I don't understand the newline command 0xC0 ?
The program will also be used later for AD converter.  But right now I want to get the display to work.  Plus it gives me some LCD display experience.

char const text1[] = {"Roger Lakin     " };
void main(void) {
    TRISC = 0x00; //  this port is set for outputs
    TRISB = 0xF8; //  all are set to inputs except the lower three
    TRISA3 = 0; //AN3 +VREF
    TRISA5 = 1; // AN4   bit 5 set as input
    TRISB0 = 0; // enable signal output
    TRISB1 = 0; // read/write signal
    TRISB2 = 0; // register select signal
    //ADCON0 = 0x11;  //  00 0100 0 1
    //ADCON1 = 0x80;  // ADFM = 1
    //ADRESH = 0x00;  // ADC 8 & 9 off
    //ADRESL = 0x10; //  ADC 4 turned on pin 7  RA5  ADC rest off
   
    /******************************************/
    x = 0;
//    Init();
    PORTC = 0x00;
    while(1){
        Init();
        DisplayInfo();
        delay(1000);
    }
 
}
 
void DisplayInfo(){   //disp_pic
  int i;
  Home();
    for (i=0;i<8;i++){
        Write(text1); 
        y = 0;  // debug breakpoint
    }
}
void Write(unsigned char Dat){
     PORTB = 0X00;
     PORTC = Dat;
     delay(10);
    RSLO; // RB2=0
    RWLO;//RB1=0; //write
    EHI; // RB0
    RSHI; //RB2  data
    delay(10);
    EHI;    //RB0=1;//EHI; //RB0
    delay(10);
    ELO; //RB0
    RSLO;
    //PORTC = 0x01;
    //WriteCtl();
    y=0;
}

void Home(){
    PORTC = 0x02;
    WriteCtl();
    delay(5);
}
void NextLine(){
    PORTC = 0xC0;
    WriteCtl();
}
// write controls

void WriteCtl(){
   
    RSLO;
    RWLO; //RB1
    EHI; //RB0
    delay(1);
    ELO; //RB0
    //RWHI; //RB1
    //RSHI; //RB2
   
}

// AorD = 0 for address and 1 for data

void WriteAN(int AorD) {  // wrtAdr = 0; wrtNum = 1;

    PORTB = 0X00;
    RWLO;//RB1=0; //write
    ELO; // RB0
    if (AorD == 0) {
        RSLO; //RB2  address
    } else {
        RSHI; //RB2  data
    }
    delay(1);
    EHI;    //RB0=1;//EHI; //RB0
    delay(1);
    ELO; //RB0
    //RB1=1;//RWHI; //RB1
    //RB2=1;//RSHI; //RB2
}


void WriteInt(unsigned char charNum){
    PORTC = charNum;
    RB2 = 0;//RSLO; // RB2
    RB1 = 0; // RWLO;  // RB1
    RB0 = 1; //EHI; // RB0
    delay(10);
    RB0 = 0; // ELO; // RB0
    y=0; // breakpoint
}

void Init(){
 ELO;
 delay(50);    //Wait >40 msec after power is applied       
 WriteInt(0x30);  //command 0x30 = Wake up       
 delay(100);      //must wait 5ms, busy flag not available       
 WriteInt(0x30);  //command 0x30 = Wake up #2       
 delay(100);      //must wait 160us, busy flag not available       
 WriteInt(0x30);  //command 0x30 = Wake up #3       
 delay(100);      //must wait 160us, busy flag not available       
 WriteInt(0x38);  //Function set: 8-bit/1-line       
 WriteInt(0x14);//Set cursor to rightAC+1     
 WriteInt(0x0C);  //Display ON; Cursor ON       
 WriteInt(0x02);  //Entry mode set   cursor right DDRAM + 1
}

Saurabh_B

  • Administrator
  • Hero Member
  • *****
  • Posts: 338
  • Karma: 10
    • View Profile
Re: NHD-0216K1Z
« Reply #1 on: July 21, 2017, 08:25:07 AM »
Can you tell me what letter you are seeing on your display?
Also How long are the delays in your code?

lakin

  • Newbie
  • *
  • Posts: 3
  • Karma: 1
    • View Profile
Re: NHD-0216K1Z
« Reply #2 on: July 21, 2017, 10:13:37 AM »
Hi
Thank you for responding.  I got the unit working.
Notice :  Write(text1) did not have the i,  corrected Write(text1);

void DisplayInfo(){   //disp_pic
  int i;
  Home();
    for (i=0;i<8;i++){
        Write(text1); 
        y = 0;  // debug breakpoint
    }
}

Saurabh_B

  • Administrator
  • Hero Member
  • *****
  • Posts: 338
  • Karma: 10
    • View Profile
Re: NHD-0216K1Z
« Reply #3 on: July 21, 2017, 02:09:25 PM »
That's great to hear, were you able to figure out the command that helps you get to the second line?

Instead of being a new line, this is actually the Set DDRAM address.
You can find a datasheet for one of our displays here: http://www.newhavendisplay.com/specs/NHD-0216K1Z-FL-YBW.pdf

On page 6 of the datasheet, we have the master table of instructions. On this we are using the Set DDRAM Address command (4th command from the bottom).
Using this you can set the cursor to any position of the display, the addresses of the digits can be found on the bottom of page 5.

lakin

  • Newbie
  • *
  • Posts: 3
  • Karma: 1
    • View Profile
Re: NHD-0216K1Z
« Reply #4 on: July 21, 2017, 05:34:22 PM »
OK thanks.  I will be experimenting a little more and will use that method.  I'm a C programmer using a PIC.  Here is some C code if someone is interested.   To run it, header files, timers (delay) and variables need to be defined. 

void main(void) {
    TRISC = 0x00; //  this port is set for outputs
    TRISA3 = 0; //AN3 +VREF
    TRISA5 = 1; // AN4   bit 5 set as input
    ANSELH = 0x00;
    TRISB0 = 0; // enable signal output
    TRISB1 = 0; // read/write signal
    TRISB2 = 0; // register select signal   
   
    /******************************************/
    x = 0;  // debug breakpoint
    PORTC = 0x00;  // clear screen
    WriteCtl();  //  write commands
    delay(50);
    delta=500;
    cycle=40;
    //  continous run
    while(1){
      Init();
      DisplayInfo();
      delay(10000);
    }
 
}
 
void DisplayInfo(){   //disp_pic
  int i;
  Home();
    for (i=0;i<16;i++){   
       Write(text1);
        delay(1000);
        y = 0;  // debug breakpoint
    }
}
void Write(unsigned char Dat){
     
    PORTC = Dat;
    delay(5);
    RSHI; // RB2=1
    RWLO;//RB1=0; //write
    EHI; // RB0
    delay(100);
    ELO; //RB0
    RSLO;
    y=0;  // breakpoint
}

void Home(){
    PORTC = 0x02;  //home
    WriteCtl();
    delay(5);
    PORTC = 0x01;  // clear screen
    WriteCtl();
    delay(5);
}
void NextLine(){
    PORTC = 0xC0;
    WriteCtl();
}
// write controls

void WriteCtl(){   
    RSLO;
    RWLO; //RB1
    EHI; //RB0
    delay(10);
    ELO; //RB0
}

// AorD = 0 for address and 1 for data

void WriteAN(int AorD) {  // wrtAdr = 0; wrtNum = 1;
    RWLO;//RB1=0; //write
    ELO; // RB0
    if (AorD == 0) {
        RSLO; //RB2  address
    } else {
        RSHI; //RB2  data
    }
    delay(10);
    EHI;    //RB0=1;//EHI; //RB0
    delay(1);
    ELO; //RB0
}


void WriteInt(unsigned char initNum){
    PORTC = initNum;
    RSLO; // RB2
    RWLO;  // RB1
    EHI; // RB0
    delay(100);
    ELO; // RB0
    y=0; // breakpoint
}

void Init(){
 ELO;
 delay(500);    //Wait >40 msec after power is applied       
 WriteInt(0x30);  //command 0x30 = Wake up       
 delay(100);      //must wait 5ms, busy flag not available       
 WriteInt(0x30);  //command 0x30 = Wake up #2       
 delay(100);      //must wait 160us, busy flag not available       
 WriteInt(0x30);  //command 0x30 = Wake up #3       
 delay(100);      //must wait 160us, busy flag not available       
 WriteInt(0x38);  //Function set: 8-bit/1-line       
 WriteInt(0x14);//Set cursor to right AC+1     
 WriteInt(0x0C);  //Display ON; Cursor ON       
 WriteInt(0x06);  //Entry mode set   cursor right DDRAM + 1
}
 



 

CGRAM,DDRAM in 2x16 Character LCD - NHD-0216K1Z-FSW-FBW-L

Started by pradeepsysargusBoard Character LCDs

Replies: 1
Views: 2153
Last post June 24, 2016, 11:37:16 AM
by Ted_M
NHD-0216K1Z-FL-YBW Screen Corruption Problem

Started by ScorpionTechBoard Character LCDs

Replies: 1
Views: 738
Last post January 17, 2017, 12:13:51 PM
by Saurabh_B
MOVED: Problem of contrast NHD-0216K1Z-NSW-BBW-L

Started by Saurabh_BBoard Graphic LCDs

Replies: 0
Views: 673
Last post January 24, 2017, 08:36:08 AM
by Saurabh_B
Problem of contrast NHD-0216K1Z-NSW-BBW-L

Started by vincentthiventBoard Character LCDs

Replies: 1
Views: 735
Last post January 24, 2017, 02:51:57 PM
by Saurabh_B
NHD-0216K1Z-NSW-BBW-L Back light

Started by tkraus@cnmcco.comBoard Character LCDs

Replies: 1
Views: 690
Last post February 13, 2017, 10:42:43 AM
by Saurabh_B