Author Topic: LCD not working with PIC16  (Read 3868 times)

fxdxrdr

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
LCD not working with PIC16
« 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;
}



Michael_L

  • Administrator
  • Hero Member
  • *****
  • Posts: 356
  • Karma: 33
    • View Profile
Re: LCD not working with PIC16
« Reply #1 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?

fxdxrdr

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Re: LCD not working with PIC16
« Reply #2 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.

fxdxrdr

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Re: LCD not working with PIC16
« Reply #3 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  :(

Michael_L

  • Administrator
  • Hero Member
  • *****
  • Posts: 356
  • Karma: 33
    • View Profile
Re: LCD not working with PIC16
« Reply #4 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.

fxdxrdr

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Re: LCD not working with PIC16
« Reply #5 on: October 02, 2014, 07:09:14 PM »
Michael_L,
you are correct! Thank you so much, that did it!

 

Working on NHD‐2.4‐240320SF‐CTXL#‐FTN1, have problem in initialization

Started by sli25Board TFTs

Replies: 6
Views: 3924
Last post June 04, 2015, 09:52:25 PM
by sli25
Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 9269
Last post July 10, 2014, 08:46:06 AM
by Michael_L
NHD‐1.5‐128128UGC3 some commands not working

Started by lordavonBoard OLEDs

Replies: 4
Views: 2379
Last post January 07, 2016, 10:58:36 PM
by lordavon
MOVED: working with nhd-7.0-800480ef-asxv-t with buildroot framebuffer

Started by Saurabh_BBoard Graphic LCDs

Replies: 0
Views: 120
Last post November 16, 2017, 08:14:59 AM
by Saurabh_B
working with nhd-7.0-800480ef-asxv-t with buildroot framebuffer

Started by mnylund05Board TFTs

Replies: 2
Views: 179
Last post November 17, 2017, 08:40:34 AM
by mnylund05