2x16 LCD and 4x4 keypad example

17,428

Circuit Image

This circuit is designed for experiments using the AT90S2313 microcontroller, a 2x16 LCD display, and a 4x4 keypad. It operates with a clock based on a 4 MHz crystal, although any crystal between 1-4 MHz can be utilized. The keys labeled "A", "B", and "F" correspond to numbers 10-16 on the LCD. Due to the AVR's limitation of 15 I/O pins, the LCD display is operated using a 4-bit data bus. Four 10 kΩ resistors are employed to protect the AVR from potential short circuits on the keypad columns while scanning the keys by toggling the pin status from input to output. The source code is written in a straightforward manner, prioritizing clarity over memory efficiency to facilitate understanding of the circuit's operation. The AVR configures Port B with pins PB0-PB3 as inputs and PB4-PB7 as outputs. Initially, the AVR sets pin PB4 to logic '0' to enable the first column (the first four keys) and reads their status. If any of the first four keys are pressed, the AVR sends the corresponding key number to the LCD display. If no keys are pressed, PB4 is set to logic '1' and PB5 to logic '0' to enable the second column. This process continues for all 16 keys, after which the circuit restarts the scanning from the first key in the first column.

The circuit utilizes the AT90S2313 microcontroller, which is a member of the AVR family and is well-suited for embedded applications due to its low power consumption and versatility. The 2x16 LCD display provides a clear interface for outputting the pressed key values, while the 4x4 keypad allows for user input. The 4 MHz crystal oscillator ensures stable clock signals necessary for the microcontroller's operation.

To interface the LCD in 4-bit mode, the data lines are connected to pins PB4 to PB7 of the AVR, allowing for efficient communication with the display while conserving I/O resources. The keypad is connected in a matrix configuration, which enables the microcontroller to scan multiple keys using fewer pins. The 10 kΩ resistors serve as pull-up resistors, ensuring that the input pins are in a known state when not actively driven low by the keypad.

The scanning algorithm implemented in the source code sequentially enables each column of the keypad, reading the state of the keys. This method allows the microcontroller to detect which key is pressed by checking the status of the corresponding input pins. When a key press is detected, the microcontroller sends the appropriate value to the LCD, providing immediate feedback to the user.

This circuit serves as an excellent platform for learning about microcontroller interfacing, LCD operation, and keypad scanning techniques. It can be further expanded by adding additional features such as debounce logic for the keypad or implementing more complex user interactions through the LCD display.A very simple circuit forexperiments with AT90S2313, 2x16 LCD display and 4x4 keypad. The clock is based on 4 MHz crystal, but you can use any other crystalbetween 1-4 MHz. The keys with the name "A", "B". "F" are typed to the LCD with numbers 10-16. Because the AVR has only 15 I/O pins we work the LCD display with 4-bit data bus. The 4 resistors (10 k) are protecting the AVR from anyshortcut onthe columns of the keypad when AVR is scanning the keys by changing the pinstatus from input to output. I wrotethe source code ina simple form, that it means I haven`t made any economy to the flash memory, for understanding the way howthis circuit works.

The AVR configure the PortB as PB0-PB3 inputs and PB4-PB7 outputs. Onthe beginning, the AVR puts the pin PB4 at logic `0` to enable the column 1 (the first 4 keys) and reads the status of the keys. If we have pressed any of the 4 first keys then the AVR sends the number of the key to the LCD display.

If we have not pressed any of 4 first keys, the AVR puts the PB4 at logic `1` and PB5 at logic `0` to enable the secondcolumn. Reading the statusof the keys and display the result to LCD, etc, until the 16th key is been read. After that, the circuit starts again to read from the 1st key (1st column). 🔗 External reference




Warning: include(partials/cookie-banner.php): Failed to open stream: Permission denied in /var/www/html/nextgr/view-circuit.php on line 713

Warning: include(): Failed opening 'partials/cookie-banner.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/nextgr/view-circuit.php on line 713