728x90

728x90

Saturday, May 22, 2021

ATMega32 LCD and Keypad Interfacing Example

In previous example I showed a simple keypad programming example using C in Atmel Studio 7. It displays key value on a typical single seven segments display. We can add a character LCD as an output device.

In this programming example we use a 4x4 keypad matrix as a digital input, and a character LCD bases on HD44780 as an output device. A 20x4 character LCD is used to show information a key value.

ATMega32 LCD and Keypad Interfacing Example
Program starts up

Port C is 8-bit wide, connects to a 4x4 matrix keypad as shown in the picture above. Port D connects to a character LCD in 8-bit mode. Read/Write pin is ignored, and it's connects to ground as the LCD just accept the data/command from micro-controller.

Atmega32 operates at 16MHz supplies at +5V DC supply voltage.

C main program shows below. It requires LCD and Keypad driver files that I don't show them here.

/*
 * m32LcdKeyPad.c
 *
 * Created: 5/18/2021 10:15:15 PM
 * Author : aki-technical
 */ 

#include <avr/io.h>

#define F_CPU 16000000UL
#include <util/delay.h>

#include "keypad4x4.h"
#include "m32Lcd.h"

void writeTitle(void);

unsigned char getKey=0;

int main(void)
{
unsigned char pressCount=0,newLine=0,lineCount=1;
DDRD=0xFF;
PORTD=0x00;
keyInit();
lcdInit();
setXy(0,0);
writeString("Atmega32 LCD KeyPad");
setXy(0,1);
writeString("Interfacing Example");
setXy(0,2);
writeString("Programing in C ");
setXy(0,3);
writeString("in Atmel Studio 7");
_delay_ms(2500);
writeTitle();
while(1)
{
getKey=scan();
if (getKey!=0)
{
writeChararacter(getKey);
_delay_ms(250);
pressCount+=1;
getKey=0;
}
if (pressCount==20)
{
newLine=1;
lineCount++;
pressCount=0;
}
if (newLine)
newLine=0;
setXy(0,lineCount);
}
if (lineCount==4)
{
lineCount=1;
writeTitle();
}
}
}

void writeTitle(void){
/*Clear LCD*/
writeCommand(LCD_CLEAR);
setXy(0,0);
writeString("Enter Key Value: ");
writeCommand(CURSOR_ON);
setXy(0,1);
}

Click here to download this example in zip file. I additionally add its schematic diagram below.

ATMega32 LCD and Keypad Interfacing Example
Schematic

If you want a standard PCB for ATMega32 micro-controller, you can order my AVR Microcontroller project from PCBWay with a reasonable price. Click here to get a free $5 credit for new account.


See Also,

No comments:

Post a Comment

320x50

Search This Blog

tyro-728x90