A 4x3 matrix keypad and a 16x2 LCD has been used here. Keypad and LCD are very commonly used input & output devices, respectively. The connections in the circuit are as following: port P2 of microcontroller AT89C51 is used as data input port which is connected to data pins (7-14) of LCD. P3^0, P3^1 and P3^2 pins of microcontroller are connected to control pins RS, RW and EN of LCD. Port P0 is used to take input from keypad. Also refer to Keypad interfacing with AT89C51.
The alphabetic pattern or letter mapping used in this system is depicted in the following figure:
Every key is assigned with a variable to count the number of times it has been pressed. The count is set to zero initially and increases by one when the same key is pressed again.
On first count, the first alphabet of the key from its letter map is displayed on LCD. For example, if Key1 is pressed when its count is 0, then ‘a’ appears on the LCD screen. After this operation, the count increases to 1.
The second letter of the alphabetic pattern is shown on the display module when the same key is pressed again. This time the count increases again to 2 and second alphabet is displayed at same position. Thus, we get ‘b’ on display if Key1 is used twice.
When the same key is pressed third time, its count value changes to 3. This time the third alphabet of the letter pattern gets displayed on screen replacing the previous alphabet. For the considered case, ‘c’ appears on the LCD screen when Key1 is pressed thrice in a row.
The count is reset to zero after it reaches to a value of 3. After this execution, the position on LCD is shifted to right to allow the second letter to be printed there.
Therefore, pressing the same key four times consecutively, the first alphabet from its letter map reappears in succession to the last letter. Here, ‘a’ gets displayed on LCD after ‘c’ when Key1 is used four times.
In other words, if a key is pressed more than thrice in a row, the count resets to zero and it’ll behave as a new alphabetic key. Thus the same modes of operations continue on repeated access of the keypad buttons.
Key0 of this keypad is set for to provide a blank space ‘ ’ while Key* provides the functionality of backward movement while writing a text on LCD. Key# of the keypad is configured for forward movement.
The 16x2 LCD can display only 16 characters in a line. Therefore, after 16th letter appears on screen, the cursor position is moved and 17th letter gets displayed on the first position of 2nd line of LCD. Similarly, 23rd letter appears back on the first line and so on.