Debug.c
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:1k
- #include <REG52.H>
- #include "Debug.H"
- xdata unsigned char hex[]={"0123456789ABCDEF"}; //为ascii-》hex的转换表
- /*
- void DebugInit(void)
- {
- TMOD=0x21;
- SCON=0x50;
- TH1=0xfd;
- TL1=0xfd ;
- IP=0x10;
- PCON|=0x80;
- TR1=1;
- EA=0;
- ET0=0;
- ES=0;
- RI=0;
- }
- */
- unsigned char DebugSend(unsigned char de_data)
- {
- unsigned int Dtime=0;
- SBUF=de_data;
- do{
- Dtime++;
- if(Dtime>1000)
- return 1;
- }while(!TI);
- TI=0;
- return 0;
- }
- void Debughex(unsigned char senddata)
- {
- unsigned char ch;
- ch=senddata>>4;
- DebugSend(hex[ch]);
- ch=senddata&0x0f;
- DebugSend(hex[ch]);
- }
- void DebugString(unsigned char *string)
- {
- while(*string!=0)
- {
- DebugSend(*string);
- string++;
- }
- }
- void DebugData(unsigned int length,unsigned char x,unsigned char *buff)
- {
- unsigned int i=0,j=0;
- unsigned int pos=0;
- unsigned char temp;
- for(i=0;i<length/x;i++)
- {
- for(j=0;j<x;j++)
- {
- temp=buff[pos];
- Debughex(temp);
- temp<<=2;
- DebugString(" ");
- pos++;
- }
- DebugString("rn");
- }
- for(i=0;i<(length%x);i++)
- {
- Debughex(buff[pos]);
- DebugString(" ");
- pos++;
- }
- DebugString("rn");
- }