拜读了圈圈的书,按书中所讲搭了块板(用mega16+d12)
现在情况是:读芯片ID是对的(返回0x1012),可d12的14脚(int_n)一直为低电平?
//================================================
//Main_Program
void main(void)
{
unsigned char id0=0;
unsigned char id1=0;
unsigned char intSource=0;
DDRA|=0xE0;
Uart_Init();
DDRB|=0xF0;
delay_ms(100);
D12WriteDataOrCmd(0xFD,COMMAND);
id0=D12ReadData();
id1=D12ReadData();
if(id0==0x12 && id1==0x10)
printf(" ID is correct! Congratulations! \r\n");
UsbDisconnect();
UsbConnect();
//**************************************************************************
for(;;)
{
if(D12GetIntPin()==0)
{
D12WriteDataOrCmd(READ_INT_REG,COMMAND); //写读中断寄存器的命令
intSource=D12ReadData(); //读回第一字节的中断寄存器
printf("intSource = %d \r\n",intSource);
if(intSource&0x80) //总线挂起中断
UsbBusSuspend();
if(intSource&0x40) //总线复位中断
UsbBusReset();
if(intSource&0x01) //端点0输出中断
UsbEp0Out();
if(intSource&0x02) //端点0输入中断
UsbEp0In();
if(intSource&0x04) //端点1输出中断
UsbEp1Out();
if(intSource&0x08) //端点1输入中断
UsbEp1In();
if(intSource&0x10) //端点2输出中断
UsbEp2Out();
if(intSource&0x20) //端点2输入中断
UsbEp2In();
}
}
} |