Newhaven Display Forum

Newhaven Products => Character LCDs => Topic started by: fxdxrdr on September 24, 2014, 09:19:48 AM

Title: LCD not working with PIC16
Post by: fxdxrdr on September 24, 2014, 09:19:48 AM
HI all,
I'm working with a PIC16F1459 and a NHD-0216K1Z-Fl-YBW in 8 bit mode.
I'm using MLABX IDE with XC8.
I'm  programming with a PICKIT3.

The back light works fine, but that's all. Nothing is coming up on the display. I've been searching on the internet for an answer and keep running into the same code and trying it, but the display is dead. The back light and contrast are connected to trimmers for adjustment. I've ohmed out all connections and they are hooked up correctly. The LCD VDD and contrast are hooked to a pin so that I can control them being turned on.
Any help would be appreciated! I've attached the code I'm using
TIA Pete

Code: [Select]
// PIC16F1459 I/P
#include "LCDTestConfig.h"

#define _XTAL_FREQ 500000               //Used by the XC8 delay_ms(x) macro

#define POWER   LATCbits.LATC2
#define PWR_ON  1

#define D_I     LATBbits.LATB4 //RS
#define R_W     LATBbits.LATB5
#define E       LATBbits.LATB6

#define DB0     LATBbits.LATB7
#define DB1     LATCbits.LATC7
#define DB2     LATCbits.LATC6
#define DB3     LATCbits.LATC3
#define DB4     LATCbits.LATC4
#define DB5     LATCbits.LATC5
#define DB6     LATAbits.LATA4
#define DB7     LATAbits.LATA5

typedef union
{
    struct
    {
        unsigned DB_0    :1;
        unsigned DB_1    :1;
        unsigned DB_2    :1;
        unsigned DB_3    :1;
        unsigned DB_4    :1;
        unsigned DB_5    :1;
        unsigned DB_6    :1;
        unsigned DB_7    :1;
    };
}DBbits;

char const text1[] = {"Newhaven Display"};
char const text2[] = {"Character LCD   "};

void init();
void command(char i);
void write(char i);
void home();
void nextline();
void disp_pic();
void SetDataBits(char i);

void main()
{
    OSCCON = 0b00101000;    // 500 khz internal oscillator

    TRISA = 0;  // all ports set for output
    TRISB = 0;
    TRISC = 0;

    LATA = 0;
    LATB = 0;
    LATC = 0;

    POWER = PWR_ON; // puts 4.60 volts to LCD VDD
    __delay_ms(50);
    init();
   
    while(1)
    {
       disp_pic(); 
        __delay_ms(1000);
    }
   
}

void command(char i)
{
    SetDataBits(i);
    D_I = 0;
    R_W = 0;
    E = 1;
    __delay_ms(1);
    E = 0;
}
void write(char i)
{
    SetDataBits(i);

    D_I = 1;
    R_W = 0;
    E = 1;
    __delay_ms(1);
    E  = 0;
}

void init()
{
    E = 0;
    __delay_ms(5);
    command(0x30);
    __delay_ms(100);
    command(0x30);
    __delay_ms(10);
    command(0x30);
    __delay_ms(10);
    command(0x38);
    command(0x10);
    command(0x0c);
    command(0x06);
}

void home()
{
    command(0x01);
    __delay_ms(5);
}
void nextline()
{
    command(0xc0);
}
void disp_pic()
{
    int i;
    home();
    for (i=0;i<16;i++)
    {
        write(text1[i]);
    }
     nextline();
     for (i=0;i<16;i++)
     {
        write(text2[i]);
     }
}

void SetDataBits(char i)
{
    DBbits *db = (DBbits*)&i;

    DB0 = db->DB_0;
    DB1 = db->DB_1;
    DB2 = db->DB_2;
    DB3 = db->DB_3;
    DB4 = db->DB_4;
    DB5 = db->DB_5;
    DB6 = db->DB_6;
    DB7 = db->DB_7;
}


Title: Re: LCD not working with PIC16
Post by: Michael_L on September 25, 2014, 08:07:48 AM
What voltage are you using for VDD and your logic levels?  What voltage are you using for pin 3 (V0)?  Do you have an adjustable voltage source for this pin?  It is possible you may be communicating with the display but you don't see anything because of the contrast voltage on pin 3 being off.  Also, can you change your first line of code in your init() routine to E = 1?
Title: Re: LCD not working with PIC16
Post by: fxdxrdr on September 25, 2014, 10:20:36 AM
Thank you for the reply
I will try changing E=0 to E= 1. Voltage to Pin3 (V0) is run through a trimmer. However the trimmer is turned all the way, at this point and Pin3 is receiving 4.6 volts.
Title: Re: LCD not working with PIC16
Post by: fxdxrdr on September 25, 2014, 07:25:25 PM
Changed E = 0 to E= 1, connected 9v with power supply to get 4.88 volts at pic 3 as well as pin 2. Still nothing  :(
Title: Re: LCD not working with PIC16
Post by: Michael_L on September 29, 2014, 08:53:22 AM
Pin 3 should have approx. 0.5V, as stated in the pin description of the datasheet.  With the voltage you are applying to it, you wont see anything on the display at all.  Please correct this and try again.
Title: Re: LCD not working with PIC16
Post by: fxdxrdr on October 02, 2014, 07:09:14 PM
Michael_L,
you are correct! Thank you so much, that did it!