Hi, today we will learn how to connecting your keypad with ATMega16 Microcontroller. As we all know, this just a quiet simple project. let me know that u've been prepare this tolls before
- AVR Modul (of course)
- LED and switch (it's up to you)
- RS 232 / cross
- and, KEYPAD 3 x 4
KEYPAD
General Specification
- Contact rating:20mA,24VDC
- Contact resistance:200 ohm max
- Life:1,000,000 cycles per key
- Operating Temperature: -20 to +60
- Storage Temperature: -40 to +65
Hey.. i see that u've been expert about this know, Congratulation dude! :)
Okey, that's all about keypad. Now we will connecting these keypad to our AVR Micro PIN. here is the Connection Diagram.
If ROW 1 has a logic value 0 and other ROW given logic 1, then: PORTC=0xFD (1111 1101)
If pressed button 1, (ROW1 COL 1) then PINC= 0xF9(1111 1001)
If pressed button 2, (ROW 1 COL 2) then PINC= 0xFC(1111 1100)
If pressed button 3, (ROW 1 COL 3) then PINC = 0xED(1110 1101)
If ROW 2 has a logic value 0 and other ROW given logic 1, then: PORTC=0xBF (1011 1111)
If pressed button 4, (ROW 2 COL 1) then PINC= 0xBB(1011 1011)
If pressed button 5, (ROW 2 COL 2) then PINC= 0xBE(1011 1110)
If pressed button 6, (ROW 2 COL 3) then PINC = 0xAF(1010 1111)
If ROW 3 has a logic value 0 and other ROW given logic 1, then: PORTC=0xDF (1101 1111)
If pressed button 7, (ROW 3 COL 1) then PINC= 0xDB(1101 1011)
If pressed button 8, (ROW 3 COL 2) then PINC= 0xDE(1101 1110)
If pressed button 9, (ROW 3 COL 3) then PINC = 0xCF(1100 1111)
If ROW 4 has a logic value 0 and other ROW given logic 1, then: PORTC=0xEF (1111 0111)
If pressed button *, (ROW 4 COL 1) then PINC= 0xF3(1111 0011)
If pressed button 0, (ROW 4 COL 2) then PINC= 0xF6(1111 0110)
If pressed button #, (ROW 4 COL 3) then PINC = 0xE7(1110 0111)
THE CODE
Before we start to crack the code, i'll tell you that i'm using CodeVision AVR to hack my code. I hope you already knew about this software. But it's OK if you dont, i'll explain this tolls on the next post.
Read the binary keypad value with LED
#include <mega16.h>
#include <delay.h>
// Declare your global variables here
int read_keypad()
{
int a,button;
PORTC= 0xff;
button=0x00; //
PORTC.1=0; // Row 1
#asm("nop")
a = PINC;
if (a==0xf9) {button=1; goto fin;}
if (a==0xfc) {button=2; goto fin;}
if (a==0xed) {button=3; goto fin;}
PORTC.6=0; PORTC.1=1; // Row 2
#asm("nop")
a = PINC;
if (a==0xbb) {button=4; goto fin;}
if (a==0xbe) {button=5; goto fin;}
if (a==0xaf) {button=6; goto fin;}
PORTC.5=0; PORTC.6=1; // Row 3
#asm("nop")
a = PINC;
if (a==0xdb) {button=7; goto fin;}
if (a==0xde) {button=8; goto fin;}
if (a==0xcf) {button=9; goto fin;}
PORTC.3=0; PORTC.5=1; // Row 4
#asm("nop")
a = PINC;
if (a==0xf3) {button=10; goto fin;}
if (a==0xf6) {button=11; goto fin;}
if (a==0xe7) button=12;
fin:
return(button);
}
void main(void)
{
// Declare your local variables here
int value;
PORTA=0x00; // out LED
DDRA=0xFF;
// d7=In d6=Out d5=Out d4=In d3=Out d2=In d1=Out d0=In
PORTC=0x00;
DDRC=0x6A;
while (1)
{
value= read_keypad();
PORTA=~value;
delay_ms(100);
}
}
That's the end. hope you enjoy.. i'll give you another code about this keypad, but of course not today, hehe.. see ya next post.. Happy coding :)
Dont be shy my friend.. Give a comment below.. :D



Subscribe to my feed