#include #include #include //#include //#include sbit CS=P2^1; sbit A0=P2^0; //sbit WR=P3^6; //sbit RD=P3^7; sbit INT=P3^2; /* 为printf和getkey输入输出初始化串口 */ void mInitSTDIO( void ) { SCON = 0x50; PCON = 0x00; TMOD = 0x20; TH1 = 0xfd; /* 11.0592MHz晶振, 9600bps */ TL1 = 0xfd; TR1 = 1; TI = 1; } void delay(unsigned int z) { unsigned int x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void CH376_Write_Cmd(unsigned char cmd)//io 写命令 { CS=0; A0=1; P0=cmd; WR=0; WR=1; CS=1; A0=1; } void CH376_Write_Dat(unsigned char dat)//io 写数据 { CS=0; A0=0; P0=dat; WR=0; WR=1; CS=1; A0=1; } unsigned char CH376_Read_Dat()//io读数据 { unsigned char temp; CS=0; A0=0; RD=0; P0=0xff; temp=P0; RD=1; CS=1; A0=1; return temp; } unsigned char CH376_Wait_Int()//等待中断 { INT=1; while(INT); CH376_Write_Cmd(CMD01_GET_STATUS); return CH376_Read_Dat(); } unsigned char CH376_InitDisk() //初始化U盘 { unsigned char status; printf( "初始化U盘: \n" ); printf( "请插入U盘: \n" ); status=CH376_Wait_Int(); if(status==USB_INT_CONNECT) {printf( "U盘已插入 \n" );} else {printf( "U盘插入错误 \n" );} CH376_Write_Cmd(CMD0H_DISK_INIT); status=CH376_Wait_Int(); if(status!=USB_INT_SUCCESS) { printf( "U盘初始化失败 \n" ); return(status); } printf( "初始化U盘成功 \n" ); printf( "\n" ); return(0); } void main() { unsigned char s; mInitSTDIO(); s=CH376_InitDisk(); }
不知道为什么,上电后用超级终端看串口返回的信息只看到"初始化U盘:"和"请插入U盘:"这两句,然后插入U盘就没下文了,请各位帮忙看看?UploadImages/20104162225817.rar