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 - fxdxrdr

Pages: [1]
1
Character LCDs / 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;
}



Pages: [1]