發(fā)表于:2008-1-31 20:15:00,來源于:222.69.62.162 發(fā)貼心情: ----------------------------------------------------------------------------------------------------- 偶用374模擬并口方式和計算機(jī)通信,芯片用DSPIC的現(xiàn)在程序遇到點(diǎn)麻煩,讀寫時序沖突,當(dāng)WR為低時,RD也有低電平,打電話后按你們的方式做還是有讀寫沖突,而且和網(wǎng)上帖子給我的關(guān)于時序的處理方法的 建議(hcn給的)有出入,特把程序貼出來,望幫忙看看:: D端口有12個引腳,低8位數(shù)據(jù)連374并口,高4位連信號線! #define CH374_DATA_DAT_OUT(d) (LATD=(LATD&&0XFF00)+d)//數(shù)據(jù)輸出 #define CH374_DATA_DAT_IN() (LATD&&0X00FF)//數(shù)據(jù)輸出 #define CH374_DATA_DIR_OUT() (TRISD&=0X0000)//設(shè)置口為輸出 #define CH374_DATA_DIR_IN() (TRISD|=0X00FF)//設(shè)置口為輸入 [ 1] WRITE374indeX( UINT8mindex) { //DSP復(fù)位后引腳能輸出高電平 CH374_RD=1; CH374_DATA_DIR_OUT(); CH374_DATA_DAT_OUT(d); ch374_A0=1; CH374_CS=0; CH374_WR=0; mDelayus(1);//125ns CH374_WR=1; CH374_CS=0; CH374_DATA_DIR_IN(); ch374_A0=0; } //=========================================================================== [2] WRITE374DATA( UINT8 mdata) { CH374_RD=1; CH374_DATA_DIR_OUT();//設(shè)置為輸出 CH374_DATA_DAT_OUT(d);//輸出數(shù)據(jù) ch374_A0=0; CH374_CS=0; CH374_WR=0; mDelayus(1);//125ns CH374_WR=1; CH374_CS=0; CH374_DATA_DIR_IN(); //ch374_A0=1; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ [3] READ374DATA(VOID) { UINT8 mDATA; //CH374_WR=1; CH374_DATA_DIR_IN(); CH374_A0=0; CH374_CS=0; CH374_RD=0; mDelayus(1);//125ns mDATA=CH374_DATA_DAT_IN(); CH374_RD=1; CH374_CS=1; } 這是按照你們的提示做的,示波器上WR/RD信號有沖突,374的指示燈亮,PC沒有發(fā)現(xiàn)未知硬件提示!沒有用4通道測CS/A0????? 謝謝---------------------! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 你的程序應(yīng)該這樣寫: [ 1] WRITE374indeX( UINT8mindex) { //DSP復(fù)位后引腳能輸出高電平 CH374_RD=1; CH374_DATA_DIR_OUT(); CH374_DATA_DAT_OUT(d); ch374_A0=1; CH374_CS=0; CH374_WR=0; mDelayus(1);//125ns CH374_WR=1; CH374_CS=1; // CH374_DATA_DIR_IN(); ch374_A0=0; } //=========================================================================== [2] WRITE374DATA( UINT8 mdata) { CH374_RD=1; CH374_DATA_DIR_OUT();//設(shè)置為輸出 CH374_DATA_DAT_OUT(d);//輸出數(shù)據(jù) ch374_A0=0; CH374_CS=0; CH374_WR=0; mDelayus(1);//125ns CH374_WR=1; CH374_CS=1; // CH374_DATA_DIR_IN(); //ch374_A0=1; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ [3] READ374DATA(VOID) { UINT8 mDATA; //CH374_WR=1; CH374_DATA_DIR_IN(); CH374_A0=0; CH374_CS=0; CH374_RD=0; mDelayus(1);//125ns mDATA=CH374_DATA_DAT_IN(); CH374_RD=1; CH374_CS=1; } ------------------------------------------- __________________________________________ 按你們說的方法還是出現(xiàn)讀寫沖突,還有別的原因嗎? 比如軟件復(fù)位,以及其他?
按照你上面說的,你的D口的高4位為控制位,這樣的話,你這樣看下,在你將RD或者WR拉低之后,你看下別的信號線是否有沖突,因為這個不是我們時序的問題,可能是你I/O端口會不會出現(xiàn)沖突之類的。
關(guān)于8位數(shù)據(jù)口這幾個宏定義有問題 #define CH374_DATA_DAT_OUT(d) (LATD=(LATD&&0XFF00)+d)//數(shù)據(jù)輸出 應(yīng)改為 #define CH374_DATA_DAT_OUT(d) (LATD = (LATD & 0XFF00) + d)//數(shù)據(jù)輸出
#define CH374_DATA_DAT_IN() (LATD&&0X00FF)//數(shù)據(jù)輸出 應(yīng)改為 #define CH374_DATA_DAT_IN() (LATD & 0X00FF)//數(shù)據(jù)輸出
你的CS A0 WR RD不知道是怎么配置的?
&&: 邏輯與 &: 位運(yùn)算與 我搞錯了~~~~~~~~~ 讀寫沖突問題解決! CS A0 WR RD分別通過D端口引腳 發(fā)送高低電平! 但是現(xiàn)在計算機(jī)還是只能提示"無法識別的USB設(shè)備",并且和374?。粒茫耍_相連的指示燈不亮,能產(chǎn)生中斷,想在程序中讀取寄存器的值,讀不到! 該怎么辦,有什么方法!