Sign in

username:

password:



Not a member?

Search avrclub



Search tips

Subscribe to avrclub



avrclub by Keywords

AT90S2313 | AT90S8515 | ATMega | ATmega128 | ECL | FETS | IAR | Keyboard | LCD | STK50 | TMOS | UART

Discussion Groups

Discussion Groups | AVRclub | [AVR club] interfacing a keypad to at mega 8

Atmel AVR Microcontroller discussion group.

[AVR club] interfacing a keypad to at mega 8 - NISA BALAKRISHNAN - Jun 26 2:53:51 2008


can any one help me out in the following problems with my project?
if i directly connect the row and column lines of my keypad to the port b
of at mega 8 , set DDRB as 11110000 and PORTB as 00001111 initially and
press a key ,then what will be the value in PORTB and PINB?
will this sort of connection be practical?
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] interfacing a keypad to at mega 8 - Dave Hylands - Jun 26 3:43:27 2008

Hi Nisa,

On Wed, Jun 25, 2008 at 11:40 PM, NISA BALAKRISHNAN
wrote:
> can any one help me out in the following problems with my project?
> if i directly connect the row and column lines of my keypad to the port b
> of at mega 8 , set DDRB as 11110000 and PORTB as 00001111 initially and
> press a key ,then what will be the value in PORTB and PINB?

PORTB will continue to contain 00001111

PINB will read 00001111 with no keys pressed, and one of the 1's
should change to a zero when a key is pressed.

You then need to perform a scan where you walk a single zero bit
through the 4 output lines (with the other 3 output lines set to 1) to
figure out which column the key corresponds to.

You also need to be concerned with debounce. So, if once you detect a
change, you should probably wait for 10-20 milliseconds before
performing the actual scan. How badly a switch bounces will depend on
the exact switch, but they pretty much all bounce.

Here is some excellent background material on switch bounce:


--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] interfacing a keypad to at mega 8 - Javier Chavez - Jun 26 18:21:35 2008

Nisa,

I also used the same port tied to a keypad however inputs should have pull
ups o pull downs according to the software.
The keyboards works nice and we have to add extra software for debouncing.
I attached a sample (kbd.h & kbd.c ), in case that anyone make some
comments it would be nice. (2x3 keyboard)

Javier

//------->>> kbd.h

//

// Definiciones de teclado

#define KBD_COL PORTD

#define KBD_COL_DDR DDRD

#define COL1 PD3

#define COL2 PD4

#define COL3 PD5

#define KBD_ROW PORTD

#define KBD_INPUT PIND

#define KBD_ROW_DDR DDRD

#define ROW1 PD6

#define ROW2 PD7

void kbd_init(void);

uint8_t kbd_kbhit( void );

uint8_t kbd_getch(void);

/// ----------------->>> kbd.c
#include

#include

#include "delay.h"

#include "kbd.h"

void kbd_init(void)

{

/* Columns outputs */

sbi(KBD_COL_DDR, COL1);

sbi(KBD_COL_DDR, COL2);

sbi(KBD_COL_DDR, COL3);

/* Idle state will be high, since the inputs have pullups.

You can go the other way, but you have to provide pulldowns externally */

sbi(KBD_COL, COL1);

sbi(KBD_COL, COL2);

sbi(KBD_COL, COL3);

/* Rows are outputs for pullups */

sbi(KBD_ROW_DDR,ROW1);

sbi(KBD_ROW_DDR,ROW2);

/* PullUps */

sbi(KBD_ROW,ROW1);

sbi(KBD_ROW,ROW2);

/* Rows are inputs now */

cbi(KBD_ROW_DDR,ROW1);

cbi(KBD_ROW_DDR,ROW2);

}

//

//

uint8_t kbd_kbhit( void )

{

uint8_t A;

A=3D0;

cbi(KBD_COL,COL1);

asm("nop");

if( bit_is_clear(KBD_INPUT, ROW1) )

A |=3D 0x01;

if( bit_is_clear(KBD_INPUT, ROW2) )

A |=3D 0x02;

sbi(KBD_COL,COL1);

cbi(KBD_COL,COL2);

asm("nop");

if( bit_is_clear(KBD_INPUT, ROW1) )

A |=3D 0x04;

if( bit_is_clear(KBD_INPUT, ROW2) )

A |=3D 0x08;

sbi(KBD_COL,COL2);

cbi(KBD_COL,COL3);

asm("nop");

if( bit_is_clear(KBD_INPUT, ROW1) )

A |=3D 0x10;

if( bit_is_clear(KBD_INPUT, ROW2) )

A |=3D 0x20;

sbi(KBD_COL,COL3);

return A;

}

//

//

// Cambir valores para repetici=A2n de teclas

// Apuntar a 73 ms por tecla, 20 ms de tecla y 50 ms de espera

uint8_t kbd_getch(void)

{

uint8_t A;

uint16_t i;

do{

A=3Dkbd_kbhit();

}while(A =3D=3D 0); // Aqui se presiona la tecla

i=3D5500; // 3400; //1700; //

do{

i=3Di-1;

if(A!=3Dkbd_kbhit()) i=3D0;

}while(i!=3D0);

ms_delay(150); // era 50 Repetici=A2n

return A;

}

On Thu, Jun 26, 2008 at 2:40 AM, NISA BALAKRISHNAN <
s...@gmail.com> wrote:

> can any one help me out in the following problems with my project?
> if i directly connect the row and column lines of my keypad to the port b
> of at mega 8 , set DDRB as 11110000 and PORTB as 00001111 initially and
> press a key ,then what will be the value in PORTB and PINB?
> will this sort of connection be practical?
>
> [Non-text portions of this message have been removed]
>
>=20
>
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )