亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? combi.c

?? USB接口鼠標電路以及程序設計
?? C
?? 第 1 頁 / 共 5 頁
字號:
void ResetScaling(void);
char GetByte ( void);
void ProcessCommand(char p);
void SendMouseData(void);
void Put(char p);
void PutMsgBuff(void);
void SendMouseData(void);
void ps2main(void);
void PutNextByte(void);
void ReInitialize(void);
void ResetInterval(void);
void Ps2MouseTask(void);


/*
**
** FUNCTION:		ClearRam
**
** PURPOSE:			Clears all RAM except data and program stacks.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		Written in assembler so that only X and A are used ( no variables
**					that might be cleared as a result of this function executing)
**
*/

void ClearRam(void)
{
    #asm 
    mov     X,REGISTER_SIZE - 1
    mov     A,0
lp:
    mov     [X + REGISTER_START],A
    dec     X
    jnc     lp
    #endasm
    return;
    }


/*
**
** FUNCTION:		IsUsbInterface
**
** PURPOSE:			Determines whether a USB or PS/2 host is connected upstream.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		This function performs the following algorithm:

					1) Wake up and delay 50mS. Initialize the PS2 BAT delay counter.

					2) For a period of 2mS, poll the SCLK and SDATA lines every 10uS.
					   If we get 4 samples in a row with non-zero data on either line, 
					   detect PS2. If the 2mS expires, go to (3).

					3) Enable USB pull up resistor and delay 500uS. 
					   Poll the SCLK and SDATA lines indefinitely 
					   until a non-zero condition exists on either line. 
					   During this polling period, we begin to count down the PS2 BAT delay.  
					   If SCLK(D+) is sampled high, detect PS2. If SDATA(D-) 
					   is sampled high, go to (4).

					4) Disable the USB connect resistor and Delay 100uS.  
						if D+ and D- are both 0, detect  USB, else detect PS2.
*/

char 	IsUsbInterface(void)
{

	char temp;
	char samples = 4;
     bBatDelay = (500 - 50);								//initialize BAT delay to 500 msec
	temp = MsecStatus.b1msCounter+50;					    //wait 50 msec
  														    
	while (temp != MsecStatus.b1msCounter)
		RESET_COP();
	temp = MsecStatus.b1msCounter+2;
	while (temp != MsecStatus.b1msCounter)					//for 2 msec, sample clock and data
	{
		if ((PORT2 & (PS2_CLOCK_BIT | PS2_DATA_BIT)) && (!--samples))
				return(0);									//4  consecutive samples of either clock or data high, it's ps2
		samples = 4;					
	}

	USB_STATUS = (VREG_ENABLE_MASK | FORCE_NEG_OPEN_POS_OPEN);//enable USB pullup 
	Delay(250);												//and delay 250 usec
	while (1)												//wait forever
	{
		RESET_COP();
		if (MsecStatus.b1msFlags & ONE_MSEC_FLAG)
		{
			if (bBatDelay)									//if a msec expires, decrease bat delay
				bBatDelay--;
			MsecStatus.b1msFlags &= ~ONE_MSEC_FLAG;
		}
		if (PORT2 & PS2_CLOCK_BIT)							
			return(0);										//clock bit high it's ps2
		if (PORT2 & PS2_DATA_BIT)							//data bit high, quit the loop
			break;
	}
	USB_STATUS = FORCE_NEG_OPEN_POS_OPEN;					//disable USB pullup 
    Delay(100);  
	return(!(PORT2 & (PS2_CLOCK_BIT | PS2_DATA_BIT)));		//if both clock and data go low, it's usb
}


/*
**
** FUNCTION:		MY_RESET_ISR
**
** PURPOSE:			Reset ISR, vectored to during power-up or watchdog reset.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		This function performs the following initialization:
**					
**					1)disables interrupts;
**					2)resets the watchdog;
**					3)initializes data stack pointer;
**					4)clears ram;
**					5)initializes port I/O;
*					6)enables 1msec interrupt;
**					7)jumps to main loop
**					
**
*/

