piclist 1997\05\26\214501a >
Thread: CCS 'C' Code Help Req'
www.piclist.com/techref/index.htm?key=ccs+code+help+req
flavicon
face BY : Mike Smith email (remove spam text)



> From: Phil Whitmarsh <KILLspampjwdesignspam_OUTspamSTOPspamEMARKT.COM>
> To: EraseMEPICLISTEraseMEspamRemoveMEMITVMA.MIT.EDU
> Subject: CCS 'C' Code Help Req'
> Date: Tuesday, 27 May 1997 01:38
>
> Hello All,
>
> I have the PCM version of the CCS compiler and i am having problems
reading a
>  string through
> the serial port and then converting this to a value eg. send "255" and
convert
>  to 255

You want something like a  sscanf() function (shudder)  - which doesn't
come in the library.  I wrote a couple of routines called parsexxx, where
xxx is int or byte.  This extracts the nth number from a line.  It's not
terribly bulletproof, nor efficent, but it works...

// parse.c - contains routines for extracting numbers from command lines
// 5/11/96 Mike Smith

#define SHORTINT long
#define BYTE unsigned char
#define BOOL short int
#define FALSE 0
#define TRUE 1

// system includes
#include <16c74.h>
#include <ctype.h>

// pCH points to a null-terminated string
// parm indicates which white-space separated param you want.  (starts with
0)
// returns a 2 byte int
SHORTINT ParseInt(char* pCH, BYTE parm)
{       SHORTINT val;
       char ch;
       do
       {       val = 0;
               while(*pCH != '\0' && !isdigit(*pCH)) // skip white space
                       pCH++;
               ch = *pCH;
               while(isdigit(ch))
               {       val *= 10;
                       val += (ch - '0');
                       pCH++;
                       ch = *pCH;
               }
       } while(parm--);
       return val;
}

// same as above, but returns a one byte int
BYTE ParseBYTE(char* array, BYTE parm)
{       SHORTINT val;
       val = ParseInt(array, parm);
       return (BYTE)val;
}

// returns a bit value
BOOL ParseBOOL(char* array, BYTE parm)
{       SHORTINT val;
       val = ParseInt(array, parm);
       return (BOOL)val;
}

// doesn't expect hex numbers to be prefixed with 0x
SHORTINT ParseHexInt(char* pCH, BYTE parm)
{       SHORTINT val;

       char ch;
       do
       {       val = 0;
               while(*pCH != '\0' && !isxdigit(*pCH)) // skip white space
                       pCH++;
               ch = *pCH;
               while(isxdigit(ch))
               {       val *= 16;
                       if(isdigit(ch))
                               val += (ch - '0');
                       else
                               val += (toupper(ch) - 'A' + 10);
                       pCH++;
                       ch = *pCH;
               }
       } while(parm--);
       return val;
}

BYTE ParseHexBYTE(char* array, BYTE parm)
{       SHORTINT val;
       val = ParseHexInt(array, parm);
       return (BYTE)val;
}



> anybody able to give an example, also anybody got sample programs for the
CCS
>  compiler
> apart from the ones it came with !
>

Like for what?  I think we'd try the patience of PICLIST members by posting
unspecific code...

MikeS
<mikesmith_ozspamspam@spam@relaymail.net>

BTW, do ppl here have a preference for how stuff like the above is posted?
As an attachment?  A zipped attachment?  Inlined with mail?(as above)
<01421873488053@onaustralia.com.au> 7bit

See also: www.piclist.com/techref/index.htm?key=ccs+code+help+req
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) CCS 'C' Code Help Req'

month overview.

new search...