www.pudn.com > STM32_CH376-SPI.zip > debug.c, change:2014-01-15,size:2398b
#include "DEBUG.H" #include "usart.h" #include "delay.h" /******************************************************************************* * 函 数 名 : mStopIfError * 描 述 : 检查操作状态,如果错误则显示错误代码并停机,应该替换为实际的处 * 理措施,例如显示错误信息,等待用户确认后重试等. * 输 入 : UINT8 iError: * 返回状态. * 返 回 : 无. *******************************************************************************/ void mStopIfError( UINT8 iError ) { if ( iError == USB_INT_SUCCESS ) { return; /* 操作成功 */ } printf( "Error: %02X\n", (UINT16)iError ); /* 显示错误 */ // while ( 1 ) /* 可用LED灯做指示 */ // { ///* LED_OUT_ACT( ); */ /* LED闪烁 */ // delay_ms( 200 ); ///* LED_OUT_INACT( ); */ // delay_ms( 200 ); // } } /****************************************************************** - 功能描述:将一个16位的变量dat转为字符串,比如把1234转为"1234" - 隶属模块:公开函数模块 - 函数属性:外部,用户可调用 - 参数说明:dat:带转的long型的变量 str:指向字符数组的指针,转换后的字节串放在其中 - 返回说明:无 ******************************************************************/ unsigned char u16tostr(unsigned int dat,char *str) { char temp[30]; unsigned char i=0,j=0; i=0; while(dat) { temp[i]=dat%10+0x30; i++; dat/=10; } j=i; printf("j=%d",j); for(i=0;i<j;i++) { str[i]=temp[j-i-1]; } if(!i) {str[i++]='0';} str[i]=0; return j; } /****************************************************************** - 功能描述:将一个字符串转为16位的变量,比如"1234"转为1234 - 隶属模块:公开函数模块 - 函数属性:外部,用户可调用 - 参数说明:str:指向待转换的字符串 - 返回说明:转换后的数值 ******************************************************************/ unsigned int strtou16(char *str) { unsigned int temp=0; unsigned int fact=1; unsigned char len=strlen(str); unsigned char i; for(i=len;i>0;i--) { temp+=((str[i-1]-0x30)*fact); fact*=10; } return temp; } /************************************ End *************************************/