void CH375_INIT() { unsigned char i; unsigned char xdata str[20]; lcd_init() ;
CH375_WR_CMD_PORT(CMD_CHECK_EXIST); //測(cè)試CH375是否正常工作 CH375_WR_DAT_PORT(0x55); //寫(xiě)入測(cè)試數(shù)據(jù) i = CH375_RD_DAT_PORT(); //返回?cái)?shù)據(jù)應(yīng)該是測(cè)試數(shù)據(jù)取反
if(i != ~0x55) { for ( i=80; i!=0; i-- ) { CH375_WR_CMD_PORT(CMD_RESET_ALL); //多次重復(fù)發(fā)命令,執(zhí)行硬件復(fù)位 */ CH375_RD_DAT_PORT(); } CH375_WR_CMD_PORT(0); delay_ms(15); //延時(shí)50ms sprintf(str,"####################"); print_str(2,0,str); } CH375_WR_CMD_PORT(CMD_SET_USB_MODE); CH375_WR_DAT_PORT(0x02); //設(shè)置為使用內(nèi)置固件的USB設(shè)備方式 */ delay_ms(50); i = CH375_RD_DAT_PORT(); if(i == CMD_RET_SUCCESS) { sprintf(str,"枚舉成功!%bx ",CMD_RET_SUCCESS); print_str(1,0,str); } else { sprintf(str,"枚舉失敗!%x ",CMD_RET_ABORT); print_str(1,0,str); } /*******************外部中斷0初始化*************************/ IT0 = 0; //低電平觸發(fā) EX0 = 1; //開(kāi)外部中斷0 EA = 1; //開(kāi)中斷總開(kāi)關(guān) }
void CH375_ISR() interrupt 0 using 2 { unsigned char status = 0; unsigned char i, length; unsigned char buffer[20]; uchar xdata str2[20]; EA = 0;
CH375_WR_CMD_PORT(CMD_GET_STATUS); //獲取中斷狀態(tài)并取消中斷請(qǐng)求 status = CH375_RD_DAT_PORT(); //獲取中斷狀態(tài) sprintf(str2,"status: %bx ",status); print_str(2,0,str2); switch (status) { //分析中斷狀態(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ū) length = CH375_RD_DAT_PORT(); //首先讀取后續(xù)數(shù)據(jù)長(zhǎng)度 for(i=0; i { buffer[i] = CH375_RD_DAT_PORT(); //接收數(shù)據(jù)包 } buffer[i] = '\0'; CH375_WR_CMD_PORT(CMD_WR_USB_DATA7); // 向USB端點(diǎn)2的發(fā)送緩沖區(qū)寫(xiě)入數(shù)據(jù)塊 CH375_WR_DAT_PORT(length); // 首先寫(xiě)入后續(xù)數(shù)據(jù)長(zhǎng)度,回傳剛接收到的數(shù)據(jù)長(zhǎng)度 for ( i=0;i< length; i++) { CH375_WR_DAT_PORT(buffer[i]+1); // 數(shù)據(jù)取反后返回,由計(jì)算機(jī)應(yīng)用程序測(cè)試數(shù)據(jù)是否正確 */ } break; } case USB_INT_EP2_IN: //批量數(shù)據(jù)上傳成功 { CH375_WR_CMD_PORT(CMD_UNLOCK_USB); //釋放當(dāng)前USB緩沖區(qū) break; } default: { //其它中斷,未用到,解鎖后退出即可 CH375_WR_CMD_PORT(CMD_UNLOCK_USB); //釋放當(dāng)前USB緩沖區(qū) break; } } // EA = 1; }
想問(wèn)沁恒的工程師們一個(gè)問(wèn)題,我最近做一個(gè)項(xiàng)目,用的是華邦單片機(jī)做USB設(shè)備開(kāi)發(fā),CH375枚舉成功,發(fā)送數(shù)據(jù)后也能響應(yīng)中斷,但是在中斷服務(wù)程序中用CH375_WR_CMD_PORT(CMD_GET_STATUS);獲得中斷狀態(tài),返回中斷狀態(tài)傎都是0,測(cè)中斷引腳一直為低電平,也就是說(shuō)CH375_WR_CMD_PORT(CMD_GET_STATUS)命令執(zhí)行不成功,不然的話(huà),這個(gè)引腳會(huì)變成高電平,請(qǐng)問(wèn)我的說(shuō)法是不是正確?上面貼的是初始化和中斷程序,問(wèn)題急待解決,匆吝賜教!