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.

[PIC] convert individual digits (from the keypads) into a single number

Status
Not open for further replies.

dorutomkat

Newbie level 3
Joined
Jul 10, 2008
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
convert individual digit (fom keypad) into a single number

Hi,
I have in my mind a programable counter. When i input a digits form keypad (1,2,3,4) , it's mean i input "1234". the counter (i resolved that part), start (after i input "#" from keypad) and stop at designated number like "1234".

i try with "FloatToStr" but, i'm not sure it's work!

any help?
thank you!

P.S.
i'm rookie in mikroc!
 

Re: convert individual digit (fom keypad) into a single number

long value = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
 

Re: convert individual digit (fom keypad) into a single number

Hi,

Or on each input:

value = value x 10 + new_input

Klaus
 

Re: convert individual digit (fom keypad) into a single number

Thank you all, I will try, back with details!
 

Re: convert individual digit (fom keypad) into a single number

hi again!
As expected, it not work!
I hope that I understood what you meant. I think kp+10, or kp+100, etc, is not a number!
This is part of my program:


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
// pic16F877A
  unsigned short kp ;
  char  keypadPort at PORTD;
  unsigned int v;
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_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 TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_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;
// End LCD module connections
 
  char *digit="0000";
 
  void main()
  {
   int x=1;
  Keypad_Init();                           // Initialize Keypad
  lcd_init();
  lcd_cmd(_lcd_clear);
  lcd_cmd(_lcd_cursor_off);
    do {
    kp = 0;                                // Reset key code variable
 
    do
 
     kp = Keypad_Key_Click();             // Store key code in kp variable
     while (!kp);
     switch (kp)
     {
      case  1: kp = 49; break; // 1
      case  2: kp = 50; break; // 2
      case  3: kp = 51; break; // 3
      case  5: kp = 52; break; // 4
      case  6: kp = 53; break; // 5
      case  7: kp = 54; break; // 6
      case  9: kp = 55; break; // 7
      case 10: kp = 56; break; // 8
      case 11: kp = 57; break; // 9
      case 14: kp = 48; break; // 0
      }
      
       digit[0]=kp;
       digit[1]=kp*10;
       digit[2]=kp*100;
       digit[3]=kp*1000;
      
       v=digit[1]+digit[1]+digit[2]+digit[3];
      
 
      Lcd_chr(1,x++,v);
      }
      while(1);
      }

 
Last edited by a moderator:

Re: convert individual digit (fom keypad) into a single number

Hi,

Undocumented code.
Not saying WHAT does not work.

How can we help?

What do you want to achieve with this?
Code:
 switch (kp)
     {
      case  1: kp = 49; break; // 1
...
digit[0]=kp;

Lets say kp = 1
Then you make kp = 49
Then you make digit[0] = 49

** very unclear why "49"...

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top