?? consol.c
字號:
* Arguments : none.
*
* Return : Returns the received Integer value.
*
* Note(s) :
*********************************************************************************************
*/
int CONSOL_GetIntNum(void)
{
char abStr[30];
char *pbString=abStr;
int wBase=10;
int wMinus=0;
int wLastIndex;
int wResult=0;
int wI;
CONSOL_GetString(pbString);
if(pbString[0]=='-'){wMinus=1;pbString++;}
if(pbString[0]=='0' && (pbString[1]=='x' || pbString[1]=='X'))
{
wBase=16;
pbString+=2;
}
wLastIndex=strlen(pbString)-1;
if( pbString[wLastIndex]=='h' || pbString[wLastIndex]=='H' )
{
wBase=16;
pbString[wLastIndex]=0;
wLastIndex--;
}
if(wBase==10)
{
wResult=atoi(pbString);
wResult=wMinus ? (-1*wResult):wResult;
}
else
{
for(wI=0; wI<=wLastIndex; wI++)
{
if(__isalpha(pbString[wI]))
{
if(__isupper(pbString[wI]))
wResult=(wResult<<4)+pbString[wI]-'A'+10;
else
wResult=(wResult<<4)+pbString[wI]-'a'+10;
}
else
{
wResult=(wResult<<4)+pbString[wI]-'0';
}
}
wResult=wMinus ? (-1*wResult):wResult;
}
return wResult;
}
/*
*********************************************************************************************
* CONSOL_SendChar
*
* Description: This routine waits till the character is sent.
*
* Arguments : bData - Data to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_SendChar(char bData)
{
switch(__wChannel)
{
case 0:
while(rUFSTAT0 & 0x200); //Wait until THR is empty.
// Delay(4);
rUTXH0 = bData;
break;
case 1:
while(rUFSTAT1 & 0x200); //Wait until THR is empty.
// Delay(4);
rUTXH1 = bData;
break;
case 2:
while(rUFSTAT2 & 0x200); //Wait until THR is empty.
// Delay(4);
rUTXH2 = bData;
break;
}
}
/*
*********************************************************************************************
* CONSOL_SendCh
*
* Description: This routine waits till the character is sent. It also sends an extra carriage
* return character when sending a new line character
*
* Arguments : bData - Data to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_SendCh(char bData)
{
if(bData == '\n')
{
CONSOL_SendChar('\r');
}
CONSOL_SendChar(bData);
}
/*
*********************************************************************************************
* CONSOL_SendString
*
* Description: This routine waits till the string is sent.
*
* Arguments : pbString - String to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_SendString(char *pbString)
{
while(*pbString)CONSOL_SendCh(*pbString++);
}
/*
*********************************************************************************************
* CONSOL_Scanf
*
* Description: Reads input from the consol stream, under control of the string pointed to by
* format that specifies the admissible input sequences and how they are to be
* converted for assignment, using subsequent arguments as pointers to the
* objects to receive the converted input. If there are insufficient arguments
* for the format, the behavior is undefined. If the format is exhausted while
* arguments remain, the excess arguments are ignored.
*
* Arguments : pcFmt - Format string. It can contain only the following format specifiers:
* %s - String.
* %c - character.
* %i - Integer.
* ... - Are the passed parameters (pointers to the objects to receive the
* converted input).
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_Scanf(char *pcFmt,...)
{
va_list pArg;
char cChar;
int *pwInt;
char *pbChar;
va_start(pArg, pcFmt);
while((cChar=*pcFmt++) != '\0')
{
if(cChar != '%')continue;
switch(*pcFmt)
{
case 's':
case 'S':
pbChar = va_arg (pArg, char *);
CONSOL_GetString(pbChar);
break;
case 'i':
case 'I':
pwInt = va_arg (pArg, int *);
*pwInt = CONSOL_GetIntNum();
break;
case 'c':
case 'C':
pbChar = va_arg (pArg, char *);
*pbChar = CONSOL_GetCh();
break;
}
}
va_end(pArg);
}
/*
*********************************************************************************************
* CONSOL_Printf
*
* Description: Writes output to the consol stream, under control of the string pointed to by
* format that specifies how subsequent arguments are converted for output. If
* there are insufficient arguments for the format, the behavior is undefined.
* If the format is exhausted while arguments remain, the excess arguments are
* ignored.
*
* Arguments : pcFmt - Format string. It can contain all the format specifies.
* ... - Are the passed parameters (pointers to the objects to receive the
* converted input).
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_Printf(char *pcFmt,...)
{
va_list ap;
char pbString[256];
va_start(ap,pcFmt);
vsprintf(pbString,pcFmt,ap);
CONSOL_SendString(pbString);
va_end(ap);
}
/* ********************************************************************* */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -