Answers for "KEYPAD-SMALLCALC"

C
0

KEYPAD-SMALLCALC

char read_key = '\0', read_val = '\0' ;

read_val = 0x0f & keypin ;  // only take lower 4 bits i.e. value of ABCD and set all other bits to zero

switch (read_val){   // switch statement to convert input to associated char
       case 0x00 :                    // there is 16 casae(for all 16 combination)
            read_key = '/' ;
            break;
       case 0x01 :
            read_key = '9' ;
            break;
       case 0x02 :
            read_key = '8' ;
            break;
       case 0x03 :
            read_key = '7' ;
            break;
       case 0x04 :
            read_key = '*' ;
            break;
       case 0x05 :
            read_key = '6' ;
            break;
       case 0x06 :
            read_key = '5' ;
            break;
       case 0x07 :
            read_key = '4' ;
            break;
       case 0x08 :
            read_key = '-' ;
            break;
       case 0x09 :
            read_key = '3' ;
            break;
       case 0x0a :
            read_key = '2' ;
            break;
       case 0x0b :
            read_key = '1' ;
            break;
       case 0x0c :
            read_key = '+' ;
            break;
       case 0x0d :
            read_key = '=' ;
            break;
       case 0x0e :
            read_key = '0' ;
            break;
       case 0x0f :
            read_key = 'R' ;
            break;
                                                                                                                                                                                                 
    }  
    
    lcd_putchar (read_key); // put this digit on LCD
    
}
Posted by: Guest on May-21-2021

Code answers related to "C"

Browse Popular Code Answers by Language