375可以枚舉,但是沒中斷,程序如下:

//GCC //ATMEGA16L //內(nèi)部晶振 8M //CH375 _INT M16_INT0(PD2/16腳) //CH375 _CS (PC0/22腳) //CH375 _WR (PC1/23腳) //CH375 _RD (PC2/24腳) //CH375 _A0 (PC3/25腳) /* ; CH375/CH372 Bulk Data Test ; U2(AT89C51) Program ; 本程序測試數(shù)據(jù)傳輸?shù)恼_性,可以用于長時間連續(xù)測試,對應(yīng)的計算機端的測試程序為TEST.EXE ; 方法: 下傳隨機長度的隨機數(shù)據(jù)包,被單片機接收并將數(shù)據(jù)按位取反后返回,最終由計算機程序接收后比較數(shù)據(jù)是否正確 */

#include #include

#define CH375_CMD_PORT 0xBDF1 /* CH375命令端口的I/O地址 */ #define CH375_DAT_PORT 0xBCF0 /* CH375數(shù)據(jù)端口的I/O地址 */

//============================================================= //延時 //8M=2.25us //=============================================================

void delay2us( ) { asm("nop"); }

//============================================================= //延時指定毫秒時間,根據(jù)單片機主頻調(diào)整,不精確 //8M=6180us //============================================================= void mDelaymS( unsigned char ms ) { volatile unsigned int i; while ( ms -- ) for ( i = 2600; i != 0; i -- ); }

//============================================================= // //通過并口直接讀寫CH375 // //向CH375的命令端口寫入命令,周期不小于4uS,如果單片機較快則延時 //============================================================= void CH375_WR_CMD_PORT( unsigned char cmd ) { delay2us(); PORTA = cmd; //向CH375的并口輸出數(shù)據(jù) DDRA = 0xFF; //并口D0-D7輸出

//輸出有效寫控制信號, 寫CH375芯片的命令端口 PORTC|=(1< PORTC&=~(1< PORTC&=~(1< PORTC|=(1< DDRA = 0xFF; /* 該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS */

//輸出無效的控制信號, 完成操作CH375芯片 PORTC|=(1< PORTC|=(1< PORTC|=(1< PORTC|=(1< DDRA = 0x00; //禁止數(shù)據(jù)輸出 PORTC&=~(1< delay2us(); } //============================================================= // //通過并口直接寫CH375 // //向CH375的數(shù)據(jù)端口寫入數(shù)據(jù),周期不小于1.5uS,如果單片機較快則延時 //============================================================= void CH375_WR_DAT_PORT( unsigned char dat ) { PORTA = dat; //向CH375的并口輸出數(shù)據(jù) DDRA = 0xFF; //并口D0-D7輸出

//輸出有效寫控制信號, 寫CH375芯片的數(shù)據(jù)端口 PORTC&=~(1< PORTC&=~(1< PORTC&=~(1< PORTC|=(1< DDRA = 0xFF; //該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS

//輸出無效的控制信號, 完成操作CH375芯片 PORTC&=~(1< PORTC|=(1< PORTC|=(1< PORTC|=(1< DDRA = 0x00; //禁止數(shù)據(jù)輸出 delay2us(); } //============================================================= // //通過并口直接讀CH375 // //從CH375的數(shù)據(jù)端口讀出數(shù)據(jù),周期不小于1.5uS,如果單片機較快則延時 //============================================================= unsigned char CH375_RD_DAT_PORT( void ) { volatile unsigned char mData; delay2us(); DDRA = 0x00; //數(shù)據(jù)輸入

//輸出有效讀控制信號, 讀CH375芯片的數(shù)據(jù)端口 PORTC&=~(1< PORTC&=~(1< PORTC|=(1< PORTC&=~(1< DDRA = 0x00; //該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS mData = PINA; //從CH375的并口PA輸入數(shù)據(jù)

