Problem In Switch And Password Setting

Discussion in 'Programmer's Corner' started by sryzdn, Aug 30, 2014.

  1. sryzdn

    Thread Starter New Member

    Jun 1, 2014
    23
    0
    Hi,

    I am writing a C code in code vision for a digital lock with 4 digit password. The first part of the code generates numbers upon pressing the buttons on a keypad through an interrupt.

    I have three menus on the lcd, the first one "menu" is to choose 1. to change the password and 2. to enter passwords. Upon pressing "1" we are shifted to the secong menu "set". But still "1" is there. How can I resent keys while switching?

    In the second menu "set", not only I still have "1" as I have pressed in the first place, I cannot type the new password through the following commands:



    I have enclosed some additional information as follows, I hope you would kindly help me solve this problem.

    Code (Text):
    1.  
    2. //The first part generating keys:
    3.  
    4. interrupt [EXT_INT0] void ext_int0_isr(void)
    5. {
    6.  
    7.     PORTA=0xf0;
    8.  
    9.     ps=0b11111110;
    10.  
    11.     for(m=0;m<4;m++)
    12.     {
    13.         PORTA=ps;
    14.         delay_ms(10);
    15.        
    16.         if((PINA & 0xf0)!=0xf0)
    17.             break;
    18.            
    19.         ps<<=1;
    20.         ps|=1;
    21.     }
    22.    
    23.     key_code=((PINA & 0xf0)|(ps & 0x0f));
    24.    
    25.     switch(key_code)
    26.     {
    27.         case 0b11101110:  
    28.         key=1;
    29.         break;
    30.         case 0b11011110:  
    31.         key=2;
    32.         break;
    33.         case 0b10111110:  
    34.         key=3;
    35.         break;
    36.         case 0b01111110:  
    37.         key=4;
    38.         break;
    39.         case 0b11101101:  
    40.         key=5;
    41.         break;
    42.         case 0b11011101:  
    43.         key=6;
    44.         break;
    45.         case 0b10111101:  
    46.         key=7;
    47.         break;
    48.         case 0b01111101:  
    49.         key=8;
    50.         break;
    51.         case 0b11101011:  
    52.         key=9;
    53.         break;
    54.         case 0b11011011:  
    55.         key=10;
    56.         break;
    57.         case 0b10111011:  
    58.         key=11;
    59.         break;
    60.         case 0b01111011:  
    61.         key=12;
    62.         break;
    63.         case 0b11100111:  
    64.         key=13;
    65.         break;
    66.         case 0b11010111:  
    67.         key=14;
    68.         break;
    69.         case 0b10110111:  
    70.         key=15;
    71.         break;
    72.         case 0b01110111:  
    73.         key=16;
    74.        
    75.     }
    76.  
    77.   PORTA=0xf0;  
    78.      
    79. }
    In the while loop I am using switch between the menus as follows:

    Code (Text):
    1. while (1)
    2.       {
    3.      
    4.       switch (state) {
    5.       case menu :
    6.      
    7.       lcd_gotoxy(0,0);
    8.       lcd_putsf("1) New Pass");
    9.  
    10.       lcd_gotoxy(0,1);
    11.       lcd_putsf("2) Enter Pass");
    12.      
    13.       if (key==1){
    14.       lcd_clear();
    15.       PORTA=0xf0;
    16.       state=set;
    17.       delay_ms(100);}
    18.      
    19.       if (key==2){
    20.       lcd_clear();
    21.       PORTA=0xf0;
    22.       state=check;
    23.       delay_ms(100);}
    24.      
    25.       break;
    26.      
    27.      
    28.       case set:
    29.       lcd_gotoxy(0,0);
    30.       lcd_putsf("Enter New Pass:");
    31.      
    32.       for (i=0 ; i<4; i++){
    33.       newcode[i]=key;
    34.  
    35.       sprintf(d, "%d", newcode[i]);
    36.       lcd_gotoxy(i,1);
    37.       lcd_puts(d);}  
    38.      
    39.       break;
    40.      
    41.       }
     
Loading...