程序调试心得分享
时间:10-02
整理:3721RD
点击:
- /***********************************************************
- ****程序全称:数据高低位转换
- ****程序功能:1001010101011100=0011101010101001
- ****输 入: 要转换位数 要转换数据
- ****返 回:转换后的数据
- ***********************************************************/
- int data_to_data(unsigned char num,unsigned int data)
- { //高低位..互换.
- unsigned char i;
- unsigned int m = 0;
-
- for(i = 0;i<num;i++){
- m= (m<<1)+(data&1);
- data >>=1;
- }
- return(m);
- }
- /***********************************************************
- ****程序全称:数据高低位转换
- ****程序功能:10010101=10101001
- ****输 入: 要转换数据
- ****返 回:转换后的数据
- ***********************************************************/
- uchar reverse_bit(uchar data)
- { //高低位..互换.
- data=(data<<4)|(data>>4);
- data=((data&0x33)<<2)|((data&0xCC)>>2);
- data=((data&0x55)<<1)|((data&0xAA)>>1);
- return data;
- }
3,得到指定地址上的一个字节或字
- #define MEM_B( x ) ( *( (byte *) (x) ) )
- #define MEM_W( x ) ( *( (word *) (x) ) )
- #define MAX( x, y ) ( ((x) > (y)) ? (x) : (y) )
- #define MIN( x, y ) ( ((x) < (y)) ? (x) : (y) )
- #define FPOS( type, field ) \
- /*lint -e545 */ ( (dword) &(( type *) 0)-> field ) /*lint +e545 */
- #define FSIZ( type, field ) sizeof( ((type *) 0)->field
7,按照LSB格式把两个字节转化为一个Word
- #define FLIPW( ray ) ( (((word) (ray)[0]) * 256) + (ray)[1] )
- #define FLOPW( ray, val ) \
- (ray)[0] = ((val) / 256); \
- (ray)[1] = ((val) & 0xFF)
- #define B_PTR( var ) ( (byte *) (void *) &(var) )
- #define W_PTR( var ) ( (word *) (void *) &(var) )
- #define WORD_LO(xxx) ((byte) ((word)(xxx) & 255))
- #define WORD_HI(xxx) ((byte) ((word)(xxx) >> 8))
- #define RND8( x ) ((((x) + 7) / 8 ) * 8 )
- #define UPCASE( c ) ( ((c) >= 'a' && (c) <= 'z') ? ((c) - 0x20) : (c) )
- #define DECCHK( c ) ((c) >= '0' && (c) <= '9')
- #define HEXCHK( c ) ( ((c) >= '0' && (c) <= '9') ||\
- ((c) >= 'A' && (c) <= 'F') ||\
- ((c) >= 'a' && (c) <= 'f') )
- #define INC_SAT( val ) (val = ((val)+1 > (val)) ? (val)+1 : (val))
- #define ARR_SIZE( a ) ( sizeof( (a) ) / sizeof( (a[0]) ) )
- #define MOD_BY_POWER_OF_TWO( val, mod_by ) \
- ( (dword)(val) & (dword)((mod_by)-1) )
- /*****************************************************************************
- **** Byte2BCD
- ****
- ****
- *****************************************************************************/
- uchar Byte2BCD(uchar Data)
- {
- uchar Rslt=0;
-
- if (Data>=99) return 0x99;
- while(Data>9)
- {
- Data-=10;
- Rslt+=0x10;
- }
- return(Rslt+Data);
- }
- /*****************************************************************************
- **** BCD2Byte
- ****
- ****
- *****************************************************************************/
- uchar BCD2Byte(uchar Data)
- {
- return(((Data>>4)&0x0f)*10+(Data&0x0f));
- }