Microcontroller › AVR › LCD JHD 162a not displaying Characters
- This topic has 2 replies, 2 voices, and was last updated 12 years ago by Neelesh.
-
AuthorPosts
-
January 17, 2013 at 7:57 am #2075NeeleshParticipant
Hi Everyone,
I am trying to interface and LCD “JHD 162a” with Atmega8. I tried the program from LCD interfacing tutorial and several others as well, but facing an issue.
Whenever I try to print a integer (be it any thing from 0 – 9 ) every thing goes well, but when it try to get a print of characters or String or characters ( any thing A – Z or a – z ) invalid symbols are displayed.
If we print “A” a space is shown in LCD and with “a” a difficult character is displayed.
I tried to write the below code as well:
IDE: AVR Studio,
Burner: Exterme Burner with USBasp programmer
MCU: ATmega8
LCD: JHD 162aint main (void){
DDRB = 0b11111111;
DDRD = 0b11100000; // RS is connected to PB5, RW to PB6 and E-PB7PORTB = 0b00111000;
_delay_ms(50);
PORTD = 0b10000000;
_delay_ms(50);
PORTD = 0b00000000;_delay_ms(50);
PORTB = 0b00001111;
_delay_ms(50);
PORTD = 0b10000000;
_delay_ms(50);
PORTD = 0b00000000;_delay_ms(50);
PORTB = 0b00000010;
_delay_ms(50);
PORTD = 0b10000000;
_delay_ms(50);
PORTD = 0b00000000;_delay_ms(150);
PORTD = 0b00100000;
_delay_ms(50);
PORTB = 0b00100001; // Trying to print “A” this will print a Space.
_delay_ms(50);
PORTD = 0b10100000;
_delay_ms(50);
PORTD = 0b00100000;_delay_ms(150);
PORTD = 0b00100000;
_delay_ms(50);
PORTB = 0b00100001; // Trying to print “!” this will be printed well.
_delay_ms(50);
PORTD = 0b10100000;
_delay_ms(50);
PORTD = 0b00100000;while(1){
}
}The basic idea behind displaying anything on LCD is sending a sequence of voltage across data and control pins of an LCD, which further displays the respective character. This was later controlled by the micro controller.
The above issue is faced with you code also. For any sequence of characters invalid symbols are displayed.
If we take reference from the datasheet of JHD 162a, we will get the below data from the Font table:
Few Examples:
1. “A” = 01000001 // This will print a Space.
2. “a” = 01100001 // This will display a garbage character
3. “!” = 00100001 // This will be printedIt would be helpful if you can suggest any solution.
Thanks
January 19, 2013 at 4:21 am #8980nidhin.kParticipanttry this code…..
#include<avr/io.h>#include <avr/interrupt.h>#include <inttypes.h>#include <util/delay.h>#define First_Line 0x80#define Second_Line 0xc0#define Curser_On 0x0f#define Curser_Off 0x0c#define Clear_Display 0x01#define Data_Port PORTD#define enable PORTC |= 0x80#define disable PORTC &= ~0x80#define data_mode PORTC |= 0x40#define cmd_mode PORTC &= ~0x40void Lcd4_Init();void Lcd4_Command(unsigned char);void Lcd4_Write(unsigned char,unsigned char);void Lcd4_Display(unsigned char,const unsigned char*,unsigned int);void Delay(unsigned int);unsigned char Lcd_com1,Lcd_com2,Lcd_Temp;void main(){cli();DDRC=0xff;DDRD=0xff;sei();Lcd4_Init();while(1){Lcd4_Display(0x80,”welcome to atmga”,16);Lcd4_Display(0xc0,”welcome to atmga”,16);}}void Lcd4_Init(){Lcd4_Command(0x38);Lcd4_Command(0x02); //return homeLcd4_Command(0x28); //to select function setLcd4_Command(0x06); //entry mode setLcd4_Command(0x0c); //display onLcd4_Command(0x01); //clear display}void Lcd4_Display(unsigned char com,const unsigned char *word,unsigned int n){unsigned char Lcd_i;for(Lcd_i=0;Lcd_i<n;Lcd_i++){Lcd4_Write(com+Lcd_i,word[Lcd_i]);}}void Lcd4_Command(unsigned char com){Lcd_com1 = com & 0xf0;Lcd_com2 = com & 0x0f;Lcd_com2 = Lcd_com2<<4;// disable;//sel command regLcd_Temp = Data_Port & 0x0f;Data_Port=Lcd_Temp | Lcd_com1;cmd_mode; //send com to poenable; //clock_delay_ms(5);disable;_delay_ms(5);Lcd_Temp = Data_Port & 0x0f;Data_Port=Lcd_Temp | Lcd_com2;cmd_mode; //send com to poenable; //clock_delay_ms(5);disable;_delay_ms(5);}void Lcd4_Write(unsigned char com,unsigned char dat){Lcd4_Command(com);_delay_ms(5);Lcd_com1 = dat & 0xf0;Lcd_com2 = dat & 0x0f;Lcd_com2 = Lcd_com2<<4;// disable;//sel data regLcd_Temp = Data_Port & 0x0f;Data_Port=Lcd_Temp | Lcd_com1;data_mode; //send com to poenable; //clock_delay_ms(5);disable;_delay_ms(5); //sel data regLcd_Temp = Data_Port & 0x0f;Data_Port=Lcd_Temp | Lcd_com2;data_mode; //send com to poenable; //clock_delay_ms(5);disable;cmd_mode;_delay_ms(5);}void Delay(unsigned int del){while(del–);}January 19, 2013 at 2:15 pm #8989NeeleshParticipantHi Nidhin.K,
Thanks for your help friend.
I tried your code, but ended with the same results.
Today again I further narrowed the issue, and 5 mins back I got the results. The isssue was with LCD, it was defective, I replaced it and now all the characters are getting printed.
Thanks for your help.
Thanks
Neelesh
-
AuthorPosts
- You must be logged in to reply to this topic.