⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d12-avr._c

📁 D12固件程序
💻 _C
字号:
#include "io8515v.h"
#include "d12head.h"

unsigned int Rshu[3];
int q=0;
//#define D12_suspend (PINB & 0x01)

void D12_int(void)
{
	unsigned char i=0,j,c,*k;//三个变量,一个指针
	
	SREG = 0x00;//全局中断使能
	
	D12_COMMAND = 0xf4; // 读中断寄存器
	cwait1;
	i=D12_DATA;
	csram;
	if(i & 0x01)	//ENDP0_OUT
	{
		D12_COMMAND = 0x40; //读 OUT 最后状态
		cwait1;
		i= D12_DATA;
		csram;
		if (i & 0x20) //收到 SETUP 包
		{
			Setup_control();
		}
	}
	else if(i & 0x02) //ENDP0_IN
	{	
		D12_COMMAND = 0x41;//读 in 最后状态
		cwait1;
		i = D12_DATA;
		csram;
		USB_submit();
	}
	else if(i & 0x04)//ENDP1_OUT
	{	
		D12_COMMAND = 0x42;//读 out 最后状态
		cwait;
		i = D12_DATA;
		csram;
	    ReadEndpoint1(3,Rshu);
		
	}
	else if(i & 0x08)//ENDP1_IN
	{
		D12_COMMAND = 0x43;//读 in 最后状态
		cwait1;
		i = D12_DATA;
		cwait1;
		csram;
		D12_COMMAND = 3;// 选择 IN 端点(指针指向0位置)
		cwait;
		D12_COMMAND = 0xf0;// 写缓冲区
		cwait;
		D12_DATA = 0;
		csram;
//		WriteEndpoint1();
	
	}
	else if(i & 0x10)//ENDP2_out  对应管道2
	{
		D12_COMMAND = 0x44;//读 in 最后状态
		cwait1;
		i = D12_DATA;
		cwait1;
		D12_COMMAND = 4;// 选择 IN 端点(指针指向0位置)
		cwait;
		D12_COMMAND = 0xf0;// 读缓冲区
		cwait1;
		j=D12_DATA;
		cwait1;
		j=D12_DATA;  //数据字节的长度
		csram;
//		flashWrite(j);
	}
	else if(i & 0x20)//ENDP2_IN   对应管道3
	{
		D12_COMMAND = 0x45;//读 in 最后状态
		cwait1;
		i = D12_DATA;
		cwait1;
		D12_COMMAND = 5;// 选择 IN 端点(指针指向0位置)
		cwait;
		D12_COMMAND = 0xf0;// 写缓冲区
		cwait;
		D12_DATA = 0;
		csram;
		flashRead();
	}
	else if(i & 0x80)//D12_INT_SUSPENDCHANGE D12挂起
	{
		//if(D12_suspend)
		{
			  /** /
			  D12_suspend = 0;//处理挂起事务
			  D12_COMMAND = 0xf6;//发送恢复命令
			  D12_suspend = 1;//复位51输入引脚
			  /**/
		}
	}
	else if(i & 0x40)//D12_INT_BUSRESET 总线复位
	{
		bus_reset();
	}
	else
	{
		i=D12_DATA; //D12_INT_EOT DMA操作已结束
		if(i & 0x01)
		{
			dma_eot();
		}
	}
	
	SREG = 0x80;//全局中断使能
}

void bus_reset(void)
{
}

void dma_eot(void)
{
}

void ReadEndpoint1(unsigned int len,unsigned int * buf)
{
    unsigned int i,j,n;
	D12_COMMAND=2;
	D12_COMMAND=0xf0;
	j= D12_DATA;								
	j = D12_DATA;								
	if(j>len)
	 j=len;							
	for(i=0; i<j; i++)
		*(buf+i) = D12_DATA;
		if(Rshu[0]==0xa1 && Rshu[1]==0xa2 && Rshu[2]==0xa3)
		{
		
		adrstart=0xcc;
		}
		else if(Rshu[0]==0xb1 && Rshu[1]==0xb2 && Rshu[2]==0xb3)	
		{
		adrstop=0xee;
		//DDRD=0xfb;
		PORTD=0xdd;
		for(n=0;n<6;n++)
		cwait1;
		PORTD=0xdf;
		
		}
		else
		{
		D12_COMMAND=0xf2;
		}	
	
	D12_COMMAND=0xf2;
	
}	

							

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -