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

📄 fw.c

📁 单片机读写优盘
💻 C
字号:
//************************************************************************
//author:dragon
//web:8dragon.com
//2004.2.5完成于桃龙源
//*************************************************************************
#include "AT89X52.H"
#include "fw.h"
#include "host_811.H"
#include "ufi.h"
#include "file.h"
#include "api.h"
extern Control bdata USB_Control;
BYTE UsbEvent;
void Init_Port()
{
	P0 = 0xFF;
	P1 = 0xFF;
	P2 = 0xFF;
	P3 = 0xFF;
}
void Init_Interrupt(void)
{
	IT0 = 0;
	EX0 = 1;
}
BYTE Demo(void)
{
//	MCU_LED4=0;
	    if(P3_4==0)
		{
		
			DelayMs(30);
			if(P3_4==0)
			{
				if(!CreateFile("demo.txt",0x20))
				   return;
			MCU_LED4=1;
			}
		}	
			
}
main()
{
	BYTE i;
	//BYTE Buf[0x100],buf1[50];
	Init_Port();
//	Init_COMM();
//	MCU_LED0=0;
//	DelayMs(6000);
//	MCU_LED0=1;
//	P1_2=0;
//	P1_2=1;
//	nRest=0;
	DelayMs(6);
	nRest=1;
	Init_Interrupt();
	ENABLE_INTERRUPTS;
/*	for(i=0;i<100;i++)
	{
		Buf[i]=i;
	}
	SL811BufWrite(16,Buf,100);	
	SL811BufRead(16,buf1,50);*/
	sl811h_init();
	UsbEvent=TRUE;	
	while(TRUE)
	{
		if(UsbEvent)
		{
			UsbEvent=FALSE;
			SL811Write(IntStatus,0XFF);
			i=SL811Read(IntStatus);    
			if((USB_RESET&i))
			{	
				if(USB_Control.SLAVE_ONLINE ==TRUE)
				{
					USB_Control.SLAVE_REMOVED=TRUE;
					USB_Control.SLAVE_ONLINE =FALSE;
				}
			}
			else	
			{  
				if(USB_Control.SLAVE_ONLINE == FALSE&&(i|0x7F))
				{	 
					USB_Control.SLAVE_FOUND=TRUE;
	   				USB_Control.SLAVE_ONLINE =TRUE;
				}
			}
			if(USB_Control.SLAVE_FOUND)
			{	
				DISABLE_INTERRUPTS;
				USB_Control.SLAVE_FOUND=FALSE;
		//		for(i=0;i<5;i++)
		//		DelayMs(250);
				if(EnumUsbDev(1))							// enumerate USB device, assign USB address = #1
					USB_Control.SLAVE_ENUMERATED = TRUE;	// Set slave USB device enumerated flag		
				ENABLE_INTERRUPTS;
			}		
			if(USB_Control.SLAVE_REMOVED)

			{
				DISABLE_INTERRUPTS;
				USB_Control.SLAVE_REMOVED=FALSE;
				USB_Control.SLAVE_ENUMERATED = FALSE;
				ENABLE_INTERRUPTS;
			}
			if(USB_Control.bMassDevice)
			{
				DISABLE_INTERRUPTS;
				USB_Control.bMassDevice=FALSE;
				ApiDemo();
				MCU_LED4=0;	
				ENABLE_INTERRUPTS;
			}
		}//end if 
	   Demo();	
	   MCU_LED1=~MCU_LED1;
	   DelayMs(200);
	}//end for while	

}//end main
//************************************************************************
//author:dragon
//web:8dragon.com
//2004.2.5完成于桃龙源
//*************************************************************************

⌨️ 快捷键说明

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