SlideShare a Scribd company logo
1 of 3
#include<avr/io.h> //include avr header file
#include<util/delay.h> //include delay header file
#define LCD_PRT PORTC // define portb as a lcd port
#define LCD_DDR DDRC //define ddr for lcd
/*#define LCD_PIN PINB
#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2*/
void lcdcommand( unsigned char cmnd )
{
//to send higher bit of cmnd to LCD_PRT
LCD_PRT=(LCD_PRT & 0X0F) | (cmnd & 0XF0); //masking of portb in nibbles
LCD_PRT = (LCD_PRT&0b11111100); //FOR MAKING RS=0, RW=0
LCD_PRT = (LCD_PRT|0b00000100); //FOR MAKING EN=1
_delay_us(100);
LCD_PRT = (LCD_PRT&0b11111011); //FOR MAKING EN=0
_delay_us(500);
//to send lower bit of cmd to LCD_PRT
LCD_PRT=(LCD_PRT & 0X0F) | (cmnd << 4);
LCD_PRT = (LCD_PRT|0b00000100);/*FOR MAKING EN=1*/
_delay_us(100);
LCD_PRT = (LCD_PRT&0b11111011);/*FOR MAKING EN=0*/
_delay_us(500);
}
void lcddata( unsigned char data ) //Function to send data to LCD
{
LCD_PRT = (LCD_PRT & 0x0F) | (data & 0xF0); //to send higher bit of cmnd to
LCD_PRT
LCD_PRT = (LCD_PRT|0b00000001); /*FOR MAKING RS=1*/
LCD_PRT = (LCD_PRT&0b11111101); /*FOR MAKING RW=0*/
LCD_PRT = (LCD_PRT|0b00000100); /*FOR MAKING EN=1*/
_delay_us(100);
LCD_PRT = (LCD_PRT&0b11111011); /*FOR MAKING EN=0*/
_delay_us(500);
LCD_PRT = (LCD_PRT & 0x0F)|(data<<4); //to send lower bit of data to
LCD_PRT
LCD_PRT = (LCD_PRT|0b00000100); /*FOR MAKING EN=1*/
_delay_us(100);
LCD_PRT = (LCD_PRT&0b11111011); /*FOR MAKING EN=0*/
_delay_us(500);
}
void lcd_init() //Function to initialize the LCD
{
LCD_DDR=0xFF; //LCD port as output port
LCD_PRT = (LCD_PRT&0b11111011); //FOR MAKING EN=0
lcdcommand(0x33);
_delay_us(1000);
lcdcommand(0x32);
_delay_us(1000);
lcdcommand(0x28); //these three command are for 4 bit LCD
mode
_delay_us(1000);
lcdcommand(0x0E); //display on cursor on
_delay_us(1000);
lcdcommand(0x01); //to clear display
_delay_us(1000);
lcdcommand(0x06); //shift the cursor to right
_delay_us(1000);
}
void lcd_gotoxy(unsigned char x,unsigned char y) // Function to set a
starting position on 16x2 LCD
{
unsigned char firstcharadr[]={ 0x80, 0xC0};
lcdcommand(firstcharadr [y-1]+x-1);
_delay_us(2000);
}
void lcd_puts(char *str) // Function to send a string to LCD
{
unsigned char i=0;
while(str[i]!=0)
{
lcddata(str[i]);
_delay_ms(1000);
i++;
}
}
void lcd_clr(void) // Function to clear the lcd
{
lcdcommand(0x01);
_delay_ms(2000);
}
int main(void)
{
lcd_init();
while(1)
{
lcd_gotoxy(1,1);
lcd_puts("E&C");
_delay_ms(2000);
_delay_ms(100);
lcd_gotoxy(1,2);
lcd_puts("SRMSCET");
_delay_ms(9000);
lcd_clr();
}
}

More Related Content

What's hot

PWM based motor speed control using LPC 1768
PWM based motor speed control using LPC 1768PWM based motor speed control using LPC 1768
PWM based motor speed control using LPC 1768Omkar Rane
 
20170127 tokyoserversideswiftmeetup資料
20170127 tokyoserversideswiftmeetup資料20170127 tokyoserversideswiftmeetup資料
20170127 tokyoserversideswiftmeetup資料jugemjugemjugem
 
