Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 16 x 2 LCD interfacing problem

Status
Not open for further replies.

Venkadesh_M

Advanced Member level 4
Advanced Member level 4
Joined
Jun 26, 2013
Messages
1,374
Helped
258
Reputation
516
Reaction score
254
Trophy points
1,363
Location
Coimbatore, India
Visit site
Activity points
8,020
Hi all,
I am using PIC 16f877A with lcd jhd 162a. I am trying to interfacing in a 4 bit mode.
I am doing all this

sending command as said in manual and followed by data
but i am getting clear screen on first line and block boxes on second line.
Code:
0x3
0x3
0x3
0x28 //for 4 bit mode
0x08
0x38
0x01 // clear display
after that i am sending data to LCD
I am very new to lcd please help me.....
 

i think u need check you connection TX RX
sorry i mean: ur config....

if u use Mikroc
HelloWorld_LCD_MikroC.png
Code:
// LCD module connections
sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB7_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB7_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
void main()
{
 Lcd_Init(); // Initialize LCD
 Lcd_Cmd(_LCD_CLEAR); // Clear display
 Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
 Lcd_Out(1,1,"Hello World");//Write text'Hello World' in first row
}
 
Last edited:

U really Bad boy if don't know don't reply

- - - Updated - - -

U connect lower port or higher port bit for sending data . also after each place few ms delay which is compulsory

- - - Updated - - -

U connect lower port or higher port bit for sending data . also after each place few ms delay which is compulsory

delay1(3500);
lcd_write_nibble(ctrl_instr,0x03);
delay1(5000);
lcd_write_nibble(ctrl_instr,0x03);
delay1(250);
lcd_write_nibble(ctrl_instr,0x03);
delay1(250);
lcd_write_nibble(ctrl_instr,0x02);
delay1(250);
//-------------------------------------------------------------------
lcd_write_nibble(ctrl_instr,0x02);
lcd_write_nibble(ctrl_instr,0x08);
delay1(10);
//-------------------------------------------------------------------
lcd_write_nibble(ctrl_instr,0x00);
lcd_write_nibble(ctrl_instr,0x08);
delay1(10);
//-------------------------------------------------------------------
lcd_write_nibble(ctrl_instr,0x00);
lcd_write_nibble(ctrl_instr,0x0C);
delay1(10);
 
Golden electronics for my doubt i given 30ms delay between enable as well as each instruction. still its not working it makes clearing display in upper row.
is that a over delay or any mistake in commanding sequence??
 

please clear me ur hardware pin details means which pin used. Can u check is ur controller working for this u may blink any led cont.. sill problem then inform i send details according to ur code
 
Ya I checked other ports with output LEDs everything works fine. and the portd LCD pins also changing.
I am adding the codes here please check and found out . .

- - - Updated - - -
- - - Updated - - -

Code:
#include <pic.h>
#include <htc.h>

#define _XTAL_FREQ 20000000

#define RW RD2
#define RS RD3
#define EN RD1
#define databits PORTD

void delay_ms(void)
{
__delay_ms(31);
__delay_ms(31);
__delay_ms(31);
}

void data(unsigned char c)
{
	delay_ms();
 	databits = ( c & 0xF0 ) | 0x08 | 0x02;
   	delay_ms();
	databits = ( c & 0XF0 ) | 0x08;
        delay_ms();
        databits = ( ( c << 4 ) & 0xF0 ) | 0x08 | 0x02;
        delay_ms();
	databits = ( ( c << 4 ) & 0XF0 ) | 0x08;
	delay_ms();
}

void cmd(unsigned char c)
{
	delay_ms();
 	databits = ( c & 0xF0 ) | 0x02;
       delay_ms();
	databits = ( c & 0XF0 );
        delay_ms();
 	databits = ( ( c << 4 ) & 0xF0 ) | 0x02;
        delay_ms();
	databits = ( ( c << 4 ) & 0XF0 );
	delay_ms();
}


