AVR 软件操作库函数
扫描二维码
随时随地手机看文章
1.C语言宏定义技巧(常用宏定义)
1,防止一个头文件被重复包含
#ifndef COMDEF_H
#define COMDEF_H
//头文件内容
#endif
2,重新定义一些类型,防止由于各种平台和编译器的不同,而产生的类型字节数差异,方便移植.
typedef unsigned char boolean;
typedef unsigned long int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
typedef signed long int int32;
typedef signed short int16;
typedef signed char int8;
2.AVR 软件操作库函数
uint8 dataElem[6];
void speaData(uint32 dat,sint8 len)
{
uint8 i;
uint32 j,y;
for(i=0,j=1;i
y=dat/j;
dataElem[i]=y;
j*=10;
}
}
#define changeIntToHex(dec) ( ( ((dec)/10) <<4 ) + ((dec)) )
#define converseIntToHex(dec) ( ( ((dec)>>4) *10 ) + ((dec)) )
#define changeHexToInt(hex) ( ( ((hex)>>4) *10 ) + ((hex)) )
#define converseHexToInt(hex) ( ( ((hex)/10) <<4 ) + ((hex)) )
#endif
*--------------------------------------------------------------------
程序全称:数据拆字程序
程序功能:
注意事项:D<=999999,C<=6
提示说明:调用speaData(12,2),得到dataElem[0]=2,dataElem[1]=1
输入:
返回:无
--------------------------------------------------------------------*/
uint8 dataElem[6];
void speaData(uint32 dat,sint8 len)
{
uint8 i;
uint32 j,y;
for(i=0,j=1;i
y=dat/j;
dataElem[i]=y;
j*=10;
}
}
#define changeIntToHex(dec)( ( ((dec)/10) <<4 ) + ((dec)) )
#define converseIntToHex(dec)( ( ((dec)>>4) *10 ) + ((dec)) )
#define changeHexToInt(hex)( ( ((hex)>>4) *10 ) + ((hex)) )
#define converseHexToInt(hex)( ( ((hex)/10) <<4 ) + ((hex)) )
#endif