Stevens HFC2009
Stevens HFC2009Stevens HFC2009
Stevens HFC2009jzw200
 
C++ hello world
C++ hello worldC++ hello world
C++ hello worldAL- AMIN
 

What's hot (6)

PWM based motor speed control using LPC 1768
PWM based motor speed control using LPC 1768PWM based motor speed control using LPC 1768
PWM based motor speed control using LPC 1768
 
20170127 tokyoserversideswiftmeetup資料
20170127 tokyoserversideswiftmeetup資料20170127 tokyoserversideswiftmeetup資料
20170127 tokyoserversideswiftmeetup資料
 
Gray code
Gray code Gray code
Gray code
 
Stevens HFC2009
Stevens HFC2009Stevens HFC2009
Stevens HFC2009
 
Codigo
CodigoCodigo
Codigo
 
C++ hello world
C++ hello worldC++ hello world
C++ hello world
 

Similar to Atmega lcd programing_with_header_file

Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxSANTIAGO PABLO ALBERTO
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controllerSyed Ghufran Hassan
 
code for DTMF and bluetooth based digital switch board
code for DTMF and bluetooth based digital switch boardcode for DTMF and bluetooth based digital switch board
code for DTMF and bluetooth based digital switch boardNilgiri publicity
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd YearAndrew Kozik
 
Gsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontrollerGsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontrollerYonas Andualem
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Svet Ivantchev
 
Quanta ze7 r1b_schematics
Quanta ze7 r1b_schematicsQuanta ze7 r1b_schematics
Quanta ze7 r1b_schematicsDATACORP
 
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docxajoy21
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics Felipe Prado
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver艾鍗科技
 
Microcontroller Programming Assignment
Microcontroller Programming AssignmentMicrocontroller Programming Assignment
Microcontroller Programming Assignmentbabak danyal
 
PWM wave generator using microcontroller
 PWM wave generator using microcontroller  PWM wave generator using microcontroller
PWM wave generator using microcontroller Swapnil2515
 

Similar to Atmega lcd programing_with_header_file (20)

PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
code for DTMF and bluetooth based digital switch board
code for DTMF and bluetooth based digital switch boardcode for DTMF and bluetooth based digital switch board
code for DTMF and bluetooth based digital switch board
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
 
LCD Keypad Shield
LCD Keypad ShieldLCD Keypad Shield
LCD Keypad Shield
 
Gsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontrollerGsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontroller
 
Direct analog
Direct analogDirect analog
Direct analog
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
_LCD display-mbed.pdf
_LCD display-mbed.pdf_LCD display-mbed.pdf
_LCD display-mbed.pdf
 
Quanta ze7 r1b_schematics
Quanta ze7 r1b_schematicsQuanta ze7 r1b_schematics
Quanta ze7 r1b_schematics
 
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
 
Microcontroller Programming Assignment
Microcontroller Programming AssignmentMicrocontroller Programming Assignment
Microcontroller Programming Assignment
 
Lampiran 1.programdocx
Lampiran 1.programdocxLampiran 1.programdocx
Lampiran 1.programdocx
 
PWM wave generator using microcontroller
 PWM wave generator using microcontroller  PWM wave generator using microcontroller
PWM wave generator using microcontroller
 
Pwm wave
Pwm wave Pwm wave
Pwm wave
 

More from ABHISHEK MAURYA

Data_storage_Flash_Memory.pptx
Data_storage_Flash_Memory.pptxData_storage_Flash_Memory.pptx
Data_storage_Flash_Memory.pptxABHISHEK MAURYA
 
Installation process of Arduino
Installation process of ArduinoInstallation process of Arduino
Installation process of ArduinoABHISHEK MAURYA
 
Basic electronics component
Basic electronics componentBasic electronics component
Basic electronics componentABHISHEK MAURYA
 
An industrial training ppt at Hal lucknow
An industrial training ppt at Hal lucknowAn industrial training ppt at Hal lucknow
An industrial training ppt at Hal lucknowABHISHEK MAURYA
 

More from ABHISHEK MAURYA (6)

Data_storage_Flash_Memory.pptx
Data_storage_Flash_Memory.pptxData_storage_Flash_Memory.pptx
Data_storage_Flash_Memory.pptx
 