//輸出無效的控制信號, 完成操作CH375芯片 PORTC&=~(1< PORTC|=(1< PORTC|=(1< PORTC|=(1< return( mData ); } //============================================================= // // CH375初始化子程序 // //============================================================= void CH375_Init( ) { volatile unsigned char i; //測試CH375是否正常工作,可選操作,通常不需要 CH375_WR_CMD_PORT( 0x06 ); //測試CH375是否正常工作=0x06 CH375_WR_DAT_PORT( 0x55 ); //寫入測試數(shù)據(jù) i = ~ 0x55; if ( CH375_RD_DAT_PORT( ) != i ) //返回數(shù)據(jù)應(yīng)該是測試數(shù)據(jù)取反 { //CH375不正常 for ( i=20; i!=0; i-- ) { CH375_WR_CMD_PORT( 0x05 ); //多次重復(fù)發(fā)命令,執(zhí)行硬件復(fù)位=0x05 CH375_RD_DAT_PORT( ); } CH375_WR_CMD_PORT( 0 ); mDelaymS(10); //延時60ms } //設(shè)置USB工作模式, 必要操作 CH375_WR_CMD_PORT( 0x15 ); //設(shè)置USB工作模式0x15 CH375_WR_DAT_PORT( 2 ); //設(shè)置為使用內(nèi)置固件的USB設(shè)備方式 for ( i=100; i!=0; i-- ) { //等待操作成功,通常需要等待10uS-20uS if ( CH375_RD_DAT_PORT( ) == 0x51 ) break; //命令操作成功=0x51 } //if ( i==0 ) { CH372/CH375存在硬件錯誤 };

//下述啟用中斷,CH375連接在INT0 MCUCR=(0< MCUCR=(0< GICR=(1< GIFR=(1<}

//============================================================= // // CH375中斷服務(wù)程序,使用INT0 // //============================================================= SIGNAL (INT0_vect) { GIFR=(1< volatile unsigned char InterruptStatus; volatile unsigned char i, length; volatile unsigned char buffer[ 64 ];

CH375_WR_CMD_PORT( 0x22 ); //獲取中斷狀態(tài)并取消中斷請求=0x22 InterruptStatus = CH375_RD_DAT_PORT( ); //獲取中斷狀態(tài) switch ( InterruptStatus ) { //分析中斷狀態(tài)處理 case 0x02: //USB_INT_EP2_OUT=0x02 { //批量端點下傳成功 CH375_WR_CMD_PORT( 0x28 ); //從當(dāng)前USB中斷的端點緩沖區(qū)讀取數(shù)據(jù)塊,并釋放緩沖區(qū)=0x28 length = CH375_RD_DAT_PORT( ); //首先讀取后續(xù)數(shù)據(jù)長度 for ( i = 0; i < length; i ++ ) buffer[ i ] = CH375_RD_DAT_PORT( ); //接收數(shù)據(jù)包 //測試數(shù)據(jù)正確性,將接收到的命令包數(shù)據(jù)取反后返回給PC機 CH375_WR_CMD_PORT( 0x2b ); //向USB端點2的發(fā)送緩沖區(qū)寫入數(shù)據(jù)塊=0x2b CH375_WR_DAT_PORT( length ); //首先寫入后續(xù)數(shù)據(jù)長度,回傳剛接收到的數(shù)據(jù)長度 for ( i = 0; i < length; i ++ ) CH375_WR_DAT_PORT( ~buffer[ i ] ); //數(shù)據(jù)取反后返回,由計算機應(yīng)用程序測試數(shù)據(jù)是否正確 break; } case 0x0a: //USB_INT_EP2_IN=0x0a { //批量數(shù)據(jù)發(fā)送成功 CH375_WR_CMD_PORT( 0x23 ); //釋放當(dāng)前USB緩沖區(qū)=0x23 break; } default: { //其它中斷,未用到,解鎖后退出即可 CH375_WR_CMD_PORT( 0x23 ); //釋放當(dāng)前USB緩沖區(qū)=0x23 break; } } }

//============================================================= // // 主程序 // //============================================================= int main(void ) { DDRA=0xFF; DDRC=0xFF; PORTA=0xFF; PORTC=0xFF;

