/* ******************************************************************************** SIEMENS C511/C513 STARTER KIT -------------------------------------------------------------------------------- PROGRAM ssc1_ma -------------------------------------------------------------------------------- MODUL NAME ssc1_ma2.c -------------------------------------------------------------------------------- DESCRIPTION This module contains functions for reading characters and numbers via serial interface. The functions are adapted for the use via simulated IO feature of the dScope debugger (0x11 is filtered out). Characters are converted to integers with atoi() which is basically the same as the library function. -------------------------------------------------------------------------------- FUNCTIONS int atoi (char *); unsigned int getnumber (void); void getline (char *); -------------------------------------------------------------------------------- NOTE No precautions are implemented for overflow of line[] buffer -------------------------------------------------------------------------------- VERSION V1.0 -------------------------------------------------------------------------------- COMPILER Keil PK51 Eval V5.02 -------------------------------------------------------------------------------- SEE ALSO ssc1_ma1.c -------------------------------------------------------------------------------- DATE 16/10/95 -------------------------------------------------------------------------------- MODIFICATIONS none ******************************************************************************** */ /*********************** Compiler Includes ******************************/ #include /* define I/O functions */ #include /* for atoi function */ /*********************** Prototypes ******************************/ /* int atoi (char *); */ unsigned int getnumber (void); void getline (char *); /*********************** Program Code ******************************/ void getline (char *line) { while ((*line = getchar()) != '\n') if (*line != 0x11 ) line++; } /*----------------------------------------------------------------------------*/ #if 0 int atoi (char *line) { bit sign; int number; /* skip white space */ for ( ; *line == ' ' || *line == '\n' || *line == '\t'; line++); /* establish sign */ sign = 1; if (*line == '+' || *line == '-') sign = (*line++ == '+'); /* compute decimal value */ for (number=0; *line >= '0' && *line <= '9'; line++) number = (number * 10) + (*line - '0'); return (sign ? number : -number); } #endif /*----------------------------------------------------------------------------*/ unsigned int getnumber (void) { char line [40]; getline (line); return (atoi (line)); }