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

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

?? combi.c

?? 低成本USB轉PS/2接口的設計
?? 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一区二区三区免费野_久草精品视频
日韩电影在线观看电影| 日韩毛片高清在线播放| 久久久久国产精品厨房| 亚洲综合视频网| 国产99精品视频| 777午夜精品视频在线播放| 国产精品欧美经典| 一区二区三区在线观看欧美| 日本欧美肥老太交大片| 亚洲午夜激情av| 9色porny自拍视频一区二区| 欧美一卡二卡在线观看| 一区二区三区欧美亚洲| 国产不卡视频在线播放| 欧美一区二区在线播放| 一区二区三区四区五区视频在线观看 | 国产乱淫av一区二区三区| 欧美日韩久久久一区| 洋洋成人永久网站入口| 高清国产午夜精品久久久久久| 欧美日韩成人综合| 亚洲v精品v日韩v欧美v专区| 色94色欧美sute亚洲线路一久| wwwwww.欧美系列| 激情综合网激情| 日韩免费观看2025年上映的电影| 亚洲综合色视频| 在线看一区二区| 亚洲国产成人精品视频| 91视频免费观看| 亚洲精品国产无天堂网2021| 日本韩国欧美一区二区三区| 亚洲日本成人在线观看| 欧洲一区二区三区在线| 亚洲永久免费视频| 欧美日韩免费观看一区三区| 天天综合网天天综合色| 日韩三级av在线播放| 久久电影国产免费久久电影| 久久免费美女视频| 国产电影一区二区三区| 国产精品久久久久9999吃药| www.成人在线| 夜夜嗨av一区二区三区中文字幕| 欧美区一区二区三区| 日本亚洲三级在线| 久久精品欧美一区二区三区不卡| 国产一区不卡在线| 国产精品成人一区二区三区夜夜夜| 欧美中文字幕久久| 久久久久久影视| 日韩va欧美va亚洲va久久| 欧美午夜不卡在线观看免费| 国产视频在线观看一区二区三区| 一区二区三区欧美亚洲| 91久久国产最好的精华液| 午夜精彩视频在线观看不卡| 日韩免费视频线观看| 狠狠色狠狠色综合| 国产精品精品国产色婷婷| 欧美亚洲一区三区| 久久 天天综合| 国产精品久久久99| 欧美女孩性生活视频| 国产伦理精品不卡| 一区二区三区四区乱视频| 日韩一区二区在线观看视频播放| 成人一区二区三区视频| 视频一区二区三区入口| 国产欧美在线观看一区| 欧美精品在线一区二区三区| 国产jizzjizz一区二区| 午夜激情综合网| 亚洲欧洲精品一区二区三区| 日韩欧美一区在线| 色8久久精品久久久久久蜜| 久久er精品视频| 亚洲电影一区二区| 国产精品沙发午睡系列990531| 欧美日韩精品一区二区三区| 丰满白嫩尤物一区二区| 日韩视频一区二区在线观看| 亚洲国产欧美一区二区三区丁香婷| 一区二区三区**美女毛片| 亚洲第一在线综合网站| 欧美女孩性生活视频| 成人影视亚洲图片在线| 日韩一区精品视频| 最新欧美精品一区二区三区| 久久婷婷色综合| 欧美一区二区三区免费| 欧美视频一区在线观看| 99re免费视频精品全部| 91九色02白丝porn| 国产电影一区在线| 国内精品写真在线观看| 人妖欧美一区二区| 图片区小说区国产精品视频| 亚洲夂夂婷婷色拍ww47| 亚洲视频资源在线| 国产精品福利影院| 欧美性一区二区| 国产中文字幕精品| 欧美日韩小视频| 91浏览器在线视频| 成人app软件下载大全免费| 激情深爱一区二区| 老司机免费视频一区二区三区| 亚洲成av人片在www色猫咪| 亚洲精品中文在线| 夜夜爽夜夜爽精品视频| 亚洲韩国精品一区| 亚洲一区二区三区影院| 亚洲一区二三区| 午夜久久久久久电影| 亚洲成人在线网站| 丝袜美腿亚洲色图| 日本欧美在线看| 久久精品噜噜噜成人av农村| 久久成人综合网| 国产精品88888| 不卡视频一二三四| 91原创在线视频| 欧美视频一区二| 欧美一二区视频| 精品免费99久久| 欧美性淫爽ww久久久久无| 色婷婷综合激情| 狠狠色狠狠色综合系列| 国产又粗又猛又爽又黄91精品| 黑人巨大精品欧美黑白配亚洲| 久久成人麻豆午夜电影| 国产成人综合亚洲91猫咪| www.亚洲在线| 精品视频1区2区| 欧美xfplay| 欧美激情在线免费观看| 亚洲精品老司机| 日韩成人av影视| 国产成人免费高清| 91官网在线观看| 日韩欧美在线一区二区三区| 国产精品―色哟哟| 亚洲成在线观看| 国产激情视频一区二区三区欧美| 91在线视频网址| 欧美一区二区三区精品| 久久久久国产一区二区三区四区| 自拍偷自拍亚洲精品播放| 奇米影视在线99精品| 高清不卡一区二区| 欧美精品在线观看一区二区| 精品国产人成亚洲区| 日韩亚洲欧美综合| 午夜免费欧美电影| 日韩一区二区三区四区| 国产午夜精品理论片a级大结局| 一区二区三区小说| 欧美日韩国产123区| 亚洲精品一区二区三区精华液| 亚洲欧美aⅴ...| 国产一区二区在线视频| 欧美日韩中文国产| 国产精品福利影院| 国产麻豆视频精品| 欧美夫妻性生活| 亚洲精品中文字幕在线观看| 国产精品一区二区久久精品爱涩 | 日韩电影网1区2区| av网站免费线看精品| 精品国产乱码久久久久久蜜臀| 尤物在线观看一区| 成人精品视频一区| 久久久www成人免费无遮挡大片| 亚洲成人一区二区在线观看| av日韩在线网站| 日本一区二区三级电影在线观看| 免费久久99精品国产| 91成人国产精品| 亚洲免费在线看| av在线这里只有精品| 久久九九99视频| 精品一区二区成人精品| 欧美色倩网站大全免费| 亚洲精品视频观看| 91免费看`日韩一区二区| 国产欧美日韩激情| 国产精品亚洲专一区二区三区 | 中文字幕的久久| 韩国欧美国产1区| 欧美tickle裸体挠脚心vk| 日韩va亚洲va欧美va久久| 欧美精品在线观看一区二区| 午夜国产不卡在线观看视频| 在线观看区一区二| 午夜视频在线观看一区二区三区| 欧亚洲嫩模精品一区三区| 亚洲狠狠丁香婷婷综合久久久| 91蝌蚪porny| 亚洲女人小视频在线观看|