mDelaymS(8); //延時約48ms等待CH375初始化完成,如果單片機由CH375提供復(fù)位信號則不必延時 CH375_Init( ); //初始化CH375 sei(); //允許中斷 while(1); }


熱門產(chǎn)品 : USB3.0 HUB控制器:CH634

是指找到了設(shè)備,沒有實現(xiàn)下傳數(shù)據(jù)?CH375的中斷腳可變低了? 將三個子程序用下面這個試試. //向CH375的命令端口寫入命令,周期不小于4uS,如果單片機較快則延時 //============================================================= void CH375_WR_CMD_PORT( unsigned char cmd ) { //delay2us(); PORTA = cmd; //向CH375的并口輸出數(shù)據(jù) PORTC|=(1<DDRA = 0xFF; //并口D0-D7輸出

//輸出有效寫控制信號, 寫CH375芯片的命令端口 PORTC|=(1<PORTC&=~(1<PORTC&=~(1< DDRA = 0xFF; /* 該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS */

PORTC|=(1<PORTC|=(1<PORTC&=~(1<//PORTC|=(1<DDRA = 0x00; //禁止數(shù)據(jù)輸出

//delay2us(); } //============================================================= // //通過并口直接寫CH375 // //向CH375的數(shù)據(jù)端口寫入數(shù)據(jù),周期不小于1.5uS,如果單片機較快則延時 //============================================================= void CH375_WR_DAT_PORT( unsigned char dat ) { PORTA = dat; //向CH375的并口輸出數(shù)據(jù) DDRA = 0xFF; //并口D0-D7輸出

//輸出有效寫控制信號, 寫CH375芯片的數(shù)據(jù)端口 //PORTC&=~(1<PORTC&=~(1<PORTC&=~(1<//PORTC|=(1<DDRA = 0xFF; //該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS PORTC|=(1<PORTC|=(1<DDRA = 0x00; //禁止數(shù)據(jù)輸出 // delay2us(); } //============================================================= // //通過并口直接讀CH375 // //從CH375的數(shù)據(jù)端口讀出數(shù)據(jù),周期不小于1.5uS,如果單片機較快則延時 //============================================================= unsigned char CH375_RD_DAT_PORT( void ) { volatile unsigned char mData; // delay2us(); DDRA = 0x00; //數(shù)據(jù)輸入

//輸出有效讀控制信號, 讀CH375芯片的數(shù)據(jù)端口 //PORTC&=~(1< PORTC&=~(1<//PORTC|=(1< PORTC&=~(1<DDRA = 0x00; //該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS mData = PINA; //從CH375的并口PA輸入數(shù)據(jù)

//輸出無效的控制信號, 完成操作CH375芯片 //PORTC&=~(1< //PORTC|=(1<PORTC|=(1<PORTC|=(1<return( mData ); }


測INT0沒有低電平信號.


按照你所說,在計算機端可以找到外部接口CH375/CH372嗎?如果找到的話,那么,只有在你計算機端給你發(fā)送數(shù)據(jù)之后才會出現(xiàn)中斷的。


我用上位機TEST軟件測試,INT0不為0


現(xiàn)在INTO為低電平,改為查詢方式.上位機TEST軟件返回為:return length error:0


那你用CH372DBG這個軟件來調(diào)試??聪掠袥]有數(shù)據(jù)給你返回


沒有數(shù)據(jù)返回.


那在上位機給你傳輸數(shù)據(jù)的時候,下位機收到的中斷之后,中斷狀態(tài)是多少?是端點2下傳端點嗎?如果是的話,那么,能讀取到數(shù)據(jù)嗎?


//GCC //ATMEGA16L //內(nèi)部晶振 8M //CH375 _INT M16_INT0(PD2/16腳) //CH375 _CS (PC0/22腳) //CH375 _WR (PC1/23腳) //CH375 _RD (PC2/24腳) //CH375 _A0 (PC3/25腳) /* ; CH375/CH372 Bulk Data Test ; U2(AT89C51) Program ; 本程序測試數(shù)據(jù)傳輸?shù)恼_性,可以用于長時間連續(xù)測試,對應(yīng)的計算機端的測試程序為TEST.EXE ; 方法: 下傳隨機長度的隨機數(shù)據(jù)包,被單片機接收并將數(shù)據(jù)按位取反后返回,最終由計算機程序接收后比較數(shù)據(jù)是否正確 */

#include #include

#define CH375_CMD_PORT 0xBDF1 /* CH375命令端口的I/O地址 */ #define CH375_DAT_PORT 0xBCF0 /* CH375數(shù)據(jù)端口的I/O地址 */

//============================================================= //延時 //8M=2.25us //=============================================================

void delay2us( ) { asm("nop"); }

//============================================================= //延時指定毫秒時間,根據(jù)單片機主頻調(diào)整,不精確 //8M=6180us //============================================================= void mDelaymS( unsigned char ms ) { unsigned int i; while ( ms -- ) for ( i = 2600; i != 0; i -- ); }

//============================================================= // //通過并口直接讀寫CH375 // //向CH375的命令端口寫入命令,周期不小于4uS,如果單片機較快則延時 //============================================================= void CH375_WR_CMD_PORT( unsigned char cmd ) { delay2us(); PORTC|=(1<PORTA = cmd; //向CH375的并口輸出數(shù)據(jù) DDRA = 0xFF; //并口D0-D7輸出

//輸出有效寫控制信號, 寫CH375芯片的命令端口 PORTC|=(1< PORTC&=~(1< PORTC&=~(1<PORTC|=(1<DDRA = 0xFF; /* 該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS */

//輸出無效的控制信號, 完成操作CH375芯片 PORTC|=(1<PORTC|=(1<PORTC|=(1<PORTC|=(1<DDRA = 0x00; //禁止數(shù)據(jù)輸出 PORTC&=~(1< delay2us(); } //============================================================= // //通過并口直接寫CH375 // //向CH375的數(shù)據(jù)端口寫入數(shù)據(jù),周期不小于1.5uS,如果單片機較快則延時 //============================================================= void CH375_WR_DAT_PORT( unsigned char dat ) { PORTA = dat; //向CH375的并口輸出數(shù)據(jù) DDRA = 0xFF; //并口D0-D7輸出

//輸出有效寫控制信號, 寫CH375芯片的數(shù)據(jù)端口 PORTC&=~(1< PORTC&=~(1< PORTC&=~(1<PORTC|=(1<DDRA = 0xFF; //該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS

//輸出無效的控制信號, 完成操作CH375芯片 PORTC&=~(1<PORTC|=(1<PORTC|=(1<PORTC|=(1<DDRA = 0x00; //禁止數(shù)據(jù)輸出 delay2us(); } //============================================================= // //通過并口直接讀CH375 // //從CH375的數(shù)據(jù)端口讀出數(shù)據(jù),周期不小于1.5uS,如果單片機較快則延時 //============================================================= unsigned char CH375_RD_DAT_PORT( void ) { unsigned char mData; delay2us(); DDRA = 0x00; //數(shù)據(jù)輸入

//輸出有效讀控制信號, 讀CH375芯片的數(shù)據(jù)端口 PORTC&=~(1< PORTC&=~(1<PORTC|=(1< PORTC&=~(1<DDRA = 0x00; //該操作無意義,僅作延時,CH375要求讀寫脈沖寬度大于100nS mData = PINA; //從CH375的并口PA輸入數(shù)據(jù)

//輸出無效的控制信號, 完成操作CH375芯片 PORTC&=~(1<PORTC|=(1<PORTC|=(1<PORTC|=(1<return( mData ); } //============================================================= // // CH375初始化子程序 // //============================================================= void CH375_Init( ) { unsigned char i; //測試CH375是否正常工作,可選操作,通常不需要 CH375_WR_CMD_PORT( 0x06 ); //測試CH375是否正常工作=0x06 CH375_WR_DAT_PORT( 0x55 ); //寫入測試數(shù)據(jù) i = ~ 0x55; if ( CH375_RD_DAT_PORT( ) != i ) //返回數(shù)據(jù)應(yīng)該是測試數(shù)據(jù)取反 { //CH375不正常 for ( i=20; i!=0; i-- ) { CH375_WR_CMD_PORT( 0x05 ); //多次重復(fù)發(fā)命令,執(zhí)行硬件復(fù)位=0x05 CH375_RD_DAT_PORT( ); } CH375_WR_CMD_PORT( 0 ); mDelaymS(10); //延時60ms } //設(shè)置USB工作模式, 必要操作 CH375_WR_CMD_PORT( 0x15 ); //設(shè)置USB工作模式0x15 CH375_WR_DAT_PORT( 2 ); //設(shè)置為使用內(nèi)置固件的USB設(shè)備方式 for ( i=100; i!=0; i-- ) { //等待操作成功,通常需要等待10uS-20uS if ( CH375_RD_DAT_PORT( ) == 0x51 ) break; //命令操作成功=0x51 } //if ( i==0 ) { CH372/CH375存在硬件錯誤 }; }

//============================================================= // // 主程序 // //============================================================= int main(void ) { DDRA=0xFF; DDRC=0xFF; DDRD=0x00; PORTA=0xFF; PORTC=0xFF; PORTD=0xFF; mDelaymS(8); //延時約48ms等待CH375初始化完成,如果單片機由CH375提供復(fù)位信號則不必延時 CH375_Init( ); //初始化CH375 while(1) { PORTD=0XFF; if(PIND&0x04) { unsigned char InterruptStatus; unsigned char i, length; unsigned char buffer[ 64 ];

CH375_WR_CMD_PORT( 0x22 ); //獲取中斷狀態(tài)并取消中斷請求=0x22 InterruptStatus = CH375_RD_DAT_PORT( ); //獲取中斷狀態(tài) switch ( InterruptStatus ) { //分析中斷狀態(tài)處理 case 0x02: //USB_INT_EP2_OUT=0x02 { //批量端點下傳成功 CH375_WR_CMD_PORT( 0x28 ); //從當(dāng)前USB中斷的端點緩沖區(qū)讀取數(shù)據(jù)塊,并釋放緩沖區(qū)=0x28 length = CH375_RD_DAT_PORT( ); //首先讀取后續(xù)數(shù)據(jù)長度 for ( i = 0; i < length; i ++ ) buffer[ i ] = CH375_RD_DAT_PORT( ); //接收數(shù)據(jù)包 //測試數(shù)據(jù)正確性,將接收到的命令包數(shù)據(jù)取反后返回給PC機 CH375_WR_CMD_PORT( 0x2b ); //向USB端點2的發(fā)送緩沖區(qū)寫入數(shù)據(jù)塊=0x2b CH375_WR_DAT_PORT( length ); //首先寫入后續(xù)數(shù)據(jù)長度,回傳剛接收到的數(shù)據(jù)長度 for ( i = 0; i < length; i ++ ) CH375_WR_DAT_PORT( ~buffer[ i ] ); //數(shù)據(jù)取反后返回,由計算機應(yīng)用程序測試數(shù)據(jù)是否正確 break; } case 0x0a: //USB_INT_EP2_IN=0x0a { //批量數(shù)據(jù)發(fā)送成功 CH375_WR_CMD_PORT( 0x23 ); //釋放當(dāng)前USB緩沖區(qū)=0x23 break; } default: { //其它中斷,未用到,解鎖后退出即可 CH375_WR_CMD_PORT( 0x23 ); //釋放當(dāng)前USB緩沖區(qū)=0x23 break; } } //end switch }//end if }//end while }


用USBDEBUG軟件調(diào)試,顯示"讀取數(shù)據(jù)錯誤"


我現(xiàn)在是問你你上位機給下位機寫數(shù)據(jù)的時候,下位機有中斷過來嗎?中斷狀態(tài)是多少?


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

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