write this code in avr studio4/6....
/*this programs prints "S"char on lcd
#include <avr/io.h>
#include <util/delay.h>
#define lcd_port PORTD
#define rs 0
#define rw 1
#define en 2
void lcd_init();
void lcd_cmnd(unsigned char);
void lcd_data(unsigned char);
void dis_cmnd(unsigned char);
void dis_data(unsigned char);
void main()
{
DDRD=0b11111111;//portd as output port
while(1)
{
lcd_init();
dis_cmnd(0x80);//position to display character
dis_data('S');
}
}
void lcd_init()
{
dis_cmnd(0x28);//
dis_cmnd(0x02);//home position
dis_cmnd(0x0e);displays char or int with cursor .'0x0c' for no cursor
dis_cmnd(0x06);
dis_cmnd(0x01);//lcd clear
_delay_ms(1);
}
dis_cmnd(unsigned char abc)//to break 8 bit data in 2 (4bits)parts and send to instruction register
{
char div;
div=((0xf0)&abc);
lcd_cmnd(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_cmnd(div);
}
dis_data(unsigned char abc)//to break 8 bit data in 2 (4bits)parts and send to instruction register
{
char div;
div=((0xf0)&abc);
lcd_data(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_data(div);
}
lcd_cmnd(unsigned char abc)//sends command to lcd port
{
lcd_port=abc;
lcd_port&=~(1<<rs);//rs=0
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0
}
lcd_data(unsigned char abc)//sends data to lcd port
{
lcd_port=abc;
lcd_port|=(1<<rs);//rs=1
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0
}
//string and integer display function will be introduced in next blog...
/*this programs prints "S"char on lcd
#include <avr/io.h>
#include <util/delay.h>
#define lcd_port PORTD
#define rs 0
#define rw 1
#define en 2
void lcd_init();
void lcd_cmnd(unsigned char);
void lcd_data(unsigned char);
void dis_cmnd(unsigned char);
void dis_data(unsigned char);
void main()
{
DDRD=0b11111111;//portd as output port
while(1)
{
lcd_init();
dis_cmnd(0x80);//position to display character
dis_data('S');
}
}
void lcd_init()
{
dis_cmnd(0x28);//
dis_cmnd(0x02);//home position
dis_cmnd(0x0e);displays char or int with cursor .'0x0c' for no cursor
dis_cmnd(0x06);
dis_cmnd(0x01);//lcd clear
_delay_ms(1);
}
dis_cmnd(unsigned char abc)//to break 8 bit data in 2 (4bits)parts and send to instruction register
{
char div;
div=((0xf0)&abc);
lcd_cmnd(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_cmnd(div);
}
dis_data(unsigned char abc)//to break 8 bit data in 2 (4bits)parts and send to instruction register
{
char div;
div=((0xf0)&abc);
lcd_data(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_data(div);
}
lcd_cmnd(unsigned char abc)//sends command to lcd port
{
lcd_port=abc;
lcd_port&=~(1<<rs);//rs=0
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0
}
lcd_data(unsigned char abc)//sends data to lcd port
{
lcd_port=abc;
lcd_port|=(1<<rs);//rs=1
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0
}
//string and integer display function will be introduced in next blog...