Microcontroller › AVR › Not getting exaclty what i need on LCD
- This topic has 2 replies, 2 voices, and was last updated 12 years, 6 months ago by Sajan.
-
AuthorPosts
-
February 9, 2012 at 10:31 am #1667SajanParticipant
i am working on LCD interfacing using atmega16.. and my LCD is JHD162A.. i started with single letter ‘S’ and my code was working.. but in such cases it is not displaying the exact word what i need to be on lcd.. what i mean is if i will try with ” HELLO SAJAN ” , it is showing something like this.. ” IEMMO!SAKAO ” !!??! can anybody help me what is the mistake and why it is happening like this..
my code is shown below..
#include <avr/io.h>
#define F_CPU 16000000L
#include <util/delay.h>
#define LCD_DATA PORTB // LCD data port
#define ctrl PORTD
#define en PD6 // enable signal
#define rw PD5 // read/write signal
#define rs PD4 // register select signalvoid LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char);int main()
{
DDRB = 0xff; // making LCD_DATA port as output port
DDRD = 0xf0; // making signal as out put
init_LCD(); // initialization of LCD
_delay_ms(50); // delay of 50 milli seconds
LCD_write(‘H’); // call a function to write H on LCD
LCD_write(‘E’); // call a function to write E on LCD
LCD_write(‘L’); // call a function to write L on LCD
LCD_write(‘L’); // call a function to write L on LCD
LCD_write(‘O’); // call a function to write 0 on LCD
LCD_write(‘ ‘);
LCD_write(‘S’); // call a function to write S on LCD
LCD_write(‘A’); // call a function to write A on LCD
LCD_write(‘J’); // call a function to write J on LCD
LCD_write(‘A’); // call a function to write A on LCD
LCD_write(‘N’); // call a function to write N on LCD
while (1);
return 0;
}void LCD_write(unsigned char data)
{
LCD_DATA = data;
ctrl = (1 << rs)|(0 << rw)|(1 << en); // RW as LOW and RS, EN as HIGH
_delay_ms(5);
ctrl = (1 << rs)|(0 << rw)|(0 << en); // EN and RW as LOW and RS HIGH
_delay_ms(5); // delay to get things executed
return ;
}void LCD_cmd(unsigned char cmd)
{
LCD_DATA=cmd;
ctrl =(0 << rs)|(0 << rw)|(1 << en); // RS and RW as LOW and EN as HIGH
_delay_ms(5);
ctrl =(0 << rs)|(0 << rw)|(0 << en); // RS, RW , LOW and EN as LOW
_delay_ms(5);
return;
}void init_LCD(void)
{
LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
_delay_ms(5);
LCD_cmd(0x01); // clear LCD
_delay_ms(5);
LCD_cmd(0x0E); // cursor ON
_delay_ms(5);
LCD_cmd(0x80); // —8 go to first line and –0 is for 0th position
_delay_ms(5);return;
}March 2, 2012 at 1:43 pm #7210shreenuParticipantset the internal pullup resistor:DDRB = 0xff; // making LCD_DATA port as output port
DDRD = 0xf0; // making signal as out put and use PORTB =0xFF, and PORTC =0xFF;March 3, 2012 at 12:39 pm #7215SajanParticipantthank you for the reply..
but still result is same.. there’s nothing change in it.. -
AuthorPosts
- You must be logged in to reply to this topic.