SlideShare una empresa de Scribd logo
1 de 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();
}
}

Más contenido relacionado

La actualidad más candente (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 a Atmega lcd programing_with_header_file

Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
Andrew Kozik
 
Gsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontrollerGsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontroller
Yonas Andualem
 
PWM wave generator using microcontroller
 PWM wave generator using microcontroller  PWM wave generator using microcontroller
PWM wave generator using microcontroller
Swapnil2515
 

Similar a 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
 

Más de 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
 

Último

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Último (20)

Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

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");