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.

[SOLVED] my quiz with my kepad !!! plz help me

Status
Not open for further replies.

asrock

Junior Member level 3
Joined
Sep 10, 2010
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,538
hello ...

simply i use 16f877 and keypad 4*3 for just display on lcd the num pressed.
and this is keypad:
https://dlnmh9ip6v2uc.cloudfront.net/images/products/Keypad1-L.jpg

and my compiler i use is :mikroc pro for pic

and my project is successfully working in proteus >>> but in actual connection the lcd not display the correct number what i press!!!!

i connect the keypad to portD like that:
pin1>>>>RD0.....to 10k the GND
pin2>>>>RD1.....to 10k the GND
pin3>>>>RD2.....to 10k the GND
pin4>>>>RD3
pin5>>>>RD4
pin6>>>>RD5
pin7>>>>RD6

so is my hardware connection wrong !!?
=============
and my code here:

Code:
 sbit LCD_RS at RB0_bit;
 sbit LCD_EN at RB1_bit;

 sbit LCD_D4 at RB4_bit;
 sbit LCD_D5 at RB5_bit;
 sbit LCD_D6 at RB6_bit;
 sbit LCD_D7 at RB7_bit;

 sbit LCD_RS_Direction at TRISB0_bit;
 sbit LCD_EN_Direction at TRISB1_bit;
 sbit LCD_D4_Direction at TRISB4_bit;
 sbit LCD_D5_Direction at TRISB5_bit;
 sbit LCD_D6_Direction at TRISB6_bit;
 sbit LCD_D7_Direction at TRISB7_bit;

  char  keypadPort at PORTD;
int kp;
void main() {
 Keypad_Init();
 Lcd_Init();                 // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR);         // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);     // Cursor off



while (1) {
  kp = Keypad_Key_Press();
switch (kp) {

case 1: kp = 49; break; // 1 // Uncomme
case 2: kp = 50; break; // 2
case 3: kp = 51; break; // 3
case 4: kp = 65; break; // A
case 5: kp = 52; break; // 4
case 6: kp = 53; break; // 5
case 7: kp = 54; break; // 6
case 8: kp = 66; break; // B
case 9: kp = 55; break; // 7
case 10: kp = 56; break; // 8
case 11: kp = 57; break; // 9
case 12: kp = 67; break; // C
case 13: kp = 42; break; // *
case 14: kp = 48; break; // 0
case 15: kp = 35; break; // #
case 16: kp = 68; break; // D
  }
Lcd_Chr(1, 10, kp); // Print key ASCII value on Lcd

}
}

any one have solution about this... ?
 

hello ...

simply i use 16f877 and keypad 4*3 for just display on lcd the num pressed.
and this is keypad:
https://dlnmh9ip6v2uc.cloudfront.net/images/products/Keypad1-L.jpg

and my compiler i use is :mikroc pro for pic

and my project is successfully working in proteus >>> but in actual connection the lcd not display the correct number what i press!!!!

i connect the keypad to portD like that:
pin1>>>>RD0.....to 10k the GND
pin2>>>>RD1.....to 10k the GND
pin3>>>>RD2.....to 10k the GND
pin4>>>>RD3
pin5>>>>RD4
pin6>>>>RD5
pin7>>>>RD6

so is my hardware connection wrong !!?
=============
and my code here:

Code:
 sbit LCD_RS at RB0_bit;
 sbit LCD_EN at RB1_bit;

 sbit LCD_D4 at RB4_bit;
 sbit LCD_D5 at RB5_bit;
 sbit LCD_D6 at RB6_bit;
 sbit LCD_D7 at RB7_bit;

 sbit LCD_RS_Direction at TRISB0_bit;
 sbit LCD_EN_Direction at TRISB1_bit;
 sbit LCD_D4_Direction at TRISB4_bit;
 sbit LCD_D5_Direction at TRISB5_bit;
 sbit LCD_D6_Direction at TRISB6_bit;
 sbit LCD_D7_Direction at TRISB7_bit;

  char  keypadPort at PORTD;
int kp;
void main() {
 Keypad_Init();
 Lcd_Init();                 // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR);         // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);     // Cursor off



while (1) {
  kp = Keypad_Key_Press();
switch (kp) {

case 1: kp = 49; break; // 1 // Uncomme
case 2: kp = 50; break; // 2
case 3: kp = 51; break; // 3
case 4: kp = 65; break; // A
case 5: kp = 52; break; // 4
case 6: kp = 53; break; // 5
case 7: kp = 54; break; // 6
case 8: kp = 66; break; // B
case 9: kp = 55; break; // 7
case 10: kp = 56; break; // 8
case 11: kp = 57; break; // 9
case 12: kp = 67; break; // C
case 13: kp = 42; break; // *
case 14: kp = 48; break; // 0
case 15: kp = 35; break; // #
case 16: kp = 68; break; // D
  }
Lcd_Chr(1, 10, kp); // Print key ASCII value on Lcd

}
}

any one have solution about this... ?

If you are using 4X3 keyboard then why there are 16 choices in that switch-case statement?

---------- Post added at 09:21 ---------- Previous post was at 09:04 ----------


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
switch (kp) {
 
case 1: kp = 49; break; // 1 // Uncomme
case 2: kp = 50; break; // 2
case 3: kp = 51; break; // 3
case 4: kp = 52; break; // 4
case 5: kp = 53; break; // 5
case 6: kp = 54; break; // 6
case 7: kp = 55; break; // 7
case 8: kp = 56; break; // 8
case 9: kp = 57; break; // 9
case 10: kp = 42; break; // *
case 11: kp = 48; break; // 0
case 12: kp = 35; break; // #
default:   kp += 48;
 
 
  }

 

thx mr.papunblg for your notice

but i think that's not the main problem .. bcz the switch will takes only the first 12 possibilities in it..right?

and i want to sure from my hardware connecting if true !!!? bcz the project worked in Proteus fine.

so can u find any notices of problems?!

thx again..
 

The problem is that you are using mikroC inbuilt library routines for 4X4 keypad which use 8 pins. In your case follow the connection as shown in the following picture but do not connect the line which is connected to A B C and D buttons.

**broken link removed**

Now your code will work with the modified switch-case statement.


or
Using existing connection try to find what Keypad_Key_Press() is returning for each key press and use those values in the switch-case function.

Or if you like

write your own routines
 
Last edited:

In the picture PORTB is used, In your case it will be PORTD
 

thank you alot man with this illustration

my project works successfully after modification

and i found the other problem OR the main problem that my keypad i use above have different Distribution pins{not like other keypad}


so any one use this kind .. here is the actual Distribution pins <from left to right>:
Pin 1: Column 2
Pin 2: Row 1
Pin 3: Column 1
Pin 4: Row 4
Pin 5: Column 3
Pin 6: Row 3
Pin 7: Row 2

sure with pullup resistors with columns

good luck;
 

Thanks for your pinout sharing. Now you can mark the thread as solved.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top