Microcontroller › AVR › 4 bit LCD interfacing with ATmega32 › i wana display msg on lcd
August 13, 2012 at 11:44 am
#8449
Participant
i wana display msg on lcd interfaced with atmega 32. i want to use PB.0-rs, PB.1-rw, PB.2- en , and want to use data pins of same port i.e PB.4 TO PB.7. Here is my code…..cn ny 1 help me to solv out the prblm. wn i burn this code nthing is display on lcd.
//Program to Display string on LCD using AVR Microcontroller (ATmega16)
/*
LCD DATA port—-PORT B
signal port
PORT D
PORT D
rs
PD0
PD0
rw
PD1
PD1
en
PD2
PD2
*/
#include<mega32.h>
#include<delay.h>
#define LCD_DATA PORTB //LCD data port
#define ctrl PORTB
#define en PORTB2 // enable signal
#define rw PORTB1 // read/write signal
#define rs PORTB0 // register select signal
void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);
void LCD_write_string(unsigned char *str) ;
void main()
{
DDRB=0xff;
PORTB=0xf0;
init_LCD(); // initialization of LCD
delay_ms(50); // delay of 50 mili seconds
LCD_write_string(“sushilprajapati”); // function to print string on LCD
}
void init_LCD(void)
{
LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
delay_ms(1);
LCD_cmd(0x01); // clear LCD
delay_ms(1);
LCD_cmd(0x0E); // cursor ON
delay_ms(1);
LCD_cmd(0x80); // —8 go to first line and –0 is for 0th position
delay_ms(1);
return;
}
void LCD_cmd(unsigned char cmd)
{
LCD_DATA=cmd;
ctrl =(0<<rs)|(0<<rw)|(1<<en);
delay_ms(1);
ctrl =(0<<rs)|(0<<rw)|(0<<en);
delay_ms(50);
return;
}
void LCD_write(unsigned char data)
{
LCD_DATA= data;
ctrl = (1<<rs)|(0<<rw)|(1<<en);
delay_ms(1);
ctrl = (1<<rs)|(0<<rw)|(0<<en);
delay_ms(50);
return ;
}
void LCD_write_string(unsigned char *str) //store address value of the string in pointer *str
{
int i=0;
while(str!=’