Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How can i solve my keypad problem?

Status
Not open for further replies.

HerohetoChakma

Junior Member level 3
Junior Member level 3
Joined
Apr 19, 2013
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Chittagong, Bangladesh.
herohetoc.webs.com
Activity points
2,338
I have create a hex file and i also run this file in proteous software. By this program i can set my desire two digit set point by using a keypad. But sometime i can set my set pint by trying more times. But every key is ok. But i can't set my set point when i wish. It need to try more. When i simulate there is an mesage that simulation can't run due to excessive CPU load. Is it the main problem. or another?? Please somebody help me.
 
Last edited:

This is my code. This is the keypad scaning function. But when i run this in protious sometimes i can set desire point but sometimes i can't set it. But every key is ok. When i simulate there is an error message that simulation can't run due to excessive cpu load. so how can i solve this?
// Keypad scanning functions
//=============================================================================
void clearrow1(void) //clear the 1st row and set the others
{
RC7=0;
RC6=1;
RC5=1;
RC4=1;
}
void clearrow2(void) //clear the 2nd row and set the others
{
RC7=1;
RC6=0;
RC5=1;
RC4=1;
}
void clearrow3(void) //clear the 3rd row and set the others
{
RC7=1;
RC6=1;
RC5=0;
RC4=1;
}
void clearrow4(void) //clear the 4th roW and set the others
{
RC7=1;
RC6=1;
RC5=1;
RC4=0;
}
void scancolumn1(void)
{
if(RC0==0) //if key '1' is being pressed
{
while(RC0==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st word
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of nuum_count //variable
send_char('1'); //Display the symbol '1' at LCD
keyin[num_count]='1'; //Stall the '1' value at the keyin array
num_count+=1; //increase the num_count variable's value by 1 //and the result stall back to the variable
}
else if(RC1==0) //if key '2' is being pressed
{
while(RC1==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('2'); //Display the symbol '2' at LCD
keyin[num_count]='2'; //Stall the '2' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
else if(RC2==0) //if key '3' is being pressed
{
while(RC2==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('3'); //Display the symbol '3' at LCD
keyin[num_count]='3'; //Stall the '3' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
}
void scancolumn2(void)
{
if(RC0==0) //if key '4' is being pressed
{
while(RC0==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('4'); //Display the symbol '4' at LCD
keyin[num_count]='4'; //Stall the '4' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
else if(RC1==0) //if key '5' is being pressed
{
while(RC1==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('5'); //Display the symbol '5' at LCD
keyin[num_count]='5'; //Stall the '5' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
else if(RC2==0) //if key '6' is being pressed
{
while(RC2==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('6'); //Display the symbol '6' at LCD
keyin[num_count]='6'; //Stall the '6' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
}
void scancolumn3(void)
{
if(RC0==0) //if key '7' is being pressed
{
while(RC0==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('7'); //Display the symbol '7' at LCD
keyin[num_count]='7'; //Stall the '7' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
else if(RC1==0) //if key '8' is being pressed
{
while(RC1==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('8'); //Display the symbol '8' at LCD
keyin[num_count]='8'; //Stall the '8' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
else if(RC2==0) //if key '9' is being pressed
{
while(RC2==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('9'); //Display the symbol '9' at LCD
keyin[num_count]='9'; //Stall the '9' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
}
void scancolumn4(void)
{
if(RC0==0) //if key '*' is being pressed
{
while(RC0==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('*'); //Display the symbol '*' at LCD
keyin[num_count]='*'; //Stall the '*' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
else if(RC1==0) //if key '0' is being pressed
{
while(RC1==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('0'); //Display the symbol '0' at LCD
keyin[num_count]='0'; //Stall the '0' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
else if(RC2==0) //if key '#' is being pressed
{
while(RC2==0)continue; //waiting the key to be released
if(num_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of password_count //variable
send_char('#'); //Display the symbol '#' at LCD
keyin[num_count]='#'; //Stall the '#' value at the keyin_char array
num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the variable
}
}
 
Last edited:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Keypad scanning functions
 //================================================== ===========================
 void clearrow1(void) { //clear the 1st row and set the others
     RC7=0; 
     RC6=1;
     RC5=1;
     RC4=1;
 }
 void clearrow2(void){ //clear the 2nd row and set the others
    RC7=1;
    RC6=0;
    RC5=1;
    RC4=1;
 }
 void clearrow3(void) //clear the 3rd row and set the others
 {
    RC7=1;
    RC6=1;
    RC5=0;
    RC4=1;
 }
 void clearrow4(void) //clear the 4th roW and set the others
 {
    RC7=1;
    RC6=1;
    RC5=1;
    RC4=0;
 }
 void scancolumn1(void)
 {
       if(RC0==0) //if key '1' is being pressed
       {
              while(RC0==0)continue; //waiting the key to be released
       
              if(num_count==0){
                    lcd_clr(); //Clear the LCD if the key is the 1st word
                    lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of nuum_count 
                    send_char('1'); //Display the symbol '1' at LCD
                    keyin[num_count]='1'; //Stall the '1' value at the keyin array
               num_count+=1; //increase the num_count variable's value by 1 //and the result stall back to the variable
              }
       }
       else if(RC1==0) //if key '2' is being pressed
       {
            while(RC1==0)continue; //waiting the key to be released
            
            if(num_count==0){
                lcd_clr(); //Clear the LCD if the key is the 1st password
                lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of                 
                                                // password_count variable
                send_char('2'); //Display the symbol '2' at LCD
                keyin[num_count]='2'; //Stall the '2' value at the keyin_char array
                num_count+=1; //increase the Password_count variable's value 
                                       //by 1 and the result stall back to the variable
            }
       }
       else if(RC2==0) //if key '3' is being pressed
      {
             while(RC2==0)continue; //waiting the key to be released
            
             if(num_count==0){
                    lcd_clr(); //Clear the LCD if the key is the 1st password
                    lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of //
                                                    //password_count //variable
                    send_char('3'); //Display the symbol '3' at LCD
                    keyin[num_count]='3'; //Stall the '3' value at the keyin_char array
                    num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the //
                                           // variable
            } 
      }
 }
 void scancolumn2(void)
 {
           if(RC0==0) //if key '4' is being pressed
           {
                while(RC0==0)continue; //waiting the key to be released
                if(num_count==0){
                         lcd_clr(); //Clear the LCD if the key is the 1st password
                         lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of 
                                                         //password_count //variable
                         send_char('4'); //Display the symbol '4' at LCD
                         keyin[num_count]='4'; //Stall the '4' value at the keyin_char array
                         num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to //
                                                //the variable
               }
            }
           else if(RC1==0) //if key '5' is being pressed
           {
                 while(RC1==0)continue; //waiting the key to be released
                 if(num_count==0){
                      lcd_clr(); //Clear the LCD if the key is the 1st password
                      lcd_goto(num_count); //The cursor of LCD points to the column 
                                                      //equivalent to the value of password_count //variable
                      send_char('5'); //Display the symbol '5' at LCD
                      keyin[num_count]='5'; //Stall the '5' value at the keyin_char array
                      num_count+=1; //increase the Password_count variable's value //by 1 and the result stall back to the  
                                             //variable
                 }
           }
           else if(RC2==0) //if key '6' is being pressed
          {
                while(RC2==0)continue; //waiting the key to be released
                if(num_count==0){
                     lcd_clr(); //Clear the LCD if the key is the 1st password
                     lcd_goto(num_count); //The cursor of LCD points to the column //equivalent to the value of 
                                                     //password_count //variable
                     send_char('6'); //Display the symbol '6' at LCD
                     keyin[num_count]='6'; //Stall the '6' value at the keyin_char array
                     num_count+=1; //increase the Password_count variable's value 
                                            //by 1 and the result stall back to the variable
                }
            }
}
 void scancolumn3(void)
 {
        if(RC0==0) //if key '7' is being pressed
        {
            while(RC0==0)continue; //waiting the key to be released
            if(num_count==0){
                 lcd_clr(); //Clear the LCD if the key is the 1st password
                 lcd_goto(num_count); //The cursor of LCD points to the column 
                                                 //equivalent to the value of password_count //variable
                 send_char('7'); //Display the symbol '7' at LCD
                 keyin[num_count]='7'; //Stall the '7' value at the keyin_char array
                 num_count+=1; //increase the Password_count variable's value 
                                        //by 1 and the result stall back to the variable
        }
        else if(RC1==0) //if key '8' is being pressed
        {
             while(RC1==0)continue; //waiting the key to be released
             if(num_count==0){
                    lcd_clr(); //Clear the LCD if the key is the 1st password
                    lcd_goto(num_count); //The cursor of LCD points to the column 
                                                    //equivalent to the value of password_count //variable
                    send_char('8'); //Display the symbol '8' at LCD
                    keyin[num_count]='8'; //Stall the '8' value at the keyin_char array
                    num_count+=1; //increase the Password_count variable's value 
                                           //by 1 and the result stall back to the variable
             }
        }
        else if(RC2==0) //if key '9' is being pressed
        {
             while(RC2==0)continue; //waiting the key to be released
             if(num_count==0){
                   lcd_clr(); //Clear the LCD if the key is the 1st password
                   lcd_goto(num_count); //The cursor of LCD points to the column 
                                                   //equivalent to the value of password_count //variable
                   send_char('9'); //Display the symbol '9' at LCD
                   keyin[num_count]='9'; //Stall the '9' value at the keyin_char array
                   num_count+=1; //increase the Password_count variable's value 
                                           //by 1 and the result stall back to the variable
             }
         }
 }
 void scancolumn4(void)
 {
        if(RC0==0) //if key '*' is being pressed
        {
            while(RC0==0)continue; //waiting the key to be released
            if(num_count==0){
                 lcd_clr(); //Clear the LCD if the key is the 1st password
                 lcd_goto(num_count); //The cursor of LCD points to the column 
                                                 //equivalent to the value of password_count //variable
                 send_char('*'); //Display the symbol '*' at LCD
                 keyin[num_count]='*'; //Stall the '*' value at the keyin_char array
                 num_count+=1; //increase the Password_count variable's value 
                                         //by 1 and the result stall back to the variable
            }
        }
        else if(RC1==0) //if key '0' is being pressed
        {
            while(RC1==0)continue; //waiting the key to be released
            if(num_count==0){
                  lcd_clr(); //Clear the LCD if the key is the 1st password
                  lcd_goto(num_count); //The cursor of LCD points to the column 
                                                  //equivalent to the value of password_count //variable
                  send_char('0'); //Display the symbol '0' at LCD
                  keyin[num_count]='0'; //Stall the '0' value at the keyin_char array
                  num_count+=1; //increase the Password_count variable's value 
                                         //by 1 and the result stall back to the variable
           }
        }
        else if(RC2==0) //if key '#' is being pressed
       {
          while(RC2==0)continue; //waiting the key to be released
          if(num_count==0){
                 lcd_clr(); //Clear the LCD if the key is the 1st password
                 lcd_goto(num_count); //The cursor of LCD points to the column 
                                                 //equivalent to the value of password_count //variable
                 send_char('#'); //Display the symbol '#' at LCD
                 keyin[num_count]='#'; //Stall the '#' value at the keyin_char array
                 num_count+=1; //increase the Password_count variable's value 
                                         //by 1 and the result stall back to the variable
           }
       }
 }



- - - Updated - - -

do change as per your requirement and try this sample code. This code for PIC18F452. KEYPAD connected to PORTB pins RB4-RB7.

Code C - [expand]
1
2
3
4
5
6
7
void KeypadInit(void){
    char temp;
    // set initial conditions of keypad variables
    NewKey = 0x0f;
    temp = PORTB; // clear mismatch condition
    
}




Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
void showKeyPressed(void){
    
    char incode; // temporary variable
    INTCONbits.RBIE = 0; // disable PORTB interrupts
    // decode row and column
    PORTB = 0x0f;
    PORTBbits.RB1 = 0; // enable CDEF column
    Nop();
    incode = PORTB & 0xf0;
    
    switch (incode)
    {
        case 0x70: NewKey = '3'; break;
        case 0xB0: NewKey = '6'; break;
        case 0xD0: NewKey = '9'; break;
        case 0xE0: NewKey = '#'; break;
    }
    
    PORTB = 0x0f;
    PORTBbits.RB2 = 0; // enable 369B column
    Nop();
    incode = PORTB & 0xf0; // mask off the upper 4 bits
    switch (incode)
    {
        case 0x70: NewKey = '2'; break;
        case 0xB0: NewKey = '5'; break;
        case 0xD0: NewKey = '8'; break;
        case 0xE0: NewKey = '0'; break;
    }
    PORTB = 0x0f;
    PORTBbits.RB3 = 0; // enable 2580 column
    Nop();
    incode = PORTB & 0xf0; // mask off the upper 4 bits
    switch (incode)
    {
        case 0x70: NewKey = '1'; break;
        case 0xB0: NewKey = '4'; break;
        case 0xD0: NewKey = '7'; break;
        case 0xE0: NewKey = '*'; break;
    }
    
    PORTB = 0;
    // wait until key released
    do
    {
        incode = PORTB;
        incode = incode & 0xf0;
    } while (incode != 0xf0);
    
    WriteCmdXLCD(CLR_LCD); 
    while(BusyXLCD()); 
    WriteCmdXLCD(HOME_LCD); 
    while(BusyXLCD()); 
    putcXLCD(NewKey);
    
    incode = PORTB; // clear mismatch condition
  //  NewKey = 0x0f;
    INTCONbits.RBIF = 0; // clear PORTB flag
    INTCONbits.RBIE = 1; // enable PORTB interrupts
}



Note: RBIF interrupt enabled and if interrupt occurred, call the showKeyPressed(); function from interrupt. You should Read entire PORT and check for specific key pressed Instead of looking single key press. This is the difference between your code and this sample code, I hope.

- - - Updated - - -

avoid duplicate post.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top