void MY_RESET_ISR(void)
{
    DI();											//disable ints
	RESET_COP();									//reset watchdog

	/*
	** use assembler to initialize data stack
	*/
#asm (mov A,RAM_START + STACK_SIZE-1)			        
#asm (swap A,dsp)
      ClearRam();
	USB_STATUS = FORCE_NEG_OPEN_POS_OPEN;						//drive D+,D- to Hi-Z
	PORT0_MODE1 = PORT0_MODE1_INIT;								//set up port modes
	PORT0_MODE0 = PORT0_MODE0_INIT;								//
	PORT1_MODE0 = PORT1_MODE0_INIT ;							//
	PORT1_MODE1 = PORT1_MODE1_INIT;								//
	PORT0 = PORT0_INIT;											//set up initial values
	PORT1 = PORT1_INIT;											//
	PORT0IE = PORT0_INIT;										//set up for GPIO interrupts on switch inputs
	PORT1IE = PORT1_INIT;										//
	PORT0IP = ~PORT0_INIT;										//set up for negative edges interrupts switch inputs
	PORT1IP = ~PORT1_INIT;
	GLOBAL_INTERRUPT = MILLISECOND_ENABLE; 						//enable all pertinent interrupts
	EI();
    #asm (jmp main)
 }


/*
**
** FUNCTION:		main
**
** PURPOSE:			determines interface (usb or ps2) and dispatches to appropriate code.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		
**					
**
*/

 void main(void)
 {
    if (IsUsbInterface())								//if it is USB
    {
          UsbReInitialize();							//initialize USB variables
          usbmain();									//and go to usbmain
	}
	ps2main();											//else straight to ps2
}


/*
**
** FUNCTION:		ProcessOptics
**
** PURPOSE:			Extracts optics data from the queue, and accumulates X,Y, and Z counts
**					based on the state data of each quadrature pair.
** PARAMETERS:		none
**
** DESCRIPTION:		This routine is called from the main loop to process the optical data that has
**					accumulated during successive 128 usec interrupts. For each byte in the optics queue,
**					it extracts the X,Y,and Z state data, and uses the state data from the previous sample
**					to increment/decrement/hold the corresponding count data.	
**					
**
*/

void ProcessOptics(void)
{   
	char temp;
    char temp1;
      if (OpticsQueue.bLen > 16)								//somehow the queue overflowed
      {
		  DI();													//this should never happen, but if so
		  OpticsQueue.headP =									//reset the queue pointers and quit
		  OpticsQueue.tailP = bOpticsArray;
		  OpticsQueue.bLen = 0;
		  EI();
		  return;
      }
	while (OpticsQueue.bLen)
	{
		temp = GET_X_OPTICS(*OpticsQueue.tailP);				//get X quadrature inputs into [1:0]
		temp1 = temp;											//save temporarily
		temp |= Optics.bXstate;									//or in with previous state 
		Optics.bXstate = temp1 << 2;							//shift X inputs into [3:2] and save for next pass
		temp1 = Mouse.bXcount;
		Mouse.bXcount += quad_table[temp];						//use quadrature lookup to inc/dec xcount
		if ((unsigned char) Mouse.bXcount == 0x80)								//if overflow in either direction
			Mouse.bXcount = temp1;								//restore old count
																
		temp = GET_Y_OPTICS(*OpticsQueue.tailP);				//repeat for Y.....
		temp1 = temp;
		temp |= Optics.bYstate;
		Optics.bYstate = temp1 << 2;
		temp1 = Mouse.bYcount;
		Mouse.bYcount -= quad_table[temp];						//note, y counts need to be negated for proper direction
		if ((unsigned char) Mouse.bYcount == 0x80)
			Mouse.bYcount = temp1;

		temp = GET_Z_OPTICS(*OpticsQueue.tailP);				//repeat for Z....
		temp1 = temp;
		temp |= Optics.bZstate;
		Optics.bZstate = temp1 << 2;
		temp1 = Mouse.bZcount;
		Mouse.bZcount += z_quad_table[temp];
		if ((unsigned char) Mouse.bZcount == 0x80)
			Mouse.bZcount = temp1;

		*OpticsQueue.tailP++;									//manage queue pointers
 		if (OpticsQueue.tailP == &bOpticsArray[16])				//wrap them if necessary
			OpticsQueue.tailP = bOpticsArray;
		OpticsQueue.bLen--;
	}
}


