弱弱的问问高手[求助]

我在使用CH375做设备方式的时候参照CH372的资料,根据光盘资料中"CH372\CHECK\PUB\MCU_IF\C"目录下的CH372FRM.C给的框架写了一个简单的程序,想看看CH375与PC机通信是否建立,并且传输一些数据看看是否能正确传输。但是程序执行到:CH375_WR_CMD_PORT( CMD_GET_STATUS );IntStatus = CH375_RD_DAT_PORT( );的时候,IntStatus中的数据始终是F0,并没有正确获得中断状态。并且根据PC端的打印结果来看,数据也没有完成上传与下传,不知道究竟是什么原因。请高手指点一下,感激不尽!

这是写的简单的PC机收发一组数据的程序:

#include #include #include #include #include #include "CH375DLL.H" void main ( ) { unsigned char mBuffer[4100]; unsigned char mReadBuf[100]; unsigned long i, mLength, mErrCnt, mTotal; printf( "*** CH375OpenDevice: mode 0 \n" ); if ( CH375OpenDevice( 0 ) == INVALID_HANDLE_VALUE ) return; CH375SetTimeout( 0, 2000, 2000 ); mErrCnt=0; mTotal=64; for(i=1;i<64;i++)mBuffer[i]=rand(); if ( CH375WriteData( 0, &mBuffer, &mTotal ) ) { printf("CH375WriteData length = %ld\n",mTotal); for(i=1;i<6;i++) printf("download first 5 data = %02XH\n",mBuffer[i]); } else { mErrCnt++; printf( "CH375ReadData return error\n"); } if ( CH375ReadData( 0, &mReadBuf, &mLength ) ) { printf("read data length = %ld",mLength); for(i=0;i printf("read data = %02XH\n",mReadBuf[i]); if ( mLength != mTotal || mLength==0 ) { mErrCnt++; printf( "return length error: %ld (%ld)\n", mLength, mTotal ); } else { for(i=1;i<6;i++) printf("upload first 5 data = %ld\n",mReadBuf[i]); } } else { mErrCnt++; printf( "CH375WriteData return error, length=%ld\n",mTotal ); } if ( mErrCnt==0 ) printf( "pass\n" ); Sleep(100); printf( "Total error = %ld \n", mErrCnt ); printf( "*** CH375CloseDevice: 0 \n" ); CH375CloseDevice( 0 ); printf( "\nExit.\n" ); getch(); }


这个是单片机程序

#include "reg52.H" #include "CH375INC.H" #ifdef __CX51__ #ifndef __C51__ #define __C51__ 1 #pragma NOAREGS #endif #endif typedef unsigned char UINT8; typedef unsigned short UINT16; typedef unsigned long UINT32; #ifdef __C51__ typedef unsigned char idata *PUINT8; typedef unsigned char volatile xdata IOPORT; #else typedef unsigned char *PUINT8; typedef unsigned char volatile IOPORT; #endif #define DELAY_START_VALUE 1

void Delay1us( ) { #if DELAY_START_VALUE != 0 UINT8 i; for ( i=DELAY_START_VALUE; i!=0; i-- ); #endif }

void Delay2us( ) { UINT8 i; for ( i=DELAY_START_VALUE*2+1; i!=0; i-- ); }

void CH375_WR_CMD_PORT( UINT8 cmd ) { CH375_CMD_PORT=cmd; Delay2us(); }

void CH375_WR_DAT_PORT( UINT8 dat ) { CH375_DAT_PORT=dat; Delay1us(); }

UINT8 CH375_RD_DAT_PORT( void ) { Delay1us(); return( CH375_DAT_PORT ); }

void CH375_Init( void ) { UINT8 i; #ifdef MY_USB_VENDOR_ID #ifdef MY_USB_PRODUCT_ID CH375_WR_CMD_PORT( CMD_SET_USB_ID ); CH375_WR_DAT_PORT( (UINT8)MY_USB_VENDOR_ID ); CH375_WR_DAT_PORT( (UINT8)(MY_USB_VENDOR_ID>>8) ); CH375_WR_DAT_PORT( (UINT8)MY_USB_PRODUCT_ID ); CH375_WR_DAT_PORT( (UINT8)(MY_USB_PRODUCT_ID>>8) ); #endif #endif

CH375_WR_CMD_PORT( CMD_SET_USB_MODE ); CH375_WR_DAT_PORT( 2 ); for ( i=100; i!=0; i-- ) if ( CH375_RD_DAT_PORT( ) == CMD_RET_SUCCESS ) break;

#ifdef __C51__ IT0 = 0; IE0 = 0; EX0 = 1; #endif }

UINT8 UsbLength; UINT8 UsbBuffer[ CH375_MAX_DATA_LEN ];

void mCH375Interrupt( void ) interrupt 0 using 1 { UINT32 IntStatus = 0; UINT8 cnt; PUINT8 buf; CH375_WR_CMD_PORT( CMD_GET_STATUS ); IntStatus = CH375_RD_DAT_PORT( ); if ( IntStatus == USB_INT_EP2_OUT ) { CH375_WR_CMD_PORT( CMD_RD_USB_DATA ); UsbLength = cnt = CH375_RD_DAT_PORT( ); if ( cnt ) { buf = UsbBuffer; do { *buf = CH375_RD_DAT_PORT( ); buf ++; } while ( -- cnt ); } else return; CH375_WR_CMD_PORT( CMD_WR_USB_DATA7 ); cnt = UsbLength; CH375_WR_DAT_PORT( cnt ); if ( cnt ) { buf = UsbBuffer; do { CH375_WR_DAT_PORT( *buf ); buf ++; } while ( -- cnt ); } }

else if ( IntStatus == USB_INT_EP2_IN ) { CH375_WR_CMD_PORT( CMD_UNLOCK_USB ); } } main( void ) { CH375_Init( ); EA = 1; while ( 1 ) ; }


两个程序都被你改过了,不巧的是都改出问题了。 你还是先用TEST目录下的试吧,针对MCS51的,更简单


只有登录才能回复,可以选择微信账号登录