Hello, I recently purchased a Newhaven 2x8 Character LCD (Model: NHD‐0208BZ‐RN‐GBW). This is my first time programming for a character LCD, and I am having a bit of trouble getting this 2x8 LCD to work with my PIC18F4550. I am using MPLAB v8.76 with C18 Lite compiler (for programming in C).
I will be programming the LCD in 4-bits at a time. Here is the data sheet for the LCD I am using: https://www.electro-tech-online.com/custompdfs/2011/10/NHD-0208BZ-RN-GBW.pdf
Model: NHD-0208BZ-RN-GBW
(It is a 2x8 14pin (no backlight) character LCD display)
Updated:
Here is a diagram of the connections:
**broken link removed**
The data sheet provides me with the following code layout for the initialization:
Solved: Here is the code and a quick video.
Thank you everyone so much, I made a video to show a token of my appreciation:
https://www.youtube.com/watch?v=ZkrgRjbVZtQ
Here is the final code with the routine shown in the video:
(Note: This program uses the default clock of the 18F4550, which is 1MHz. Be sure to change the delays if you have it configured to operate at a different frequency).
Solved
I will be programming the LCD in 4-bits at a time. Here is the data sheet for the LCD I am using: https://www.electro-tech-online.com/custompdfs/2011/10/NHD-0208BZ-RN-GBW.pdf
Model: NHD-0208BZ-RN-GBW
(It is a 2x8 14pin (no backlight) character LCD display)
Updated:
Here is a diagram of the connections:
**broken link removed**
The data sheet provides me with the following code layout for the initialization:
Code:
4-bit Initialization:
/**********************************************************/
void command(char i)
{
P1 = i; //put data on output Port
D_I =0; //D/I=LOW : send instruction
R_W =0; //R/W=LOW : Write
Nybble(); //Send lower 4 bits
i = i<<4; //Shift over by 4 bits
P1 = i; //put data on output Port
Nybble(); //Send upper 4 bits
}
/**********************************************************/
void write(char i)
{
P1 = i; //put data on output Port
D_I =1; //D/I=HIGH : send data
R_W =0; //R/W=LOW : Write
Nybble(); //Clock lower 4 bits
i = i<<4; //Shift over by 4 bits
P1 = i; //put data on output Port
Nybble(); //Clock upper 4 bits
}
/**********************************************************/
void Nybble()
{
E = 1;
Delay(1); //enable pulse width >= 300ns
E = 0; //Clock enable: falling edge
}
/**********************************************************/
void init()
{
P1 = 0;
P3 = 0;
Delay(100); //Wait >15 msec after power is applied
P1 = 0x30; //put 0x30 on the output port
Delay(30); //must wait 5ms, busy flag not available
Nybble(); //command 0x30 = Wake up
Delay(10); //must wait 160us, busy flag not available
Nybble(); //command 0x30 = Wake up #2
Delay(10); //must wait 160us, busy flag not available
Nybble(); //command 0x30 = Wake up #3
Delay(10); //can check busy flag now instead of delay
P1= 0x20; //put 0x20 on the output port
Nybble(); //Function set: 4-bit interface
command(0x28); //Function set: 4-bit/2-line
command(0x10); //Set cursor
command(0x0F); //Display ON; Blinking cursor
command(0x06); //Entry Mode set
}
/**********************************************************/
Solved: Here is the code and a quick video.
Thank you everyone so much, I made a video to show a token of my appreciation:
https://www.youtube.com/watch?v=ZkrgRjbVZtQ
Here is the final code with the routine shown in the video:
(Note: This program uses the default clock of the 18F4550, which is 1MHz. Be sure to change the delays if you have it configured to operate at a different frequency).
Code:
//turns watch dog timer off, turn low voltage programming off
#pragma config WDT=OFF, LVP=OFF, DEBUG=ON, MCLRE = OFF
//Internal oscillator, port function on RA6, EC used by USB
#pragma config FOSC = INTOSCIO_EC
#include <p18f4550.h>
#include <delays.h>
//Power LED (PortA)
#define LEDPin LATAbits.LATA0 //Define LEDPin as PORT A Pin 1
//LCD (PortD)
#define E LATDbits.LATD6
#define R_W LATDbits.LATD5
#define RS LATDbits.LATD4
#define LCDdata LATD
void command(unsigned char);
void write(unsigned char);
void Nybble(unsigned char);
void init(void);
void PutMessage(rom char *);
void main()
{
while(!OSCCONbits.IOFS); //wait for osc stable
ADCON1 = 0x0F; //make RA0 digital
//data direction registers all 0's mean that all pins are set to output
//all 1's means that all of the pins are set to operate as inputs
TRISA = 0x00;
TRISB = 0x00;
TRISD = 0x00;
init();
while(1)
{
PutMessage("Thanks");
command(0xc0);
PutMessage("Pommie");
Delay10KTCYx(50);
command(0x01); //Clear Display (Added)
PutMessage("Thank");
command(0xc0);
PutMessage("You");
Delay10KTCYx(50);
command(0x01); //Clear Display (Added)
PutMessage("Electro");
command(0xc0);
PutMessage("tech");
Delay10KTCYx(50);
command(0x01); //Clear Display (Added)
PutMessage("Forum");
command(0xc0);
PutMessage("members");
Delay10KTCYx(50);
command(0x01); //Clear Display (Added)
}
}
//Write a string to the LCD
void PutMessage(rom char *Message){
rom char *Pos = Message;
while(*Pos!=0)
write(*Pos++);
}
/**********************************************************/
//4-bit methods for LCD
/**********************************************************/
void command(unsigned char i)
{
RS =0;
R_W =0; //R/W=LOW : Write
Nybble(i>>4); //Send upper 4 bits
Nybble(i); //Send lower 4 bits
Delay1KTCYx(2); //must wait at least 2mS (2*1000*4/1e6 = 8ms used)
}
void write(unsigned char i)
{
RS =1;
R_W =0; //R/W=LOW : Write
Nybble(i>>4); //Send upper 4 bits
Nybble(i); //Send lower 4 bits
Delay1KTCYx(2); //must wait 2mS
}
/**********************************************************/
void Nybble(unsigned char dat)
{
dat &= 0x0f; //clear top bits of dat
LCDdata &= 0xf0; //clear bottom bits of port (interested only in DB7-DB4)
LCDdata |= dat; //or the two and store at port
E = 1;
Delay1TCY(); //enable pulse width >= 300ns (used 4uS)
E = 0; //Clock enable: falling edge
}
/**********************************************************/
void init(void)
{
LCDdata=0x00;
Delay1KTCYx(15); //Wait >15 msec after power is applied (used 20mS)
Nybble(0x3); //command 0x30 = Wake up
Delay1KTCYx(5); //must wait 160us, busy flag not available (used 160uS)
Nybble(0x3); //command 0x30 = Wake up #2
Delay1KTCYx(5); //must wait 160us, busy flag not available (used 160uS)
command(0x20); //Function set: 4-bit/2-line
command(0x2c); //Function set: 4-bit/2-line
command(0x10); //Set cursor
command(0x01); //Clear Display (Added)
command(0x06); //Entry Mode set
command(0x0c);
}
/**********************************************************/
//End methods for LCD
/**********************************************************/
Solved
Last edited: