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

📄 kbmousetest.c

📁 有关于USB的一些主机端驱动
💻 C
字号:


unsigned char * cmd_s_port =  (unsigned char*)0x08000064;
unsigned char * dat_port = (unsigned char*)0x08000060;



//------------------------------------------------------------------------------------
void KBmouseTest(void)
{

 int i;
 unsigned char xxx=0,state=0;
 unsigned short  st, *zzz;
 
 unsigned char *yyy;
 yyy=(unsigned char*)0x08000004;
 
     
     *(yyy)=0xFF;
     *(yyy)=0xFF;

     *((unsigned long *)0x08000060) = 0x00fffa;
     *((unsigned long *)0x08000064)  = 0x0ff10;
//  test self_test
     
	  *cmd_s_port=0xAA;
	  
	 for(i=0;i<10000;i++); 
	 
	
	 state= *cmd_s_port;
	 
	 xxx=*dat_port;
	 
	 state=*cmd_s_port;
	 
   //write keyboard command byte
   
   	  *cmd_s_port=0x60;
   	  
   	  for(i=0;i<10000;i++);
   	  
   	  *dat_port=0x47;
   	  
	 for(i=0;i<10000;i++); 
	 
	 state= *cmd_s_port;
	 
	
	 //read keyboard command byte
    
     
      for(i=0;i<10000;i++);
      
	 *cmd_s_port=0x20;
	 for(i=0;i<10000;i++);
	 
	 state=*cmd_s_port; 
	  
	 xxx=*dat_port; 
	 
	 state=*cmd_s_port; 
	 
    for(i=0;i<10000;i++);
    
    //test kb, send data to kb
    
    //initial kb
    
    //enable kb
    test0:
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test0;
    else
      *cmd_s_port=0xAE;
      
      
    test1:
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test1;
    else
       *dat_port=0xFF;
       
     test2:
     state=*cmd_s_port;
     state &=0x01;  
       if (state!=0x01)
          goto test2;
       else 
          xxx=0; 
          xxx=*dat_port;    //xxx=0xfa correct
    
      test3:
     state=*cmd_s_port;
     state &=0x01;  
       if (state!=0x01)
          goto test3;
       else  
          xxx=0;
          xxx=*dat_port;    //xxx=0xaa correct
          
          
    //start kb      
    test4:
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test4;
    else
      *dat_port=0xF4;
      
    test5:
     state=*cmd_s_port;
     state &=0x01;  
       if (state!=0x01)
          goto test5;
       else 
          xxx=0; 
          xxx=*dat_port;   //xxx=0xfa correct
       
    
    //test kb led
    test6:
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test6;
    else
      *dat_port=0xED;  
      
    test7:
    state=*cmd_s_port;
    state &=0x01;  
       if (state!=0x01)
          goto test7;
       else 
          xxx=0; 
          xxx=*dat_port;   //xxx=0xfa correct
         
    test8:
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test8;
    else
      *dat_port=0x07;
      
    test9:
    state=*cmd_s_port;
    state &=0x01;  
       if (state!=0x01)
          goto test9;
       else 
          xxx=0; 
          xxx=*dat_port;   //xxx=0xfa correct
      
//reset enable start mouse controller      
    test13: 
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test13;
    else
      *cmd_s_port=0xA9; 

      test14:    
     state=*cmd_s_port;
     state &=0x01;  
       if (state!=0x01)
          goto test14;
       else 
          xxx=0; 
          xxx=*dat_port;    //xxx=0x00 correct  
      
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        //enable mouse
    //enable mouse
 test10:   
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test10;
    else
      *cmd_s_port=0xA8;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                             
    //reset  mouse
   test35: 
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test35;
    else
       *cmd_s_port=0xD4;
     
    test19:
 
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test19;
    else
       *dat_port=0xFF; 
       
       
     test29:
     state=*cmd_s_port;
     state &=0x20;  
       if (state!=0x20)
          goto test29;
       else 
          xxx=0; 
          xxx=*dat_port;    //xxx=0xfa correct  

     test39:
      
     state=*cmd_s_port;
     state &=0x20;  
       if (state!=0x20)
          goto test39;
       else  
          xxx=0;
          xxx=*dat_port;    //xxx=0xaa correct
           
          
    //start mouse      
    test36:
    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test36;
    else
       *cmd_s_port=0xD4;               
    test49:

    state=*cmd_s_port;
    state &=0x02;  
    if (state==0x02)
       goto test49;
    else
      *dat_port=0xF4;
 for( i=0;i<100;i++)     ;
    test59:
    
   
     state=*cmd_s_port;
     state &=0x20;  
       if (state!=0x20)
          goto test59;
       else 
          xxx=0; 
          xxx=*dat_port;   //xxx=0x00 correct  ????????????     
      
      
      
              
 yyy=(unsigned char*)0x08000000;
  *(yyy)=0x00;  
     
        
 yyy=(unsigned char*)0x08000000;
     *(yyy)=0x00;          
            
   
    //test cpu receive data from kb
 i = 0;
 printf("Pls press any key on keyboard some times or move mouse & press button\n");
 printf("data_port = 0x%x \n",xxx);
 printf("data_port = 0x%x \n",xxx);
 printf("data_port = 0x%x \n",xxx);
 while(i < 30)
  {  
    state=*cmd_s_port;
    if (state == 0x15 || state == 0x35) {
        xxx=*dat_port;
        printf("data_port = 0x%x \n",xxx);
        yyy=(unsigned char*)0x08000000;
       *(yyy)=0x00;
        i++;
    }//if(state ==
 }//while(i < 100 )

  
  return ;
}


⌨️ 快捷键说明

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