main()
{
        TRISD = 0;
	TRISC = 0;
	delay_ms();
        delay_ms();
        delay_ms();
        delay_ms();
        cmd(0x33);
        delay_ms();
	cmd(0x32);
        delay_ms();
	cmd(0x28);
        delay_ms();
	cmd(0x08);
        delay_ms();
	cmd(0x01);
        delay_ms();
	cmd(0x06);
	RC1 = 1;
        delay_ms();
	data('V');
        delay_ms();
	data('E');
        delay_ms();
	data('N');
        delay_ms();
	data('K');
        delay_ms();
	data('A');
        delay_ms();
	data('D');
        delay_ms();
	data('E');
        delay_ms();
	data('S');
        delay_ms();
	data('H');
	RC0 = 1;
}


RD7 to DB7
RD6 to DB6
RD5 to DB5
RD4 to DB4
RD3 to RS
RD2 to RW
RD1 to EN
 

Venkadeshm,
try to sync LCD to processor, may be they are running at different speeds

0x03
0x03
0x03
0x02 // you add this


first go to basics how you are sending a command and data to LCD.

command mode should go like this

data=buf//read buff
Rs=0,
Rw=0,
En =1,
some delay
En=0

data mode should go like this
Rs=1
Rw=0
En =1
some delay
En=0

no where you mentioned so while sending data , you just masked the data .

learn to comment your code, others have to understand what you are sending to suggest you.



** Use library functions it would be better
 

Thankyou Raady,
I mentioned the pin assignments in a particular port and I am packing the data as for the required RS and En inputs,
Commonly every one doing so thats why i didnt mentioned it..

Thanks for all............
My lcd is working very very fine....
What i did wrong is i didnt on the display, i just follow the procedure to initialize the lcd in its manual...
now its looks easy and fine thank you all...
 

Code:
#include <pic.h>
#include <htc.h>

#define _XTAL_FREQ 20000000

#define RW RD2
#define RS RD3
#define EN RD1
#define databits PORTD

void data(unsigned char c)
{
	databits = ( c & 0xF0 ) | 0x08 | 0x02;
   	__delay_us(50);
	databits = ( c & 0XF0 ) | 0x08;
    __delay_us(50);
	databits = ( ( c << 4 ) & 0xF0 ) | 0x08 | 0x02;
    __delay_us(50);
	databits = ( ( c << 4 ) & 0XF0 ) | 0x08;
}

void cmd(unsigned char c)
{
	databits = ( c & 0xF0 ) | 0x02;
   	__delay_us(50);
	databits = ( c & 0XF0 );
    __delay_us(50);
	databits = ( ( c << 4 ) & 0xF0 ) | 0x02;
    __delay_us(50);
	databits = ( ( c << 4 ) & 0XF0 );
}

void init(unsigned char c)
{
	databits = ( c & 0xF0 ) | 0x02;
   	__delay_us(50);
	databits = ( c & 0XF0 );
    __delay_ms(10);
	databits = ( ( c << 4 ) & 0xF0 ) | 0x02;
    __delay_us(50);
	databits = ( ( c << 4 ) & 0XF0 );
}

void puts(char* str)
{	
	cmd(0x01);
	cmd(0x80);
	__delay_ms(31);
    for(char i = 0; str[i] != 0; i++)
	{
    __delay_us(20);
	data(str[i]);
	}
}
    
void lcd_init(void)
{
    __delay_ms(16);
    init(0x33);
    __delay_ms(1);
	cmd(0x32);
    __delay_us(20);
	cmd(0x2C);
    __delay_us(20);
	cmd(0x0C);
    __delay_us(20);
	cmd(0x06);	
	__delay_us(20);
	cmd(0x0C);
	__delay_us(20);
	cmd(0x01);
    __delay_us(20);
	cmd(0x80);
    __delay_us(20);
	
}


main()
{
	char i, wel[]="    WELCOME";

    TRISD = 0;
	TRISC = 0;
	RC0 = RC1 = RC2 = 0;

	lcd_init();

	puts(wel);

 

	for( i = 0; i < 50; i++)
	__delay_ms(30);


	while(1);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top