ATMEGA 328
ATMEGA 328ATMEGA 328
ATMEGA 328
 
IMAGE PROCESSING
IMAGE PROCESSINGIMAGE PROCESSING
IMAGE PROCESSING
 
Installation process of Arduino
Installation process of ArduinoInstallation process of Arduino
Installation process of Arduino
 
Basic electronics component
Basic electronics componentBasic electronics component
Basic electronics component
 
An industrial training ppt at Hal lucknow
An industrial training ppt at Hal lucknowAn industrial training ppt at Hal lucknow
An industrial training ppt at Hal lucknow
 

Recently uploaded

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 

Atmega lcd programing_with_header_file

  • 1. #include<avr/io.h> //include avr header file #include<util/delay.h> //include delay header file #define LCD_PRT PORTC // define portb as a lcd port #define LCD_DDR DDRC //define ddr for lcd /*#define LCD_PIN PINB #define LCD_RS 0 #define LCD_RW 1 #define LCD_EN 2*/ void lcdcommand( unsigned char cmnd ) { //to send higher bit of cmnd to LCD_PRT LCD_PRT=(LCD_PRT & 0X0F) | (cmnd & 0XF0); //masking of portb in nibbles LCD_PRT = (LCD_PRT&0b11111100); //FOR MAKING RS=0, RW=0 LCD_PRT = (LCD_PRT|0b00000100); //FOR MAKING EN=1 _delay_us(100); LCD_PRT = (LCD_PRT&0b11111011); //FOR MAKING EN=0 _delay_us(500); //to send lower bit of cmd to LCD_PRT LCD_PRT=(LCD_PRT & 0X0F) | (cmnd << 4); LCD_PRT = (LCD_PRT|0b00000100);/*FOR MAKING EN=1*/ _delay_us(100); LCD_PRT = (LCD_PRT&0b11111011);/*FOR MAKING EN=0*/ _delay_us(500); } void lcddata( unsigned char data ) //Function to send data to LCD { LCD_PRT = (LCD_PRT & 0x0F) | (data & 0xF0); //to send higher bit of cmnd to LCD_PRT LCD_PRT = (LCD_PRT|0b00000001); /*FOR MAKING RS=1*/ LCD_PRT = (LCD_PRT&0b11111101); /*FOR MAKING RW=0*/ LCD_PRT = (LCD_PRT|0b00000100); /*FOR MAKING EN=1*/ _delay_us(100); LCD_PRT = (LCD_PRT&0b11111011); /*FOR MAKING EN=0*/ _delay_us(500); LCD_PRT = (LCD_PRT & 0x0F)|(data<<4); //to send lower bit of data to LCD_PRT LCD_PRT = (LCD_PRT|0b00000100); /*FOR MAKING EN=1*/ _delay_us(100); LCD_PRT = (LCD_PRT&0b11111011); /*FOR MAKING EN=0*/ _delay_us(500); } void lcd_init() //Function to initialize the LCD { LCD_DDR=0xFF; //LCD port as output port
  • 2. LCD_PRT = (LCD_PRT&0b11111011); //FOR MAKING EN=0 lcdcommand(0x33); _delay_us(1000); lcdcommand(0x32); _delay_us(1000); lcdcommand(0x28); //these three command are for 4 bit LCD mode _delay_us(1000); lcdcommand(0x0E); //display on cursor on _delay_us(1000); lcdcommand(0x01); //to clear display _delay_us(1000); lcdcommand(0x06); //shift the cursor to right _delay_us(1000); } void lcd_gotoxy(unsigned char x,unsigned char y) // Function to set a starting position on 16x2 LCD { unsigned char firstcharadr[]={ 0x80, 0xC0}; lcdcommand(firstcharadr [y-1]+x-1); _delay_us(2000); } void lcd_puts(char *str) // Function to send a string to LCD { unsigned char i=0; while(str[i]!=0) { lcddata(str[i]); _delay_ms(1000); i++; } } void lcd_clr(void) // Function to clear the lcd { lcdcommand(0x01); _delay_ms(2000); } int main(void) { lcd_init(); while(1) { lcd_gotoxy(1,1); lcd_puts("E&C");