CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Keypad Routine to convert string to number

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guan Choon Lim
Guest







Keypad Routine to convert string to number
PostPosted: Tue Jun 03, 2003 4:29 am     Reply with quote

Hi,all. I am new to using PIC C. I am designing a Direct Digital Frequency synthesizer which comes with a LCD display and a 4x4 keypads. The LCD will prompt user to input the desired frequency in Hz through the keypad.

Problem:

Is there a simple routine or function to convert a number string to integer? The keybd.h driver provided by CCS does not seem to allow me to do so, especially when the input is multiple characters such as "2340".

Also, how does one usually implement a Carriage Return or Enter Key in the program?

Your help is hereby sought!!

Thank You
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514997
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: Keypad Routine to convert string to number
PostPosted: Tue Jun 03, 2003 5:02 am     Reply with quote

CCS has a few functions for this purpose. One of them is atoi() as I remember. You can check the CCS help for the rest of them.

Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514998
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Keypad Routine to convert string to number
PostPosted: Tue Jun 03, 2003 1:04 pm     Reply with quote

:=Is there a simple routine or function to convert a number string to integer? The keybd.h driver provided by CCS does not seem to allow me to do so, especially when the input is multiple characters such as "2340".
:=
:=Also, how does one usually implement a Carriage Return or Enter Key in the program?
:=
:=Your help is hereby sought!!
:=
:=Thank You
--------------------------------------------------------

The following routine takes less ROM than the full atoi
function. When reading this function, remember that in CCS,
a "long" is an unsigned 16 bit value. (ie., int16)

Code:

// Convert a string of up to 5 ascii decimal digits
// ("65535" max) to a binary long.   Any value that
// is not ascii decimal will end the conversion. For
// example  "25," will convert the first two digits and
// then stop at the comma, and return 25 as the result.

long adtol(char *ptr)
{
long retval;
char c;
char i;

retval = 0;

for(i = 0; i < 5; i++)
   {
    c = *ptr++;    // Read char from string

    if(c < '0')  // Test if it's an ascii decimal value
       break;
    if(c > '9')
       break;

    retval = (retval << 3) + (retval << 1) + (c - '0');   
   }

return(retval);
}



To answer your other question:
On a 3x4 or 4x4 keypad, there is typically no Enter key.
Use the '#' key or the '*' key as the Enter key.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515011

Edited two times, to fix the font size and also to put it in a
code block for easy reading.


Last edited by PCM programmer on Tue Jan 17, 2006 12:37 pm; edited 2 times in total
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: Keypad Routine to convert string to number
PostPosted: Tue Jun 03, 2003 7:40 pm     Reply with quote

If you want a quick & easy solution, here are the functions you can use:

atoi()
atoi32()
atol()
atof()
strtod()
strtol()
strtoul()

__Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515022
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group