k1_zav
Junior Member level 2
atmega16 keypad
Hi there.
I have a problem.
I want to interface an Atmega 16 to a keypad that has 12 keys.
I use external interrupt for recognition of columns.
Assum I want to work with the third column. When I press '3' I got 3.
but when I press '6' or '9' I got many 6 or 9.
Do you know what's the problem.
By the way I use Codevision AVR as C compiler and this is interrupt service routine:
#define row1 PORTB.4
#define row2 PORTB.5
#define row3 PORTB.6
#define row4 PORTB.7
bit row_recognition;
unsigned char temp;
"// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Column 3
#asm("cli")
row1=0;
row2=1;
row3=1;
row4=1;
delay_ms(1);
row_recognition=PIND.2;
if (!row_recognition)
{
temp='3';
lcd_putchar(temp);
temp=0;
}
else
{
row1=1;
row2=0;
row3=1;
row4=1;
delay_ms(1);
row_recognition=PIND.2;
if (!row_recognition)
{
temp='6';
lcd_putchar(temp);
temp=0;
}
else
{
row1=1;
row2=1;
row3=0;
row4=1;
delay_ms(1);
row_recognition=PIND.2;
if(!row_recognition)
{
temp='9';
lcd_putchar(temp);
temp=0;
}
else //if (row_recognition)
{
temp='#';
lcd_putchar(temp);
temp=0;
};
};
};
delay_ms(5);
row1=0;
row2=0;
row3=0;
row4=0;
lcd_putchar('X');
#asm("sei")
}"
So, Does anybody know what's the problem?
Thanks.
Hi there.
I have a problem.
I want to interface an Atmega 16 to a keypad that has 12 keys.
I use external interrupt for recognition of columns.
Assum I want to work with the third column. When I press '3' I got 3.
but when I press '6' or '9' I got many 6 or 9.
Do you know what's the problem.
By the way I use Codevision AVR as C compiler and this is interrupt service routine:
#define row1 PORTB.4
#define row2 PORTB.5
#define row3 PORTB.6
#define row4 PORTB.7
bit row_recognition;
unsigned char temp;
"// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Column 3
#asm("cli")
row1=0;
row2=1;
row3=1;
row4=1;
delay_ms(1);
row_recognition=PIND.2;
if (!row_recognition)
{
temp='3';
lcd_putchar(temp);
temp=0;
}
else
{
row1=1;
row2=0;
row3=1;
row4=1;
delay_ms(1);
row_recognition=PIND.2;
if (!row_recognition)
{
temp='6';
lcd_putchar(temp);
temp=0;
}
else
{
row1=1;
row2=1;
row3=0;
row4=1;
delay_ms(1);
row_recognition=PIND.2;
if(!row_recognition)
{
temp='9';
lcd_putchar(temp);
temp=0;
}
else //if (row_recognition)
{
temp='#';
lcd_putchar(temp);
temp=0;
};
};
};
delay_ms(5);
row1=0;
row2=0;
row3=0;
row4=0;
lcd_putchar('X');
#asm("sei")
}"
So, Does anybody know what's the problem?
Thanks.