#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 寫數(shù)據(jù) { CS=0; A0=0; P0=dat; WR=0; WR=1; CS=1; A0=1; } unsigned char CH376_Read_Dat()//io讀數(shù)據(jù) { 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