/*
**
** FUNCTION:		MICROSECONDx128_ISR
**
** PURPOSE:			128 usec ISR.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		
**					This ISR samples the mouse optics and places the sample in a queue for
**					later processing by the main loop. This is done to minimize the execution time
**					of this ISR, which can interrupt during the time ps/2 bits are being clocked
**					to the host.  The timing of the ps/2 clocking is critical (20 us margin),
**					so the corresponding execution time of this ISR must be kept to less than 20 us.
**					
**
*/

void MICROSECONDx128_ISR(void)
{
	PUSHA();
	PUSHX();
	*OpticsQueue.headP++ = OPTICS_PORT;							//sample optical data
	OpticsQueue.bLen++;											//manage queue pointers and length
	if (OpticsQueue.headP == &bOpticsArray[16])					//wrap pointers if necessary
		OpticsQueue.headP = bOpticsArray;
	POPX();
	POPA();
}


/*
**
** FUNCTION:		MILLISECOND_ISR
**
** PURPOSE:			1 msec ISR.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		
**					This ISR maintains the 1msec counter variable,
**					and sets a flag indicating a 1msec interrupt has occurred. The main loop uses
**					these variables for timing purposes.
*/

void MILLISECOND_ISR(void)
{
    PUSHA();										//save A
    RESET_COP();
	MsecStatus.b1msFlags |= ONE_MSEC_FLAG;			//set flag for main loop
	MsecStatus.b1msCounter++;					    //increment 1msec counter
    POPA();
	return;
}


/*
**
** FUNCTION:		DebounceButtons
**
** PURPOSE:			Debounces the mouse switch inputs  
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					This routine should be called at regular intervals from the main loop
**					to debounce the mouse switch inputs.  It maintains a count of the number
**					of successive identical samples of the switch inputs, and returns a 1
**					if the switch inputs have changed have been stable for the debounce interval.
*/

char GetButtons(void)
{
	char bButtons = 0;


	if (LEFT_SWITCH_ASSERTED)						//format an internal copy of the switches
		bButtons |= BIT0;							//this happens to be the USB format!
	if (RIGHT_SWITCH_ASSERTED)
		bButtons |= BIT1;
	/*
	** if Zwheel is enabled in either USB or PS2 mode, report the middle switch
	*/
	if ((MouseParms.bZmouse || DeviceStatus.bProtocol) && (MIDDLE_SWITCH_ASSERTED))
		bButtons |= BIT2;
	return(bButtons);
}

char DebounceButtons(void)
{
    char bButtons;
	bButtons = GetButtons();
 	if (bButtons == bLastButtons)				    //if same as last sample
	{
		  if (bDebounceCount && !--bDebounceCount)  //and debounce interval just expired
		  {
			  Mouse.bButtons = bLastButtons;			//record new buttons
			  return(1);							//and flag that a button change occurred
		  }
		  return(0);								//else no change yet occurred
	}
	bLastButtons = bButtons;						//buttons aren't stable, reset debounce count
	bDebounceCount = DEBOUNCE_COUNT;				//
	return(0);
}


/*
**
** FUNCTION:		USB_BUS_RESET_ISR
**
** PURPOSE:			Bus Reset ISR, vectored to during USB bus reset.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		This function performs the following initialization:
**					
**					1)disables interrupts;
**					2)resets the watchdog;
**					3)initialized data stack pointer and program stack pointer;
**					4 clears ram;
**					5)makes a call to initialize system variables;
**					6)enables device to respond at address 0;
**					7)jumps to main loop
**					
**
*/

void USB_BUS_RESET_ISR(void)
{

    DI();
	RESET_COP();						//tickle watchdog
										//initialize stacks using assembler
#asm (mov A,RAM_START + STACK_SIZE-1)			        
#asm (swap A,dsp)
#asm (mov A,0)
#asm (mov psp,a)
	ClearRam();
	UsbReInitialize();						//reinitialize all system variables

	USB_DEVICE_A = 0x80;  // enable endpoint zero response at address 0
	EP_A0_MODE = USB_MODE_STALL_IN_OUT;
										//and make the leap to the main loop
#asm(jmp usbmain)							
}


