📄 lpc_lib.c
字号:
/***********************************************************************
* BU MMS China, Philips Semiconductor Software Support
* Embest info&Tech Co. Software Support
*---------------------------------------------------------------------------
* The software is delivered "AS IS" without warranty or condition of any
* kind, either express, implied or statutory. Everybody can use it as
* it is opened and without copyright. We will not take any law responsibility
* for any problem produced by using this software.
*---------------------------------------------------------------------------
* File name: LPC_Lib.c
* Description: Define some common functions for LPC2000 API
*
* History:
* 1. Date: Aug 11, 2004
* Author: Shawn Zhang
* Description: Create
*
* $Revision: 1.0 $
**********************************************************************/
#include "LPC_Lib.h"
/*************************************************************************
* Function Name: BitToNum
* Parameters: unsigned long bit
*
* Return: unsigned long -- number
*
* Description: Convert bit format to number format.
* Eg. 0x10 -> 5
*
*************************************************************************/
unsigned int BitToNum(unsigned long bit)
{
unsigned int num=0;
unsigned long temp = bit;
while (temp != 1)
{
temp = temp>>1;
num++;
}
return num;
}
/*************************************************************************
* Function Name: strcpy
* Parameters: char *des
* const char *src
*
* Return: char * --the destination string
*
* Description: Copy a string.
*
*************************************************************************/
char *strcpy(char *des, const char *src)
{
char *pChar = des;
while(*src)
*(des++)=*(src++);
return pChar;
}
/*************************************************************************
* Function Name: strcat
* Parameters: char *des
* const char *src
*
* Return: char * --the destination string
*
* Description: Append a string
*
*************************************************************************/
char *strcat(char *des, const char *src)
{
char *pChar = des;
while(*des)
des++;
while(*src)
*(des++)=*(src++);
return pChar;
}
/*************************************************************************
* Function Name: itoa
* Parameters: int value
* char *string
* int radix
*
* Return: char * -- returns a pointer to string
*
* Description: Convert an integer to a string
*
*************************************************************************/
char *itoa( int value, char *string, int radix )
{
char *head, *tail, *pChar = string, temp;
int count = 0, x = value, i, y;
while(x)
{
y = x % radix;
if (y>=0 && y <=9)
*string++ = y + '0';
else if (y>=0xA && y<=0xF)
*string++ = y + '7';
count++;
x = x / radix;
}
for(i=0, head=pChar, tail=--string; i< count /2; i++, head++, tail--)
{
temp=*head;
*head = *tail;
*tail = temp;
}
return pChar;
}
/*************************************************************************
* Function Name: ultoa
* Parameters: long value
* char *string
* int radix
*
* Return: char * -- returns a pointer to string
*
* Description: Convert a long to a string
*
*************************************************************************/
char *ultoa(unsigned long value, char *string, int radix )
{
char *head, *tail, *pChar = string, temp;
unsigned long count = 0, x = value, i, y;
while(x)
{
y = x % radix;
if (y <=9)
*string++ = y + '0';
else if (y>=0xA && y<=0xF)
*string++ = y + '7';
count++;
x = (x / radix);
}
for(i=0, head=pChar, tail=--string; i< count /2; i++, head++, tail--)
{
temp=*head;
*head = *tail;
*tail = temp;
}
return pChar;
}
/*************************************************************************
* Function Name: atoi
* Parameters: char *string
*
* Return: int* -- returns a integer
* If the string is unvalid, return -1.
*
* Description: Convert a string to an integer
*
*************************************************************************/
int atoi(char *string )
{
char *pch = string;
int num=0;
while(*pch)
{
if (*pch<'0' || *pch>'9')
return -1;
num *= 10;
num += (*pch - '0');
pch++;
}
return num;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -