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

📄 d12_comm_if.c

📁 Six objects here: The document you re reading & its Chinese version Set of "HWDesign" includes
💻 C
字号:
#include <reg51.h>	//SFR declarations

#include "base_io.h"
#include "d12_comm_if.h"
#include "mainloop.h"
#include "base_io.h"

extern EPPFLAGS bEPPflags;

void D12_SetAddrEN(unsigned char bAddr,unsigned char bEnable)
{
	outportb(D12_Command,0xD0);
	if (bEnable)
		bAddr|=0x80;
	outportb(D12_Data,bAddr);
}

void D12_SetEndPEN(unsigned char bEnable)
{
	outportb(D12_Command,0xD8);
	if (bEnable)
		outportb(D12_Data,1);
		else
			outportb(D12_Data,0);
}

void D12_SetMode(unsigned char bConfig,unsigned char bClkDiv)
{
	outportb(D12_Command,0xF3);
	outportb(D12_Data,bConfig);
	outportb(D12_Data,bClkDiv);
}

unsigned short D12_ReadIntReg(void)
{
	unsigned char tmpLow;
	unsigned int tmpHigh;

	outportb(D12_Command,0xF4);
	tmpLow=inportb(D12_Data);
	tmpHigh=inportb(D12_Data);

	tmpHigh<<=8;
	tmpHigh+=tmpLow;
	return tmpHigh;
}

unsigned char D12_SelectEndP(unsigned char bEndp)
{
	outportb(D12_Command,bEndp);
	return inportb(D12_Data);
}

unsigned char D12_ReadLastTransStatus(unsigned char bEndp)
{
	outportb(D12_Command,0x40+bEndp);
	return inportb(D12_Data);
}

void D12_SetEndPStatus(unsigned char bEndp,unsigned char bStalled)
{
	outportb(D12_Command,0x40+bEndp);
	outportb(D12_Data,bStalled);
}

void D12_SendResume(void)
{
	outportb(D12_Command,0xF6);
}

unsigned char D12_ReadEndP(unsigned char endp,unsigned char len,unsigned char *buf)
{
	unsigned char tmpi,tmpj;

	outportb(D12_Command,endp);	//select EndPoint,read its buf status
	if (inportb(D12_Data)&D12_FULLEMPTY==0)	//buf empty
		return 0;

	outportb(D12_Command,0x80+endp);	//read EndP status
	tmpi=inportb(D12_Data);
	tmpi&=D12_BUFFULL;

	if (endp==2)
	{
		if (tmpi==D12_BUFFULL)
			bEPPflags.bits.ep1buf_full=1;	//buffer of EP1 full
			else
				bEPPflags.bits.ep1buf_full=0;
	}

	if (endp==4)
	{
		if (tmpi==D12_BUFFULL)
			bEPPflags.bits.ep2buf_full=1;	//buffer of EP2 full
			else
				bEPPflags.bits.ep2buf_full=0;
	}

	outportb(D12_Command,0xF0);
	inportb(D12_Data);	//According to the format of BUF,the first Byte is reserved.
	tmpj=inportb(D12_Data);	//The second one is the length of the follow.

	if (tmpj>len)
		tmpj=len;
	for (tmpi=0;tmpi<tmpj;tmpi++)
		*(buf+tmpi)=inportb(D12_Data);
	outportb(D12_Command,0xF2);	//clean up buf

	return tmpj;
}

unsigned char D12_WriteEndP(unsigned char endp,unsigned char len,unsigned char *buf)
{
	unsigned char tmpi;
	outportb(D12_Command,endp);	//select EndPoint
	inportb(D12_Data);	//??What does this line mean??

	outportb(D12_Command,0xF0);
	outportb(D12_Data,0);
	outportb(D12_Data,len);

	for (tmpi=0;tmpi<len;tmpi++)
		outportb(D12_Data,*(buf+tmpi));
	outportb(D12_Command,0xFA);	//enable the buf,and waiting for IN
	return len;
}

void D12_AckEndP(unsigned char endp)
{
	outportb(D12_Command,endp);
	outportb(D12_Command,0xF1);

	if (endp==0)
		outportb(D12_Command,0xF2);
}

unsigned short D12_ReadChipID(void)
{
	unsigned short tmpi,tmpj;

	if(bEPPflags.bits.in_isr == 0)
		DISABLE;

	outportb(D12_Command, 0xFD);
	tmpi=inportb(D12_Data);
	tmpj=inportb(D12_Data);
	tmpi += (tmpj<<8);

	if(bEPPflags.bits.in_isr == 0)
		ENABLE;

	return tmpi;
}

⌨️ 快捷键说明

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