打印

紧急求助圈圈 能读出D12的ID号0x1012但不能被主机检测

[复制链接]
1794|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
cooperate|  楼主 | 2013-1-19 10:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
cooperate|  楼主 | 2013-1-19 10:05 | 只看该作者
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();  //则返回报告
                                }
                        }
                 }
        }
}

使用特权

评论回复
板凳
cooperate|  楼主 | 2013-1-19 10:06 | 只看该作者
//PDIUSBD12芯片连接引脚
#define D12_DATA        P0
sbit D12_A0                =        P1^0;
sbit D12_WR                =        P2^6;
sbit D12_RD                =        P2^5;
sbit D12_INT        =        P2^7;

//选择命令或数据地址
#define D12SetCommandAddr() D12_A0=D12_COMMAND_ADD;_nop_();_nop_()
#define D12SetDataAddr()    D12_A0=D12_DATA_ADD;_nop_();_nop_()
//WR控制
#define D12SetWr() _nop_();_nop_();D12_WR=1;_nop_();_nop_()
#define D12ClrWr() _nop_();_nop_();D12_WR=0;_nop_();_nop_();_nop_()
//RD控制
#define D12SetRd() _nop_();_nop_();D12_RD=1;
#define D12ClrRd() D12_RD=0;_nop_();_nop_();_nop_()

使用特权

评论回复
地板
cooperate|  楼主 | 2013-1-29 11:07 | 只看该作者
已解决 谢谢

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

32

主题

230

帖子

0

粉丝