/*
**
** FUNCTION:		WAKEUP_ISR
**
** PURPOSE:			ISR for wakeup interrupt.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		The wakeup ISR increments a global counter which is used to "tune" the
**					frequency of the occurrence of the ISR itself (See routine TuneWakeup).
**
*/

void WAKEUP_ISR(void)
{
	bWakeupCount++;
}


/*
**
** FUNCTION:		GPIO_ISR
**
** PURPOSE:			ISR for wakeup interrupt. does nothing except returns  
**
** PARAMETERS:		none
**
** DESCRIPTION:	
**
*/

void GPIO_ISR(void)
{
	
}


/*
**
** FUNCTION:		USB_A_EP0_ISR
**
** PURPOSE:			Endpoint 0 Interrupt Service Routine.  
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					this routine is entered upon receiving an endpoint 0 interrupt.
**					EP0 interrupts occur during the Setup, data , and status phases of a
**					setup transaction.  This ISR dispatches the proper routine to handle
**					one of these phases. The interrupt will remain active until the
**					phase in question is completely handled.
*/

void USB_A_EP0_ISR(void)
{
	PUSHA();												//save A and X,they'll get wasted
	PUSHX();
	if (EP_A0_MODE & (1 << ACKNOWLEDGE))					//if this packet was acknowledged,
	{
		if (EP_A0_MODE & SETUP_RECEIVED_MASK)				//if a setup was received,
		{
			DeviceStatus.bAddress &= ~0x80;					//clear the address flag
			HandleSetup();									//and handle it

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区二区在线观看视频| 91日韩精品一区| 亚洲成av人片在线| 亚洲色图色小说| 亚洲乱码一区二区三区在线观看| 中文一区二区在线观看| 久久久精品中文字幕麻豆发布| 欧美白人最猛性xxxxx69交| 欧美一级爆毛片| 精品欧美久久久| 中文字幕 久热精品 视频在线 | 欧美少妇xxx| 欧美私模裸体表演在线观看| 欧美亚洲精品一区| 欧美久久久久久久久| 日韩欧美在线网站| 久久久久久久久97黄色工厂| 国产精品视频一区二区三区不卡| ...xxx性欧美| 亚洲午夜免费福利视频| 首页亚洲欧美制服丝腿| 美女视频网站黄色亚洲| 国产成人在线电影| 日本韩国欧美一区二区三区| 欧美日韩国产高清一区| 日韩一卡二卡三卡国产欧美| 久久久美女毛片| 自拍av一区二区三区| 天堂蜜桃一区二区三区| 国内久久精品视频| 99这里只有精品| 日韩精品一区在线观看| 中文字幕一区免费在线观看| 亚洲.国产.中文慕字在线| 国产精品888| a级精品国产片在线观看| 欧美日韩一区二区三区不卡| 久久综合色鬼综合色| 亚洲欧美一区二区在线观看| 日韩在线一区二区| 成人国产亚洲欧美成人综合网| 欧美色网一区二区| 国产性天天综合网| 婷婷国产v国产偷v亚洲高清| 成人免费视频视频| 91精品国产综合久久国产大片| 欧美国产禁国产网站cc| 日韩二区三区在线观看| av欧美精品.com| 久久麻豆一区二区| 亚洲第一主播视频| www.日韩av| 欧美成人激情免费网| 亚洲激情图片小说视频| 国产乱码精品一区二区三区五月婷| 色偷偷久久一区二区三区| 国产亚洲精久久久久久| 蜜芽一区二区三区| 欧美视频一区二区三区四区 | 国产精品2024| 欧美精品一卡二卡| 亚洲卡通动漫在线| 99久久久国产精品免费蜜臀| 久久夜色精品国产欧美乱极品| 日韩一区精品视频| 欧美中文字幕一区二区三区亚洲| 中文字幕国产一区二区| 国产麻豆视频一区| 久久夜色精品一区| 国产一区二区剧情av在线| 日韩精品中文字幕一区| 蜜桃视频一区二区| 欧美一级国产精品| 毛片不卡一区二区| 日韩精品综合一本久道在线视频| 婷婷中文字幕一区三区| 欧美群妇大交群的观看方式| 午夜日韩在线电影| 欧美日韩www| 青椒成人免费视频| 日韩欧美在线综合网| 精品一区二区三区免费观看| 日韩三级视频在线观看| 久久国产精品72免费观看| 日韩一二在线观看| 国产一区二三区| 国产精品无码永久免费888| 高清不卡在线观看| 中文字幕制服丝袜一区二区三区 | 亚洲综合免费观看高清完整版在线 | 亚洲第一激情av| 欧美日本韩国一区二区三区视频| 亚洲丶国产丶欧美一区二区三区| 久久影音资源网| 国产成人免费在线观看不卡| 中文字幕av资源一区| 97精品国产露脸对白| 亚洲电影一区二区三区| 欧美一区二区精品久久911| 国产在线播放一区| 亚洲三级电影全部在线观看高清| 在线观看一区不卡| 久色婷婷小香蕉久久| 中文字幕av一区 二区| 在线一区二区三区四区| 男男成人高潮片免费网站| 26uuu色噜噜精品一区二区| av电影一区二区| 免费在线看一区| 国产精品电影院| 欧美一区二区三区小说| 国产精品一二一区| 亚洲国产精品久久艾草纯爱 | 国产精品1区2区| 亚洲成人一区二区在线观看| 精品日本一线二线三线不卡| 一本高清dvd不卡在线观看| 免费成人结看片| 一区二区三区四区精品在线视频| 欧美成人激情免费网| 色94色欧美sute亚洲线路二| 国产在线国偷精品产拍免费yy| 亚洲影院免费观看| 国产日产精品一区| 日韩欧美美女一区二区三区| 91理论电影在线观看| 国产在线精品一区二区三区不卡| 洋洋成人永久网站入口| 国产亲近乱来精品视频| 欧美一激情一区二区三区| 一本到三区不卡视频| 国产一区视频导航| 日韩主播视频在线| 亚洲国产日韩精品| 亚洲色欲色欲www在线观看| 久久久亚洲综合| 精品久久人人做人人爽| 7777精品久久久大香线蕉 | 日韩黄色一级片| 亚洲综合久久久久| 亚洲欧美成人一区二区三区| 国产女人水真多18毛片18精品视频| 欧美顶级少妇做爰| 欧美亚洲一区二区在线| 色婷婷国产精品| 色欧美乱欧美15图片| 成人高清视频在线| 成人久久18免费网站麻豆 | 99国内精品久久| 99re视频精品| 91丝袜美腿高跟国产极品老师| 国产99久久精品| 成人一区二区三区中文字幕| 国产精品77777| 国产福利一区二区三区| 粉嫩av一区二区三区| 成人综合在线视频| 不卡一区二区中文字幕| 成人av电影免费在线播放| 99在线精品免费| 欧美在线999| 91精品国产乱码| 精品国产凹凸成av人导航| 精品国产区一区| 中文字幕乱码日本亚洲一区二区| 中文字幕乱码日本亚洲一区二区| 中文字幕字幕中文在线中不卡视频| 国产精品电影院| 亚洲v精品v日韩v欧美v专区| 日韩国产成人精品| 国产麻豆91精品| av电影在线观看不卡| 欧美日韩在线播放一区| 欧美videofree性高清杂交| 国产免费久久精品| 亚洲精品久久嫩草网站秘色| 午夜精品久久一牛影视| 国产一区二区三区香蕉 | 欧美日韩在线一区二区| 欧美电影免费观看完整版| 国产视频一区二区在线| 最新久久zyz资源站| 午夜激情综合网| 岛国av在线一区| 欧美区在线观看| 日本一区二区三区久久久久久久久不 | 日本三级亚洲精品| 国产精品一品二品| 欧美三级日本三级少妇99| 精品福利在线导航| 亚洲精品国产精品乱码不99| 久久av中文字幕片| 色婷婷综合激情| 久久奇米777| 天天av天天翘天天综合网色鬼国产 | 欧美伊人久久大香线蕉综合69 | 国产一区不卡精品| 色欧美乱欧美15图片| 久久久久88色偷偷免费| 午夜免费欧美电影|