dsk2858
Member level 2
- Joined
- Aug 17, 2011
- Messages
- 47
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Chennai,India
- Activity points
- 1,683
Printing ASCII values with combination of 2-KEYS
I actually tried to implement a 2key combination to print a ASCII value according to the below logic.
I am using AVR STUDIO-4 IDE.
k1 k2 o/p
0 0 no operation
0 1 A
1 0 B
1 1 C
i used switch & case statements to implement it the code is as follows.
The problem i am facing is as follows.
when i am pressing K2 then it is switching to case(1)and printing A
when i am pressing K1 then it is switching to case (2)and printing B
but the main problem lies here when both the keys K1 and K2 are pressed at a time then only it is switching to case(3) and printing C.
how to over come this problem , as there are only two keys i can press them at a time but if there are combination of 3 or 4 keys how to procede.
which c statements to be used .
I actually tried to implement a 2key combination to print a ASCII value according to the below logic.
I am using AVR STUDIO-4 IDE.
k1 k2 o/p
0 0 no operation
0 1 A
1 0 B
1 1 C
i used switch & case statements to implement it the code is as follows.
Code:
#include<avr/io.h>
#include<util/delay.h>
void delay_ms(unsigned int d)
{
_delay_ms(d);
}
void usart_init (void)//initializing UART for serial communication
{
UCSRB = (1<<TXEN);
UCSRC = (1<< UCSZ1)|(1<<UCSZ0)|(1<<URSEL);
UBRRL = 0x33;
}
void usart_send (unsigned char ch)//sending data to PC
{
while (!(UCSRA & (1<<UDRE)));
UDR = ch;
}
int main (voide)
{
unsigned char z;
unsigned int a;
DDRB=0x00;//input port
while(1)
{
z=PINB;
z&=0b00000011
switch(z)
{
case(0):
{
break;
}
case(1):
{
a='A';
usart_init();
usart_send(a);
break;
}
case(2):
{
a='B';
usart_init();
usart_send(a);
break;
}
case(3):
{
a='C;
usart_init();
usart_send(a);
break;
}
}
}
}
}
return 0;
}
The problem i am facing is as follows.
when i am pressing K2 then it is switching to case(1)and printing A
when i am pressing K1 then it is switching to case (2)and printing B
but the main problem lies here when both the keys K1 and K2 are pressed at a time then only it is switching to case(3) and printing C.
how to over come this problem , as there are only two keys i can press them at a time but if there are combination of 3 or 4 keys how to procede.
which c statements to be used .