Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Problem with lcd-jhd162a !!!!!!!

Status
Not open for further replies.

shrinidhi kulkarni

Newbie level 5
Joined
Feb 24, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,405
hi,
i am using 16f877a... to control temperature.i have simulated the program in oshonsoft.... Simulation works perfect. But wen i make connections , on llcd display.. i get 1st row as black boxes..i have seen all related posts here in edaboard ..still problem is ther.. Kindly help..Below is the program , i am working with :

#include<pic.h>

//===============configuration==============================
__CONFIG (0x3F32);

//===============define IO port=============================

#define lcd PORTC
#define RS RA2
#define E RA5
#define CHANNEL0 0b10000001 // AN0
#define CHANNEL1 0b10001001 // AN1
#define buzzer RB5
#define fanA RB4
#define fanB RB3
#define ledA RB2
#define ledB RB1

//==============FUNCTION PTOTOTYPE=========================
void e_pulse(void);
void delay(unsigned short i);
void send_char(unsigned char data);
void send_config(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void dis_num(unsigned long data);
void increment(unsigned long data);
void read_adc(void);
unsigned short read_temp(void);

//====================MAIN================================
unsigned short result;
unsigned short temp,tempA,tempB;

void main(void)
{
ADRESH=0; //clear A/D result
ADRESL=0; //clear A/D result

//setting ADCON1 Register
ADCON1=0b11000101; // A/D result right justified,
// configure RA2 and RA5 as digital I/O

TRISA=0b11011011; //configure PORTA I/O direction
TRISB=0b00000000; //configure PORTB as output
TRISC=0b00000000; //configure PORTC as output

PORTA=0;
PORTB=0;

while(1)
{
send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function set

lcd_goto(0); //cursor start from beginning

//display character on LCD
send_char(' ');
send_char('T');
send_char('E');
send_char('M');
send_char('P');
send_char('.');
send_char('A');
send_char('=');

lcd_goto(20); //cursor go to 2nd line of the LCD

//display character on LCD
send_char(' ');
send_char('T');
send_char('E');
send_char('M');
send_char('P');
send_char('.');
send_char('B');
send_char('=');

while(1) //infinity loop
{
//sensor A
ADCON0=CHANNEL0; //CHANNEL1=0b10001001
lcd_goto(8);

read_adc();

temp=read_temp();
dis_num(temp/10);
send_char('.');
dis_num(temp%10);
send_char(0b11011111);
send_char('C');
send_char(' ');
send_char(' ');

tempA=temp;

//sensor B
ADCON0=CHANNEL1; //CHANNEL0=0b10000001

lcd_goto(28);

read_adc();

temp=read_temp();
dis_num(temp/10);
send_char('.');
dis_num(temp%10);
send_char(0b11011111);
send_char('C');
send_char(' ');
send_char(' ');

tempB=temp;

if((tempA>400)&&(tempB<350)) // *****************************************
{ // * LED A and Fan A activated only for *
ledA=1; // * temperature A greater than 40'C *
ledB=0; // * and temperature B less than 35'C *
fanA=1; // *****************************************
fanB=0;
buzzer=0;
}

else if((tempB>350)&&(tempA<400)) // *****************************************
{ // * LED B and Fan B activated only for *
ledA=0; // * temperature A less than 40'C and *
ledB=1; // * temperature B greater than 35'C *
fanA=0; // *****************************************
fanB=1;
buzzer=0;
}

else if((tempB>350)&&(tempA>400)) // *****************************************************
{ // * All LED A & LED B, Fan A & Fan B and Buzzer *
ledB=1; // * activated for temperature A greater than 40'C *
ledA=1; // * and temperature B greater than 35'C *
fanA=1; // *****************************************************
fanB=1;
buzzer=1;
}

else if((tempB<350)&&(tempA<400)) // *****************************************************
{ // * All LED A & LED B, Fan A & Fan B and Buzzer *
ledB=0; // * disactivated for temperature A less than 40'C *
ledA=0; // * and temperature B less than 35'C *
fanA=0; // *****************************************************
fanB=0;
buzzer=0;
}

delay(4000);

}

}

}



//==================subroutine LCD setting ==========================

void send_config(unsigned char data)
{
RS=0;
lcd=data;
delay(700);
e_pulse();
}

void e_pulse(void)
{
E=1;
delay(700);
E=0;
delay(700);
}

void send_char(unsigned char data)
{
RS=1;
lcd=data;
delay(900);
e_pulse();
}


void lcd_goto(unsigned char data)
{
if(data<16)
{
send_config(0x80+data);
}
else
{
data=data-20;
send_config(0xc0+data);
}
}


void lcd_clr(void)
{
RS=0;
send_config(0x01);
delay(1000);
}


void dis_num(unsigned long data)
{
unsigned char hundred_thousand;
unsigned char ten_thousand;
unsigned char thousand;
unsigned char hundred;
unsigned char tenth;

hundred_thousand = data/100000;
data = data % 100000;
ten_thousand = data/10000;
data = data % 10000;
thousand = data / 1000;
data = data % 1000;
hundred = data / 100;
data = data % 100;
tenth = data / 10;
data = data % 10;

if(hundred_thousand>0)
{
send_char(hundred_thousand + 0x30); //0x30 added to become ASCII code
send_char(ten_thousand + 0x30);
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}

else if(ten_thousand>0)
{
send_char(ten_thousand + 0x30); //0x30 added to become ASCII code
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(thousand>0)
{
send_char(thousand + 0x30); //0x30 added to become ASCII code
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(hundred>0)
{
send_char(hundred + 0x30); //0x30 added to become ASCII code
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(tenth>0)
{
send_char(tenth + 0x30); //0x30 added to become ASCII code
send_char(data + 0x30);
}
else send_char(data + 0x30); //0x30 added to become ASCII code
}

void increment(unsigned long data)
{
unsigned short j;
for(j=10;j>0;j--)
{ lcd_goto(32);
data=data+1;
dis_num(data);
delay(10000);
}

}

//==================subroutine ADC=========================

void read_adc(void)
{
unsigned short i;
unsigned long result_temp=0;
for(i=2000;i>0;i-=1) //looping 2000 times for getting average value
{
ADGO = 1; //ADGO is the bit 2 of the ADCON0 register
while(ADGO==1); //ADC start, ADGO=0 after finish ADC progress
result=ADRESH;
result=result<<8; //shift to left for 8 bit
result=result|ADRESL; //10 bit result from ADC

result_temp+=result;
}
result = result_temp/2000; //getting average value

}

unsigned short read_temp(void)
{
unsigned short temp;
temp=result;
return temp;

}

//==================subroutine DELAY==========================
void delay(unsigned short i)
{
for(;i>0;i--);
}
 

nandhu015

Advanced Member level 5
Joined
Feb 11, 2006
Messages
1,965
Helped
300
Reputation
600
Reaction score
224
Trophy points
1,353
Location
India
Activity points
9,825
LCD should be initialized properly. I cant see any initialization sequence in your code.
 

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
750
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,049
Oshonsoft simulator will simulate LCD even the initialization procedure is not so perfect. So i think in your code the initialization is not proper. Any way i cant check it properly because i am replying through my mobile. It has to follow certain steps which is recommended by the manufacturer. Or else there may be some problem with your connections . Check crystal frequency if its the same as in design. But most probably this is due to the wrong initialization. LCD will start working only after proper initialization. Pls wait i will provide my final working code for 4 bit LCD initialization. I also faced the same problem two months ago.

---------- Post added at 03:48 ---------- Previous post was at 03:32 ----------

////////////////////////////////////////////////////////////////
//16x2 LCD with PIC16F877A ///
//RS= RC4 R/W=ground ///
//EN=RC5 ///
//DATA=PORTB ( LOWER 4 BITS ) ///
//connect RB0 to D4, RB1 to D5, .....RB3 to D7 of LCD ///
////////////////////////////////////////////////////////////////
#include <htc.h>
#define _XTAL_FREQ 20e6 // 20MHz
__CONFIG(0x3F3A);
#define RS RC4
#define EN RC5
///////////////////////////////////////////////////////////////////
void LCD_STROBE(void)
{
EN = 1;
__delay_us(0.5);
EN = 0;
}
////////////////////////////////////////////////////////////////////
void data(unsigned char c)
{ RS=1;
__delay_us(40);

PORTB = ( c >> 4 );LCD_STROBE();
PORTB = ( c );LCD_STROBE();

}
//////////////////////////////////////////////////////////////////
void cmd(unsigned char c)
{ RS=0;
__delay_us(40);

PORTB = ( c >> 4 );LCD_STROBE();
__delay_ms(2);
PORTB = ( c );LCD_STROBE();
__delay_ms(2);
}
/////////////////////////////////////////////////////////////////
void clear(void)
{
cmd(0x1);
__delay_ms(2);
}
/////////////////////////////////////////////////////////////////
void lcd_init()
{
__delay_ms(20);
cmd(0x03);
__delay_us(200);
cmd(0x03);
__delay_us(200);
cmd(0x03);
cmd(0x28 ); // Function set (4-bit interface, 2 lines, 5*7 Pixels)
cmd(0x0c); // Make cursor invisible
clear(); // Clear screen
cmd(0x6); // Set entry Mode
}
////////////////////////////////////////////////////////////////
void string(const char *q)
{
while(*q)
data(*q++);
}
/////////////////////////////////////////////////////////////////
void main()
{__delay_ms(100);
PORTB=0;PORTC=0;TRISB=0;
TRISC=0b11001111;
__delay_ms(15);
lcd_init();
////////////////////////////////////////////////////////////////
cmd(0x82);//simply to start display from 3rd column of first row//
//first row start address is 0x80 and second row is 0xC0//
string("HELLO WORLD");
cmd(0xC0); //NEXT LINE START ADDRESS//
string("LCD 4-BIT MODE");

////////////////////////////////////////////////////////////////
while(1);
////////////////////////////////////////////////////////////////
}

The above program is for 4 bit mode.
 
Last edited:

shrinidhi kulkarni

Newbie level 5
Joined
Feb 24, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,405
LCD should be initialized properly. I cant see any initialization sequence in your code.
this part of code initializes lcd...
but i don't know wats wrong???
send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function set
 

qwertyuiop415263

Full Member level 4
Joined
Mar 26, 2010
Messages
232
Helped
50
Reputation
102
Reaction score
39
Trophy points
1,308
Location
Pakistan
Activity points
2,414
it should be like this
//after every command you have to give a reasonable delay about 100ms to 200ms
send_config(0x38);
Delay(200); // 200ms delay
send_config(0x0E);
Delay(200);
send_config(0x01);
Delay(200);
send_config(0x80);
Delay(200);

hope this help
 

shrinidhi kulkarni

Newbie level 5
Joined
Feb 24, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,405
i went through the link... was very useful to understand lcd.
But,
now pinout voltages from PIC MCU for lcd are...
0
5.12
0
0.05
0
0
0.5
0.4
0.4
0.5
0.5
0.4
0.5
0.5
5.12
0

but wen i check voltage at 16 pins on lcd panel.. it is :
0
5.09
5.03
4.99
4.99
0
4.99
4.99
4.99
4.99
5
5
5
5
5.09
0

are the values correct???
now.. my lcd appears fully blank. even wen i connect pin 3 of lcd to GND.

I have to get project done ..fast.. do u know anybody in b'lore..so that i can go and contact him in person..???

check the below links: (LCD initialization in 8 bit mode )

HD44780 Controlled LCD

AND

HD44780 Commands _ for LCD commands.
 

qwertyuiop415263

Full Member level 4
Joined
Mar 26, 2010
Messages
232
Helped
50
Reputation
102
Reaction score
39
Trophy points
1,308
Location
Pakistan
Activity points
2,414
this is the code for pic18f452 using mplab and C-18
i have tested it on hardware

#pragma config OSC=HS, OSCS=OFF
#pragma config PWRT=OFF, BOR=ON, BORV=45
#pragma config WDT =OFF
#pragma config DEBUG=OFF,LVP=OFF,STVR=OFF
#include <P18F452.h>
void LcdCommand (unsigned char);
void LcdData (unsigned char);
void Delay (int);
#define LcdByte LATB
#define RegSelect LATDbits.LATD5
#define ReadWrite LATDbits.LATD6
#define Enable LATDbits.LATD7


void main()
{
int count=0;
char Line1[] = "16x2 LCD DISPLAY";
char Line2[] = " WITH PIC18F452!";
LATB=0;
TRISB=0;
LATD=0;
TRISD=0;
Delay (250);
LcdCommand (0x38);
Delay (250);
LcdCommand (0x0E);
Delay (250);
LcdCommand (0x01);
Delay (250);
LcdCommand (0x06);
Delay (250);
while(Line1[count] != '\0')
{
LcdData(Line1[count]);
count++;
}
LcdCommand(0xC0);
count=0;
while(Line2[count] != '\0')
{
LcdData(Line2[count]);
count++;
}
}

void LcdCommand (unsigned char value)
{
LcdByte=value;
RegSelect=0;
ReadWrite=0;
Enable=1;
Delay (50);
Enable=0;
}


void LcdData (unsigned char value)
{
LcdByte=value;
RegSelect=1;
ReadWrite=0;
Enable=1;
Delay (50);
Enable=0;
}


void Delay (int a)
{
unsigned char y;
int i;
for (i=0;i<a;i++)
for (y=0;y<180;y++);
}



hope it helps
 

kandhu26

Member level 5
Joined
Sep 7, 2009
Messages
93
Helped
13
Reputation
26
Reaction score
12
Trophy points
1,288
Location
chennai / bangalore
Activity points
1,856
This is the code for LCD [2x16] initialization [for 8051{you could convert to your controller}]..

void Delay(unsigned int time)
{
while(time--);
}

void Enable_LCD (unsigned char dta, bit RegSel)
{
RW = 0;
RS = RegSel;
EN = 1;
LCD_DTA = dta;
Delay(10);
EN = 0;
}

void Init_LCD(void)
{
Enable_LCD(0x38,0); // 8bit, multiple line, 5x7 display
Delay(10000);
Enable_LCD(0x38,0); // 8bit, multiple line, 5x7 display
Delay(1000);
Enable_LCD(0x38,0); // 8bit, multiple line, 5x7 display
Delay(100);
Enable_LCD(0x1C,0); // Shift entire display to right
Delay(100);
Enable_LCD(0x0E,0); // Cursor on & blink off
Delay(100);
Enable_LCD(0x06,0); // Increment with no shift
Delay(100);
Enable_LCD(0x02,0); // Home cursor
Delay(100);
Enable_LCD(0x01,0); // Clear display
Delay(100);
}
 
Last edited:

abidr

Full Member level 5
Joined
Feb 14, 2007
Messages
255
Helped
37
Reputation
74
Reaction score
32
Trophy points
1,308
Location
33 N, 73 E
Activity points
2,682
You could make your life much easier and code easier to read by using the following LCD_Init routines:

Code:
void LCD_init(void)
{
unsigned char data;
unsigned char i;	
	TRISA = 0x00;	//PORTA all outputs
	LCD.RS = 0;
	for(i=1;i<=3;++i)
	{
		LCD.RS = 0;
		LCD.DATA = 3;
		LCD.E = 1;
		DelayUs(5);
		LCD.E = 0;
		DelayMs(5);
	}
	LCD_send_nibble(2);
	LCD_send_command(0x28);
	LCD_send_command(0x0C);
	LCD_send_command(0x01);
	LCD_send_command(0x06);
}

void LCD_send_nibble(unsigned char c ) 
	{
		LCD.DATA = c;
		LCD.E = 1;
		DelayUs(5);
		LCD.E = 0;
	}

void LCD_send_command(unsigned char command)
{
	DelayMs(5);
	LCD.RS = 0;
	LCD_send_nibble(command>>4);
	LCD_send_nibble(command&0x0F);
}
 

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
750
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,049
friend dont mind about PIC output pin voltage etc...If you are sure that you never given the Vdd and Vss of LCD in reverse , then no problem your LCD is good only. Could you tell me your crystal frequency ? Then i will post here some hex files for your pin configurations. You can just burn it in your PIC and can make sure that your Lcd is good or bad.
 

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
750
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,049
in your initialization sequence give command 0x38 at first for atleast 3 times with delay(10000). Then after that only give commands for LCD clear , entry mode etc etc...just try this . Still not working then just introduce a delay of about delay(1000) after every command function.
Still not working then inform.


And you replied as "now my LCD become blank" ... Is it blank or black row? If it become blank then its better.
 

shrinidhi kulkarni

Newbie level 5
Joined
Feb 24, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,405
friend dont mind about PIC output pin voltage etc...If you are sure that you never given the Vdd and Vss of LCD in reverse , then no problem your LCD is good only. Could you tell me your crystal frequency ? Then i will post here some hex files for your pin configurations. You can just burn it in your PIC and can make sure that your Lcd is good or bad.
Ya... i never gave vdd and vss in reverse... but i did give 5volt dc to pin3 of lcd... which i now..know , should be given less than 1volt.
my Crystal freq is 20MHz... give me some basic display programs.. i will check with my lcd...Thanks :)

---------- Post added at 22:05 ---------- Previous post was at 21:47 ----------

in your initialization sequence give command 0x38 at first for atleast 3 times with delay(10000). Then after that only give commands for LCD clear , entry mode etc etc...just try this . Still not working then just introduce a delay of about delay(1000) after every command function.
Still not working then inform.


And you replied as "now my LCD become blank" ... Is it blank or black row? If it become blank then its better.
okie..will try... I have my exams ..now.. will work after 3 days from now on lcd...

Ya , now my lcd is 'blank' with yello backlight.
 

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
750
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,049
okay....no problem ...your LCD is good... I will send some hex files . But just now i am at college. Everything is in my home only...Any way you can try after 3 days. If not working then i will provide some helloworld program.
 

shrinidhi kulkarni

Newbie level 5
Joined
Feb 24, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,405
hey......:) i got the display ..... there was a problem with connections to lcd pins.. also the r/w pin was connected to some i/o pin... now grounded it.
It's working !! :)

Thanks
 

qwertyuiop415263

Full Member level 4
Joined
Mar 26, 2010
Messages
232
Helped
50
Reputation
102
Reaction score
39
Trophy points
1,308
Location
Pakistan
Activity points
2,414
how you got the display r/w pin should be connected to I/O pin. r/w is included in control signals.
 

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
750
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,049
Oh that was ur problem! Any way u solved it..:grin:
R/W TO GROUND
Actually an LCD requires some time to process a data or command which we had given to it. Then in most case , we guess the delay required and we give a delay which is more than enough for the LCD to accept next data or command.
Thus we generally ground the R/W which makes the LCD work always in write mode(we r not reading any busy information from the LCD)

R/W TO PORT PIN
In this case, what we do is , we read the lcd busy flag and wait untill it is cleared. We just connect R/W to any port pin ,say ,

#define wr RC1

Now if we give a value to write to LCD, either it is command or data, no matter, in both function of cmd ad data, we introduce a LCD BUSY check function.
This is like below:
#define busy TRISD=0x80;rs=0;wr=1;do{enable=1;enable=0;}while(RD7==1);TRISD=0x00;

now we add " busy; " at the starting of both command and data write function.
So in this case, LCD will generate 1 at its MSB pin while LCD is busy. Then when this bit become 0 it means LCD is now ready to accept a data/command!, then in program , we make R/W =0 and set data/cmd port of microcontroller as O/P port and then we send data/command.

this will look like,

void cmd(unsigned char c)
{
busy;
rs=0;
wr=0;
PORTD=c;
enable=1;
enable=0;
}
void data(unsigned char c)
{
busy;
rs=1;
wr=0;
PORTD=c;
enable=1;
enable=0;
}

In this case, no need to bother about the delay and can save extra delay time which we generally give in first case(R/W ground) and increase the efficiency of the data transfer between the \mu C and LCD.
 
Last edited:

anzilkhan

Junior Member level 1
Joined
Aug 15, 2010
Messages
18
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Location
india
Activity points
1,399
dont ever trust any simulators. u will hv a bag full of problems when it comes to da practical aspect. I thk u should try to output the string to seria port first n if working fine, ther is definitely somethg wrong with ur lcd initialisatio. try passing commands (to move or blink cursor) first...The meaning of ur black boxes r simply u went wrong wt ur initialisation
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,700
Helped
4,805
Reputation
9,627
Reaction score
4,586
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
125,232
Another thing to be aware of is the power-up time of the LCD. It needs about 100mS before ANY commands are sent to it and when it has woken up, the busy line will not be usable. Try simply adding a delay before the LCD initialization commands.

Also consider the contrast control voltage, if wrong it can make all the characters invisible or all black pixels.

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top