void main(void) //主函数
{
uint8 i;
uint16 id;
uint16 loop_counter = 0xE000;
uint8 InterruptSource;
//CLKCON = 0x60; //时钟12分频
XPAGE = 0;
FLASHCON = 0;
Led_status = 0;
while(loop_counter)
{
loop_counter++;loop_counter--;
loop_counter--;
}
Led_status = 1;
P0M1 = 0xFF;P0M0 = 0xFF;
P2M1 = 0x80;P2M0 = 0x80;
ALE = 0;
CS_D12 = 0;
InitUART(); //初始化串口
/*
for(i=0;i<19;i++) //显示信息
{
Send_Out_String(HeadTable[i]);
}
*/
id = D12ReadID();
//Send_Out_String("Your D12 chip\'s ID is: ");
PrintShortIntHex(id);
if(id==0x1012)
{
//Led_status = 0;
Send_Out_String(". ID is correct! Congratulations!\r\n\r\n");
}
else
{
Send_Out_String(". ID is incorrect! What a pity!\r\n\r\n");
}
UsbDisconnect(); //先断开USB连接
//D12SetAddress(0);
//D12SetEndpointEnable(1);
UsbConnect(); //将USB连接上
ConfigValue=0; //配置值初始化为0
while(1) //死循环
{
RSTSTAT = 0x01;
//Led_status = !Led_status;
if(D12GetIntPin()==0) //如果有中断发生
{
//Led_status = !Led_status;
D12WriteCommand(READ_INTERRUPT_REGISTER); //写读中断寄存器的命令
InterruptSource=D12ReadByte(); //读回第一字节的中断寄存器
// UartPutChar(0xA5);UartPutChar(InterruptSource);UartPutChar(0x5A);
if(InterruptSource&0x80)UsbBusSuspend(); //总线挂起中断处理
if(InterruptSource&0x40)UsbBusReset(); //总线复位中断处理
if(InterruptSource&0x01)UsbEp0Out(); //端点0输出中断处理
if(InterruptSource&0x02)UsbEp0In(); //端点0输入中断处理
if(InterruptSource&0x04)UsbEp1Out(); //端点1输出中断处理
if(InterruptSource&0x08)UsbEp1In(); //端点1输入中断处理
if(InterruptSource&0x10)UsbEp2Out(); //端点2输出中断处理
if(InterruptSource&0x20)UsbEp2In(); //端点2输入中断处理
}
if(ConfigValue!=0) //如果已经设置为非0的配置,则可以返回报告数据
{
Led_status = !Led_status;
if(!Ep1InIsBusy) //如果端点1输入没有处于忙状态,则可以发送数据
{
loop_counter++;loop_counter &= 0x1FFF;
if(loop_counter == 0)
{
//Led_status = !Led_status;
SendReport(); //则返回报告
}
}
}
}
} |