Problem In Switch And Password Setting

Thread Starter

sryzdn

Joined Jun 1, 2014
27
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:

case set:
lcd_gotoxy(0,0);
lcd_putsf("Enter New Pass:");

for (i=0 ; i<4; i++){
newcode=key;

sprintf(d, "%d", newcode);
lcd_gotoxy(i,1);
lcd_puts(d);}

break;


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

Code:
//The first part generating keys:

interrupt [EXT_INT0] void ext_int0_isr(void)
{

    PORTA=0xf0;

    ps=0b11111110;

    for(m=0;m<4;m++)
    {
        PORTA=ps;
        delay_ms(10);
       
        if((PINA & 0xf0)!=0xf0)
            break;
           
        ps<<=1;
        ps|=1;
    }
   
    key_code=((PINA & 0xf0)|(ps & 0x0f));
   
    switch(key_code)
    {
        case 0b11101110:   
        key=1;
        break;
        case 0b11011110:  
        key=2;
        break;
        case 0b10111110:   
        key=3;
        break;
        case 0b01111110:   
        key=4;
        break;
        case 0b11101101:   
        key=5;
        break;
        case 0b11011101:   
        key=6;
        break;
        case 0b10111101:  
        key=7;
        break;
        case 0b01111101:  
        key=8;
        break;
        case 0b11101011:   
        key=9;
        break;
        case 0b11011011:   
        key=10;
        break;
        case 0b10111011:   
        key=11;
        break;
        case 0b01111011:   
        key=12;
        break;
        case 0b11100111:  
        key=13;
        break;
        case 0b11010111:   
        key=14;
        break;
        case 0b10110111:  
        key=15;
        break;
        case 0b01110111:   
        key=16;
       
    }

  PORTA=0xf0;  
     
}
In the while loop I am using switch between the menus as follows:

Code:
while (1)
      {
     
      switch (state) {
      case menu :
     
      lcd_gotoxy(0,0);
      lcd_putsf("1) New Pass");

      lcd_gotoxy(0,1);
      lcd_putsf("2) Enter Pass");
     
      if (key==1){
      lcd_clear();
      PORTA=0xf0;
      state=set;
      delay_ms(100);}
     
      if (key==2){ 
      lcd_clear();
      PORTA=0xf0;
      state=check;
      delay_ms(100);}
     
      break;
     
     
      case set:
      lcd_gotoxy(0,0);
      lcd_putsf("Enter New Pass:");
     
      for (i=0 ; i<4; i++){
      newcode[i]=key; 
 
      sprintf(d, "%d", newcode[i]);
      lcd_gotoxy(i,1);
      lcd_puts(d);}   
     
      break;
     
      }
 

Attachments

Top