Scrolling text and Button counter

Now that we have already learned how to print in 16×2 LCD, we are ready to proceed further. In this article, I am going to scroll text in LCD and also learn How to print an integer along with the character array in 16×2 LCD.We are going to do that by making a  project on Button counter with Atmega16. Please follow this post how to print in 16×2 LCD for reference if you are a beginner.

The Project-Button counter using Atmega16

As soon as I am going to run the project, it’s going to show a welcome message followed by a universal truth-“AVR Geeks is Awesome!”(Scrolling text). Then I am going to count the number of times I presses a particular button(Printing an integer in 16×2 LCD).

The schematic of the circuit of button counter with Atmega16 is given below

Button counter with Atmega 16-Schematic

Notice that I have connected data pins to Port B and control pins to pin A0, A1, A2 of Port A. Also, I have connected a switch with Pin 0 of Port D.

The Program-Button counter using Atmega16

In this program, I am going to horizontal scroll in 16×2 LCD. Also, I have displayed an integer type number(number of times I push the button) with the character array(Button Counter). For this, I have taken a character array of 25 lengths. Now, I have created a function for LCD Commands and LCD data. Also, I have created a function to scroll text LCDscroll(char). All of these functions take parameters in character format. LCDcmd(char) function for processing the commands of 16×2 LCD. LCDdisplay(char) for processing the display data and LCDscroll(char) for horizontal scrolling in 16×2 LCD.

#include <util/delay.h>
#include <avr/io.h>
#include <string.h>// strlength function is defined in this library
char i; // for indexing of display array. 
char z[25] = "" ;// delclaring of an array
void LCDcmd(char k)
    PORTA=0x01;  // 0 for RS, 0 for RW, 1 for EN makes 00000001 equals 1.
    PORTA=0x00;  // 0 for RS, 0 for RW, 0 for EN. High to low pulse required to give to EN.

void LCDdisplay( char a[] )
for( i = 0; i <strlen(a); i++ )
        PORTB = a[i]; // adding character one by one
        PORTA = 0x05; // 1 for RS, 0 for RW and 1 for En(for high to low pulse)
        PORTA = 0x04;

void LCDScroll(char a) //for scrolling
for(i = 0; i < a; i++)
        LCDcmd(0x18); // shifting the entire display left.

int main (void)
    int c=0;    // count the number of times I press the button
    DDRA = 0xFF; // Output Port
    DDRB = 0xFF;
    DDRD = 0x00; // Input Port
    LCDcmd(0x01);// Clear Display Screen
    LCDcmd(0x06);// Entry mode set, Sets the cursor move direction(left to right)
    LCDcmd(0x0C);// Display on, Cursor Off
    LCDcmd(0x38);// Function set:8-bit, 2 line, 5x7 Dots
    sprintf(z,"Welcome");// Welcome Message stores in array
    LCDdisplay(z);// Display the array
    _delay_ms(5000);// Display it for 5 seconds
    LCDcmd(0x01);// Clear the LCD screen
    sprintf(z,"AVR Geeks is Awesome!");
    LCDScroll(5);// I have to scroll 5 times
        LCDcmd(0x80);// force the cursor to start with the 1st row.
        if ((PIND & 0x01 == 0x01))// Monitoring the status of push button.
               sprintf(z,"Total-%d",c);// c is an integer type number. 

Display of integer with the array-the sprintf() function

The sprintf() function used to assign the value to character type array. Instead of assigning one to one using the loop, this function does the trick. Also, we can print an integer, character or even a float type number with the character array. For the integer number- we use %d, for the character- we use %c, and for the float type number- we use %f. As you can see, it is very simple to print an integer with a character array.

How is Scrolling Text Possible?

You may wonder, a 16×2 LCD should contain 16 characters in one line, but from where these new characters emerge?

The answer is- There are 16 characters visible at a time, but the character that can be stored in one line is 40. Consider this like- A house with 40 rooms and 16 of them have windows.

Execution of the Program-Button counter

On the simulation of the program in Proteus, this is the output.

Scroll Text in 16x2 LCD

Scrolling in 16x2 LCD

Button counter

Hardware Implementation

The program of button counter using Atmega16 works well in hardware.Although, you may notice that the functioning of the button is not working properly. There is another method which is a more efficient (the interrupt method).

7 thoughts on “Scrolling text and Button counter”

  1. Pingback: KATHY

  2. Greetings I am so excited I found your site, I really found you by mistake, while I was looking on Aol for something else, Regardless I am here now and would
    just like to say thank you for a marvelous post and a all round entertaining blog (I also love the theme/design), I don’t have
    time to look over it all at the moment but I have bookmarked it, so when I have time I will be back to read more,
    Please do keep up the fantastic work.

  3. It’s amazing to go to see this website and reading the views of all mates on the topic of this post,
    while I am also keen of getting know-how.

  4. My family always say that I am killing my time here at net, but I know I am
    getting know-how everyday by reading thes nice articles.

  5. Hello there! This is my first visit to your blog!

    We are a team of volunteers and starting a new project
    in a community in the same niche. Your blog provided us beneficial
    information to work on. You have done a outstanding job!

  6. This is the right site for everyone who wishes to understand this topic.
    You realize a whole lot its almost hard to argue with you (not that I really will need to…HaHa).
    You certainly put a brand new spin on a topic that’s
    been discussed for years. Great stuff, just wonderful!

Leave a Comment

Your email address will not be published. Required fields are marked *

Share This
Scroll to Top