Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Embedded Systems

AVR | Print HELLO WORLD on the 16x2 LCD



In this article, we would learn a simple program, about how to print HELLO WORLD on the LCD. As this is our first LCD program I would try to explain you every step in a more detailed way.
Submitted by Suryaveer Singh, on July 27, 2018

We would learn the connection to the LCD first as the connections is a bit complex and here we are using an 8-bit LCD.

Simulation

Simulation, AVR | Print HELLO WORLD on the 16x2 LCD

Explanation

  • Search these devices from the device selection menu:
    1. ATmega16
    2. LM016L (It’s a 16*2 Alphanumeric LCD)
    3. One Power Terminal
    4. One Ground terminal
  • Connect the power terminal from the VDD and VEE of the LCD.
  • Connect the Enable pin (E) and VSS pin to the ground terminal.
  • Double click on the Power terminal and write +5V in its properties.
  • Connect the R/S and E pin to the PC0 and PC1 of the ATmega16.
  • The next step would be to debug the HEX file in the ATmega16.

Now after all the connections are made we will move forward to the coding section. As the coding for the LCD is bit longer so I won’t be attaching the screenshots from the Atmel Studio.



C code to print HELLO WORLD on the LCD

#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>
#define RS0
#define EN1

void lcd_comm (char);
void lcd_data(char);
void lcd_init (void);


int main(void)
{
	lcd_init();
	lcd_data('H');
	lcd_data('E');
	lcd_data('L');
	lcd_data('L');
	lcd_data('O');

	lcd_comm(20);

	lcd_data('W');
	lcd_data('O');
	lcd_data('R');
	lcd_data('L');
	lcd_data('D');

	while(1)
	{
		
	}
}

void lcd_comm(char x){
	PORTD = x;
	PORTC &= ~(1<<RS);
	PORTC |= 1<<EN;
	_delay_ms(5);
	PORTC &= ~(1<<EN);
}

void lcd_data(char x){
	PORTD = x;
	PORTC |= 1<<RS;
	PORTC |= 1<<EN;
	_delay_ms(5);
	PORTC &= ~(1<<EN);
}

void lcd_init(void){
	DDRD = 0xFF;
	DDRC = 0x03;
	lcd_comm(0x38);
	lcd_comm(0x06);
	lcd_comm(0x0E);
	lcd_comm(0x01);
	lcd_comm(0x80);
}

Explanation

  • Firstly we have included all the header file that is required basically
  • At the initial condition, we have defined EN=0 and RS=1.
  • Next we have defined certain functions lcd_comm(char), lcd_data(char) and lcd_init(void).
  • Inside the int main(void) we have written the alphabets that need to be print in the screen.
  • Also here lcd_comm(20); is the command given to the LCD to create space between the two words.
  • Inside the void lcd_comm(char x) we have taken the variable as char x, which we have assigned to PORTC.
  • In the next step we have masked the initial value of RS which was initially 1, and here we have made it 0.
  • Next, we have made our Enable Pin high and then low by giving the time delay of 5ms in between.
  • Again for the next function, we would be giving the data to LCD through this.
  • We have taken a variable x, and assigned to PORTD, again made RS pin 0 and also have done similarly the Enable pin high and then low by providing the time delay of 5ms.
  • In this function lcd_init(void) we have written all the commands that are required for the LCD at the beginning.
  • For more detail of every command, you can check the last article that I have written about the LCD.
  • Also, the DDRD=0xFF indicates all the data pins connected to the PORTD, and DDRC=0x03 is for the connection of the ENABLE Pin and R/S pin we connected to PORTC.

Build the program and after this debug the Hex file in the simulation software design that we have created earlier and click on the RUN button and your HELLO WORLD will appear in the Screen.






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.