⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 consol.c

📁 这是s3c2410的几个基础实验代码,在ads下编译通过,上机调过,能用
💻 C
📖 第 1 页 / 共 2 页
字号:
* 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 + -