otuzsubat
Member level 4
- Joined
- Jun 7, 2004
- Messages
- 72
- Helped
- 7
- Reputation
- 14
- Reaction score
- 5
- Trophy points
- 1,288
- Location
- istanbul, Turkey
- Activity points
- 668
I use a 4x3 keypad in my project. I use C0, C1, C2 and C5 pins as output, and E0,E1,E2 as inputs. Can this function be more simply?
char one_char(void){
unsigned int row;
for (row=0; row<4;row++){//"row"
if (row==0){
output_low(pin_c0);
output_high(pin_c1);
output_high(pin_c2);
output_high(pin_c5);
}
if (row==1){
output_high(pin_c0);
output_low(pin_c1);
output_high(pin_c2);
output_high(pin_c5);
}
if (row==2){
output_high(pin_c0);
output_high(pin_c1);
output_low(pin_c2);
output_high(pin_c5);
}
if (row==3){
output_high(pin_c0);
output_high(pin_c1);
output_high(pin_c2);
output_low(pin_c5);
}
if(!input(PIN_E0)&&input(PIN_E1)&&input(PIN_E2))
return((row*3)+1+0x30;
else if (input(PIN_E0)&&!input(PIN_E1)&&input(PIN_E2))
return((row*3)+2+0x30);
else if (input(PIN_E0)&&input(PIN_E1)&&!input(PIN_E2))
return((row*3)+3+0x30);
else
return(0);
}
char one_char(void){
unsigned int row;
for (row=0; row<4;row++){//"row"
if (row==0){
output_low(pin_c0);
output_high(pin_c1);
output_high(pin_c2);
output_high(pin_c5);
}
if (row==1){
output_high(pin_c0);
output_low(pin_c1);
output_high(pin_c2);
output_high(pin_c5);
}
if (row==2){
output_high(pin_c0);
output_high(pin_c1);
output_low(pin_c2);
output_high(pin_c5);
}
if (row==3){
output_high(pin_c0);
output_high(pin_c1);
output_high(pin_c2);
output_low(pin_c5);
}
if(!input(PIN_E0)&&input(PIN_E1)&&input(PIN_E2))
return((row*3)+1+0x30;
else if (input(PIN_E0)&&!input(PIN_E1)&&input(PIN_E2))
return((row*3)+2+0x30);
else if (input(PIN_E0)&&input(PIN_E1)&&!input(PIN_E2))
return((row*3)+3+0x30);
else
return(0);
}