PDA

View Full Version : convert the numbers to word



savnik
- 11th April 2007, 19:58
getword:
for x = 0 to 3
Gosub getkey ' Get a key from the keypad
lcdout I,Line2 + x,#key ' Display ASCII key number
next
return

I have a keypad and show the key on LCD if a button pressed.
Like this : 2438
How i can convert the numbers 2438 as a variable(word 2.438)

skimask
- 11th April 2007, 20:38
getword:
for x = 0 to 3
Gosub getkey ' Get a key from the keypad
lcdout I,Line2 + x,#key ' Display ASCII key number
next
return

I have a keypad and show the key on LCD if a button pressed.
Like this : 2438
How i can convert the numbers 2438 as a variable(word 2.438)

http://www.picbasic.co.uk/forum/showthread.php?t=6050
Posts #3 and #5

savnik
- 11th April 2007, 20:51
http://www.picbasic.co.uk/forum/showthread.php?t=6050
Posts #3 and #5
I don't want this
If i press the button 2 i take 2 , after i press the button 4 and take 4 ,etc
3 and 8
How to take a word with this number : 2 and 4 and 3 and 8
like this: value = 2438

skimask
- 11th April 2007, 20:54
I don't this
If i press the button 2 i take 2 , after i press the button 4 and take 4 ,etc
3 and 8
How to take a word with this number : 2 and 4 and 3 and 8
like this: value = 2438

I guess there's a bit of a language barrier going on here. I don't really get what you're trying to say...

Pic_User
- 11th April 2007, 21:08
Hi savnik,

See if I read you correctly.
You want the user to be able to press a series of buttons, on your keypad. You would like the PIC to take this series of separate button values and “string them together” (“concatenate” them). Then use them as a PIC WORD variable in your program.

You are able to read the individual button presses, but are having trouble putting them together to make the variable.

Is that close?

-Adam-

Ingvar
- 11th April 2007, 21:13
Perhaps somthing like this will do what you want.


getword:
value = 0
for x = 0 to 3
Gosub getkey ' Get a key from the keypad
lcdout I,Line2 + x,#key ' Display ASCII key number
SELECT CASE x
CASE 0
value = value + (key * 1000)
CASE 1
value = value + (key * 100)
CASE 2
value = value + (key * 10)
CASE 3
value = value + key
END SELECT
next
return

skimask
- 11th April 2007, 21:16
Hi savnik,
You want the user to be able to press a series of buttons, on your keypad. You would like the PIC to take this series of separate button values and “string them together” (“concatenate” them). Then use them as a PIC WORD variable in your program.
You are able to read the individual button presses, but are having trouble putting them together to make the variable.
Is that close?
-Adam-

Ok, well that makes a bit more sense to me...

getword:
for x = 0 to 3
Gosub getkey ' Get a key from the keypad
keyin(x) = key 'save the individual keypresses
lcdout I,Line2 + x,#key ' Display ASCII key number
next
outval = ( keyin(0) * 1000 ) + ( keyin(1) * 100 ) + ( keyin(2) * 10 ) + keyin(3)
return

savnik
- 11th April 2007, 21:20
sorry but my english is not good
when press the button 2 on keyboard the LCD show 2 on first position and after when press the button 4 on keyboard the LCD show 4 on second position etc.
I want the number 2,4,3,8 to be a variable (dec 2.348)

savnik
- 11th April 2007, 21:22
Hi savnik,

See if I read you correctly.
You want the user to be able to press a series of buttons, on your keypad. You would like the PIC to take this series of separate button values and “string them together” (“concatenate” them). Then use them as a PIC WORD variable in your program.

You are able to read the individual button presses, but are having trouble putting them together to make the variable.

Is that close?

-Adam-
yes , i want it

skimask
- 11th April 2007, 21:23
sorry but my english is not good
when press the button 2 on keyboard the LCD show 2 on first position and after when press the button 4 on keyboard the LCD show 4 on second position etc.
I want the number 2,4,3,8 to be a variable (dec 2.348)

You want the variable in memory (whether it be a byte or a word) to be:
x = 2.348 ?

savnik
- 11th April 2007, 22:00
Perhaps somthing like this will do what you want.


getword:
value = 0
for x = 0 to 3
Gosub getkey ' Get a key from the keypad
lcdout I,Line2 + x,#key ' Display ASCII key number
SELECT CASE x
CASE 0
value = value + (key * 1000)
CASE 1
value = value + (key * 100)
CASE 2
value = value + (key * 10)
CASE 3
value = value + key
END SELECT
next
return

Thank you
I wanted something like this

BigWumpus
- 11th April 2007, 23:01
Maybe this is more effectiv:


getword:
value = 0
for x = 0 to 3
Gosub getkey ' Get a key from the keypad
lcdout I,Line2 + x,#key ' Display ASCII key number
value=Value*10+key
next
return

skimask
- 11th April 2007, 23:35
Maybe this is more effectiv:


getword:
value = 0
for x = 0 to 3
Gosub getkey ' Get a key from the keypad
lcdout I,Line2 + x,#key ' Display ASCII key number
value=Value*10+key
next
return


OH...that is pretty slick...

savnik
- 12th April 2007, 08:00
Maybe this is more effectiv:


getword:
value = 0
for x = 0 to 3
Gosub getkey ' Get a key from the keypad
lcdout I,Line2 + x,#key ' Display ASCII key number
value=Value*10+key
next
return

Yes , is more effectiv
Thank you