這個問題是昨天提出的,中斷程序我這么修改:
#pragma vector = INT0_vect __interrupt void int0_isr(void) { uint8 len_temp,i; CH375_WR_CMD_PORT( CMD_GET_STATUS );//產(chǎn)生操作完成中斷, 獲取中斷狀態(tài) status = CH375_RD_DAT_PORT( ); switch(status) { case USB_INT_SUCCESS: len_temp = rd_usb_data(data_buf);//鼠標(biāo)中斷端點數(shù)據(jù)長度為4字節(jié) for(i = 0; i != len_temp; i++) { data_in[i] = data_buf[i]; } flag_output = 1; toggle_recv( ); issue_token((endp_int << 4) | DEF_USB_PID_IN break; case USB_INT_DISCONNECT: //如果是設(shè)備撥出狀態(tài)碼 device_disconnect = 1; break; default: CH375_WR_CMD_PORT( CMD_CLR_STALL ); CH375_WR_DAT_PORT( 1 ); //如果設(shè)備端不是CH37X芯片,需要修改端點號 endp6_mode = 0x80; endp7_mode = 0x80; toggle_recv( ); issue_token((endp_int << 4) | DEF_USB_PID_IN); break; } }
主程序我這么修改:
do{ if(flag_output == 1) { P1_2 ^= 0x01; flag_output = 0; } if(device_disconnect == 1) //檢測到鼠標(biāo)撥出,則跳出這個死循環(huán)到外一層死循環(huán) { _CLI(); //關(guān)閉外部中斷 break; //跳出當(dāng)當(dāng)前的死循環(huán) } }while( 1 ); //while (wait_interrupt() != USB_INT_DISCONNECT); /* 等待設(shè)備端連接上來 */
原來的程序的最后一句我注釋掉了. 我這樣修改行嗎?