/* CH375中斷服務(wù)程序,使用寄存器組1 */ void mCh375Interrupt( void ) //interrupt 0 using 1 { unsigned char InterruptStatus; unsigned char i, length; //unsigned char data buffer[ 64 ]; unsigned char buffer[ 64 ]; unsigned char Lenth[ 60 ]; //a++; CH375_WR_CMD_PORT( CMD_GET_STATUS ); /* 獲取中斷狀態(tài)并取消中斷請(qǐng)求 */ InterruptStatus = CH375_RD_DAT_PORT( ); /* 獲取中斷狀態(tài) */ switch ( InterruptStatus ) { /* 分析中斷狀態(tài)處理 */ case USB_INT_EP2_OUT: { /* 批量端點(diǎn)下傳成功 */ CH375_WR_CMD_PORT( CMD_RD_USB_DATA ); /* 從當(dāng)前USB中斷的端點(diǎn)緩沖區(qū)讀取數(shù)據(jù)塊,并釋放緩沖區(qū) */ CH375_RD_DAT_PORT( ); length = RD_DATA; /* 首先讀取后續(xù)數(shù)據(jù)長度 */ for ( i = 0; i < length; i ++ ) { CH375_RD_DAT_PORT( ); buffer[ i ] = RD_DATA; /* 接收數(shù)據(jù)包 */ } CH375_WR_CMD_PORT( CMD_WR_USB_DATA7 ); /* 向USB端點(diǎn)2的發(fā)送緩沖區(qū)寫入數(shù)據(jù)塊 */ CH375_WR_DAT_PORT( length ); /* 首先寫入后續(xù)數(shù)據(jù)長度,回傳剛接收到的數(shù)據(jù)長度 */ for ( i = 0; i { buffer[ i ] = ~buffer[ i ] ; CH375_WR_DAT_PORT( buffer[ i ] ); /* 數(shù)據(jù)取反后返回,由計(jì)算機(jī)應(yīng)用程序測試數(shù)據(jù)是否正確 */ } break; } case USB_INT_EP2_IN: { /* 批量數(shù)據(jù)發(fā)送成功 */ CH375_WR_CMD_PORT( CMD_UNLOCK_USB ); /* 釋放當(dāng)前USB緩沖區(qū) */ PTCD_PTCD5 = 0; break; } default: { /* 其它中斷,未用到,解鎖后退出即可 */ CH375_WR_CMD_PORT( CMD_UNLOCK_USB ); /* 釋放當(dāng)前USB緩沖區(qū) */ break; } } }
void main(void) {
MCUinit(); port_init(); Delay50ms( ); /* 延時(shí)等待CH375初始化完成,如果單片機(jī)由CH375提供復(fù)位信號(hào)則不必延時(shí) */ CH375_Init( ); /* 初始化CH375 */ while ( 1 ) /* 以下指令開始工作循環(huán),等待PC機(jī)命令進(jìn)行操作 */ { if(!CH375_INT) { mCh375Interrupt(); } } }