View Full Version : JHD162A and atmega32 interface problems

01-09-2011, 04:55 PM
I am a newbie to microcontrollers and their programming.Recently I bought a JHD162A i.e.. 16X2 alphanumeric lcd display, and made the interface with the atmega32 using 4bit interface.The lcd just flashes and gets back to its general contrast configuration.I am using Code Vision AVR.I have made the pin configuration as given below
PD3=not connected
PD 4-7 = DB4-7

The program that I used is given below:

Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 4.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
************************************************** ***/

#include <mega32.h>

// Alphanumeric LCD Module functions
.equ __lcd_port=0x12 ;PORTD
#include <lcd.h>

#include <delay.h>

// Declare your global variables here

void main(void)
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off

// Timer(s)/Counter(s) Interrupt(s) initialization

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off

// LCD module initialization

while (1)
// Place your code here

Please help me, the lcd is just flickering....

Need help from you.

01-09-2011, 05:20 PM
I just now tested the LCD module for proper working and also put a LED to display whether lcd_init(16) gives back a value 1 and found that the function lcd_init(16) is working fine and is returning a value of 1 , but still nothing is displayed on the lcd and it is still blank

01-09-2011, 06:14 PM
Try putting the statements within the while loop outside the loop.

And please do not double post.

01-10-2011, 10:27 AM
So lets solve your problem as fast as possible. First we need to find out weather your hw or sw has the problem. Just flash the MCU with this hex file. It is a tested hex file that will work for your configuration.

And post the result here. If this does not works then your hardware has the fault. Also put a 10K pot between 5v and GND and tie the center pin of pot to pin 3 of the LCD (marked VEE on PCB ). Run the app and try to adjust the pot untill the display is clear.

If you post the result properly I will help you go further.

01-10-2011, 07:42 PM
To which port of the atmega32 should i connect this.Please give me the pin configuration so that i can make the connection.

I tried this with PORT D of the avr but the screen is just blank.I used this program to connect the lcd in 4 bit , the pin configuration with which i connected is
PD3=not connected
PD 4-7 = DB4-7
And also i didnt use the 10k pot , i used a 1k resistor between vee [pin 3] and gnd.

01-11-2011, 09:09 AM
Use the POT as told and report. The connection is as given by you in the first post. Does it shows Black dots on first line and a blank second line? If yes the connection has some problem. If it is clear screen. Then pot has the problem.

If possible shot a picture of the lcd and your setup.

01-11-2011, 07:57 PM
I used the 10k pot as told by you and on setting the contrast i got only one line of the lcd display visible.I have attached the pics of the lcd which i took when i set the 10k pot.Sorry for the image clarity as am not a good photographer and also the cam wasnt a good one.

2011-01-11 19.43.09.jpg is the image i took when i put the pot to max position [ Its the last thumbnail with only one dark line]
2011-01-11 19.43.52.jpg is the image i took when i set the contrast to the lcd using the 10k pot [ it is the first thumbnail with a normal contrast]
2011-01-11 19.48.54.jpg is the image i took when the microcontroller was executing the program that you gave me, nothing was displayed on the screen.[ the middle one]

Are there any connections wrong? or else is the lcd itself wrong.

01-11-2011, 08:19 PM

You are near the solution. The hardware is OK. My program is able to communicate with the LCD. This is clear as if the communication has error and LCD is not receiving command it will show only one line of black dots. This is because the LCD is started by default in 1 line mode. As the program runs it sets the LCD in 2 line mode.

Now I think you have not attached the POT correctly.

Also you may use camera with AF(Auto focus) to get good photos!

01-12-2011, 06:42 AM
After you said in the before post that if only one line is displayed then there is some problem with the connections , i was checking the connections after i posted and at an instant the lcd started displaying charaters.Even before i could sense it , the connection was again disturbed by myself and the display again went off.

For the POT , i am connecting one end of it to vcc [5v] and the other end to gnd and the middle connection to the vee i.e. pin 3 of the lcd module.After this connection I am adjusting the pot for proper contrast.Is there anything wrong in this connection.

01-12-2011, 10:04 AM
instant the lcd started displaying charaters

So your problem is solved. Good bye.

01-12-2011, 06:54 PM
thank you very much for your help