这个问题是昨天提出的,中断程序我这么修改:
#pragma vector = INT0_vect __interrupt void int0_isr(void) { uint8 len_temp,i; CH375_WR_CMD_PORT( CMD_GET_STATUS );//产生操作完成中断, 获取中断状态 status = CH375_RD_DAT_PORT( ); switch(status) { case USB_INT_SUCCESS: len_temp = rd_usb_data(data_buf);//鼠标中断端点数据长度为4字节 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: //如果是设备拨出状态码 device_disconnect = 1; break; default: CH375_WR_CMD_PORT( CMD_CLR_STALL ); CH375_WR_DAT_PORT( 1 ); //如果设备端不是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) //检测到鼠标拨出,则跳出这个死循环到外一层死循环 { _CLI(); //关闭外部中断 break; //跳出当当前的死循环 } }while( 1 ); //while (wait_interrupt() != USB_INT_DISCONNECT); /* 等待设备端连接上来 */
原来的程序的最后一句我注释掉了. 我这样修改行吗?