PDA

View Full Version : JHD162A and atmega32 interface problems



dheeraj91
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
PD0=RS
PD1=RD
PD2=E/N
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
#asm
.equ __lcd_port=0x12 ;PORTD
#endasm
#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
PORTA=0x00;
DDRA=0x00;

// 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
PORTB=0x00;
DDRB=0xFF;

// 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
PORTC=0x00;
DDRC=0x00;

// 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
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// 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
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// LCD module initialization
lcd_init(16);

while (1)
{
// Place your code here
delay_ms(250);
lcd_gotoxy(0,0);
lcd_clear();
lcd_putsf("Checking");
};
}

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

Need help from you.

dheeraj91
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

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

And please do not double post.

avinash_g
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.

dheeraj91
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
PD0=RS
PD1=RD
PD2=E/N
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.

avinash_g
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.

dheeraj91
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.

avinash_g
01-11-2011, 08:19 PM
Umm...

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!

dheeraj91
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.

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

So your problem is solved. Good bye.

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