STC89C58控制CH375A芯片讀寫U盤問題

我正在用STC89C58單片機控制CH375A芯片讀寫U盤,電路圖基本按照CH375DS1.pdf文檔中并行方式,我只是省去了U3、U4、U5,而直接把CH375的A0、RD#、WR#、CS#、INT#和D0-D7引腳直接連接到單片機的IO引腳上,具體接法看我下面程序的引腳定義更清楚。單片機的串口我用來輸出數(shù)據(jù)到電腦上顯示CH375返回的數(shù)據(jù)以便于分析。我下載程序到單片機上運行,出現(xiàn)的現(xiàn)象: 1、不管輸入任何命令,CH375好像并沒有數(shù)據(jù)返回,理由是我讀CH375的數(shù)據(jù)口時返回的值都是單片機最后一次發(fā)給CH375的值; 2、插入U盤,串在ACT#引腳上的LED燈長亮,拔出U盤后則滅。

按我的分析,現(xiàn)象2說明了CH375已經(jīng)成功設置了USB工作模式,說明CH375已經(jīng)成功接收我命令(設置工作模式為06),也說明的寫命令和寫數(shù)據(jù)的函數(shù)是正確的。但是現(xiàn)象1我一直查不出原因,下面是我的程序,各位幫我分析分析,謝謝。

//這就是我的測試程序了 #include "reg52.h" #include #include "CH375_CMD.h" //CH375命令和常數(shù)的定義

#define CH375_IO P2 //數(shù)據(jù)口

sbit CH375_CS = P1^7; //CH375片選 sbit CH375_A0 = P1^6; //CH375數(shù)據(jù)命令選擇 sbit CH375_WR = P1^5; //CH375寫選通 sbit CH375_RD = P1^4; //CH375讀選通 sbit CH375_INT = P3^2; //CH375中斷

#define Select_Ch375( ) CH375_CS=0; #define Release_Ch375( ) CH375_CS=1;

#define Switch_Data( ) CH375_A0=0; #define Switch_cmd( ) CH375_A0=1;

#define Write_On( ) CH375_WR=0; #define Write_Off( ) CH375_WR=1;

#define Read_On( ) CH375_RD=0; #define Read_Off( ) CH375_RD=1;

void Init_Ser(void) //功能:初始化串口通訊 { //中斷允許 EA = 1; ES = 1; //允許串口中斷 EX0 = 1; //允許外部中斷0 //定時器T1設置,波特率9600,11.0592M TMOD = 0x20; TH1 = 0xfd; TL1 = 0xfd; //通訊模式設置 SM0 = 0; SM1 = 1; REN = 1; //允許接收 TR1 = 1; //啟動定時器 }

void SendStrToPC(uint8 *p) //功能:向PC串口發(fā)送字符串 { while(*p!='\0') { SBUF = (*p); while(!TI); TI = 0; p++; } }

void SendCHToPC(uint8 ch) //功能:向PC串口發(fā)送一個字符 { SBUF =ch; while(!TI); TI = 0; }

void mDelay100mS( ) { unsigned char i, j, c; for ( i = 200; i != 0; i -- ) for ( j = 200; j != 0; j -- ) c+=3; }

void CH375_Write_cmd(uint8 cmdCode) //寫命令 { Switch_cmd(); Read_Off( ); Write_Off(); CH375_IO = cmdCode; Write_On(); _nop_(); Write_Off(); Switch_Data(); CH375_IO=0xFF; }

void CH375_Write_Data(uint8 myData) //寫數(shù)據(jù) { Switch_Data(); Read_Off( ); Write_Off(); CH375_IO = myData; Write_On(); _nop_(); Write_Off(); CH375_IO=0xFF; //Switch_cmd(); }

uint8 CH375_Read_Data(void) //讀數(shù)據(jù) { uint8 temp; Switch_Data( ); Write_Off(); Read_Off( ); CH375_IO = 0xff; Read_On( ); _nop_(); temp = CH375_IO; Read_Off( ); //Switch_cmd( ); return (temp); }

uint8 CH375_Read_Sta(void) //讀中斷狀態(tài) { uint8 temp; Switch_cmd( ); Write_Off(); Read_Off( ); CH375_IO = 0xff; Read_On( ); _nop_(); temp = CH375_IO; Read_Off( ); Switch_Data( ); //Switch_cmd( ); return (temp); }

void Interrupt_int0(void) interrupt 0 //功能:處理外部中斷 { uchar i; CH375_Write_cmd(CMD_GET_STATUS); for(i=40;i>0;i--)i--; SendCHToPC(CH375_Read_Sta()); }

void Inter_Ser(void) interrupt 4 //功能:處理串口中斷 { //保留 }

void main(void) { uchar i,ch; Select_Ch375( ); Select_Ch375( ); Init_Ser(); //初始化串口 mDelay100mS(); SendStrToPC("ReSetCH375......\n"); CH375_Write_cmd(CMD_RESET_ALL); //執(zhí)行硬件復位 mDelay100mS(); SendStrToPC("Test CH375......\n"); CH375_Write_cmd(CMD_CHECK_EXIST); //測試CH375芯片是否在工作 CH375_Write_Data(0x5A); //寫數(shù)據(jù) for(i=40;i>0;i--)i--; ch=CH375_Read_Data(); SendCHToPC(ch); SendStrToPC("Set CH375 mode 07......\n"); CH375_Write_cmd(CMD_SET_USB_MODE); //先設置CH375的工作模式為07,再設置為06 CH375_Write_Data(0x07); for(i=30;i!=0;i--); //延時30us ch=CH375_Read_Data(); SendCHToPC(ch); SendStrToPC("Set CH375 mode 06......\n"); CH375_Write_cmd(CMD_SET_USB_MODE); CH375_Write_Data(0x06); //設置CH375的工作模式為06。至此,CH375的初始化算是完成了。 for(i=50;i!=0;i--)i--; //延時30us ch=CH375_Read_Data(); SendCHToPC(ch); SendStrToPC("CH375 initialize is OK..!\n"); //Release_Ch375(); while(1); }


單片機晶振是多少?


單片機和CH375的晶振都是12MHZ


只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频