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

📄 test02.lst

📁 ps2 to ubs bridge sourc for 8051e code
💻 LST
📖 第 1 页 / 共 5 页
字号:
 197   1       
 198   1        // flash KeyBoard LED ON and then OFF
 199   1        //
 200   1        KB_SET_ONE(KB_LED_OOC, 0xff);
 201   1        wait100us();
 202   1        wait100us();
 203   1        wait100us();
 204   1        KB_SET_ONE(KB_LED_OOC, 0x00);
 205   1        
 206   1        // start recieving data report
 207   1        // enable ps2a module, set ps2en, rx_ie
 208   1        // enable INT7 interrupt (PS2)
 209   1        PS2A_STA = 0xFF;
 210   1        PS2A_CTL = 0x36;
 211   1        
 212   1        PS2B_STA = 0xFF;
 213   1        PS2B_CTL = 0x36;
 214   1        
 215   1        rx_ms_bcnt=0;
 216   1        
 217   1        EX7 = 1; 
 218   1        
 219   1        configured=0;
 220   1      
 221   1        
 222   1        //
 223   1        // setup timer 3 for 1ms interrupt to check for kb buffer status
 224   1        //
 225   1        
 226   1        TIM_SEL = 0x03;       //select timer 3
 227   1        TIM_CTL = 0x48;       //enable tie, xtal/16, stop, timer mode
 228   1        TIM_PRE = 74;         //(12M/16)/75/10=1ms
 229   1        TIMER   = 9;
 230   1        TIM_SEL = 0x83;       //enable
 231   1        TIM_CTL = 0x40;       //run
 232   1        
 233   1        ET0 = 1;
 234   1        
 235   1       
 236   1        // enable usb module, set usben & pull_en
 237   1        USB_CTL0 = 0x90;
 238   1        EX5 = 1;
 239   1        USB_CTL4 = 0x40; // reset
 240   1        
 241   1        restart: while(configured==0);
C51 COMPILER V7.07   TEST02                                                                01/26/2007 14:58:49 PAGE 5   

 242   1        
 243   1      
 244   1        while(1){//ep1,2 processing
 245   2              
 246   2              // check if any keyboard data input
 247   2              if(kb_check) {
 248   3                      key_make=0;
 249   3                      while(rd_kb_ptr != rx_kb_ptr){
 250   4                       key=kb_scan();
 251   4                       if(key != 0) {
 252   5                              // new key pressed
 253   5                              if(usb_kb_ptr >= 8) {
 254   6                                      //over-flow
 255   6                                      KB_DATA[2]=0x01;        
 256   6                                      KB_DATA[3]=0x01;
 257   6                                      KB_DATA[4]=0x01;        
 258   6                                      KB_DATA[5]=0x01;
 259   6                                      KB_DATA[6]=0x01;        
 260   6                                      KB_DATA[7]=0x01;
 261   6                                      //
 262   6                                      usb_kb_ptr = 2;
 263   6                              }
 264   5                              else {
 265   6                                      KB_DATA[usb_kb_ptr++]=key;              
 266   6                              }               
 267   5                       }
 268   4                      }
 269   3                      if(key | left_shift_make | right_shift_make | left_ctrl_make | right_ctrl_make
 270   3                        |left_alt_make | right_alt_make | right_gui_make | left_gui_make){
 271   4                              // new modifier press  
 272   4                              if(left_shift_make)  KB_DATA[0] |= 0x02; //bit 1
 273   4                              if(right_shift_make) KB_DATA[0] |= 0x20; //bit 5
 274   4                              if(left_ctrl_make)   KB_DATA[0] |= 0x01; //bit 0
 275   4                              if(right_ctrl_make)  KB_DATA[0] |= 0x10; //bit 4
 276   4                              if(left_alt_make)    KB_DATA[0] |= 0x04; //bit 2
 277   4                              if(right_alt_make)   KB_DATA[0] |= 0x40; //bit 6
 278   4                              if(left_gui_make)    KB_DATA[0] |= 0x08; //bit 3
 279   4                              if(right_gui_make)   KB_DATA[0] |= 0x80; //bit 7
 280   4                              NEW_KB_DATA = 1;
 281   4                      }
 282   3                      if(mm_key0 != 0 || mm_key1 != 0){
 283   4                              //new mm key pressed    
 284   4                              MM_KB_DATA[0]=mm_key0;
 285   4                              MM_KB_DATA[1]=mm_key1;
 286   4                              NEW_MM_KB_DATA = 1;
 287   4                      }
 288   3                      if(power_make | sleep_make | wakeup_make){
 289   4                              //new sys key pressed   
 290   4                              if(power_make) SYS_KB_DATA = 0x81;
 291   4                              else if(sleep_make) SYS_KB_DATA = 0x82;
 292   4                              else if(wakeup_make) SYS_KB_DATA = 0x83;
 293   4                              NEW_SYS_KB_DATA = 1;                    
 294   4                      }
 295   3                      kb_check=0;
 296   3              }
 297   2              if(NEW_KB_DATA && ((USB_CTL2 & 0x80)==0)){
 298   3                      
 299   3                      NEW_KB_DATA=0;
 300   3                                      
 301   3                      USB_EPP = 0;                            
 302   3                      USB_EP1 = KB_DATA[0];
 303   3                      USB_EP1 = KB_DATA[1];
C51 COMPILER V7.07   TEST02                                                                01/26/2007 14:58:49 PAGE 6   

 304   3                      USB_EP1 = KB_DATA[2];
 305   3                      USB_EP1 = KB_DATA[3];
 306   3                      USB_EP1 = KB_DATA[4];
 307   3                      USB_EP1 = KB_DATA[5];
 308   3                      USB_EP1 = KB_DATA[6];
 309   3                      USB_EP1 = KB_DATA[7];
 310   3                      
 311   3                      if(ep1toggle) USB_CTL2 = 0x98;  
 312   3                      else USB_CTL2 = 0x88;
 313   3                      
 314   3                      
 315   3                      while(!(USB_STA0 & 0x04));
 316   3                      USB_CTL2 = USB_CTL2 & 0x7F; //clear tx1e
 317   3                      USB_STA0 = USB_STA0 | 0x04; //txd1f=0
 318   3                      ep1toggle = ~ep1toggle;         
 319   3                      //
 320   3                      // flush buffer
 321   3                      //
 322   3                      KB_DATA[0] = 0;
 323   3                      KB_DATA[1] = 0; 
 324   3                      KB_DATA[2] = 0; 
 325   3                      KB_DATA[3] = 0; 
 326   3                      KB_DATA[4] = 0; 
 327   3                      KB_DATA[5] = 0; 
 328   3                      KB_DATA[6] = 0;   
 329   3                      KB_DATA[7] = 0;     
 330   3                      //
 331   3                      usb_kb_ptr = 2;         
 332   3                      
 333   3                      kb_idle_cnt=0;  
 334   3                      
 335   3                      key_make = 1;
 336   3              }
 337   2              
 338   2              if(NEW_SYS_KB_DATA && ((USB_CTL3 & 0x80)==0)){
 339   3                      kb_idle_cnt=0;
 340   3                      // ep 2 traffic, 2 bytes data packet
 341   3                      NEW_SYS_KB_DATA=0;
 342   3                      USB_EPP=0;
 343   3                      USB_EP2 = 2; //Report Id=2;
 344   3                      USB_EP2 = SYS_KB_DATA;
 345   3                      if(ep2toggle) USB_CTL3 = 0x92;  
 346   3                      else USB_CTL3 = 0x82;
 347   3                      
 348   3                      
 349   3                      while(!(USB_STA0 & 0x10));
 350   3                      USB_CTL3 = USB_CTL3 & 0x7F; //clear tx2e
 351   3                      USB_STA0 = USB_STA0 | 0x10; //txd2f=0
 352   3                      ep2toggle = ~ep2toggle;         
 353   3                      //
 354   3                      // flush buffer
 355   3                      //
 356   3                      MM_KB_DATA[0] = 0;
 357   3                      MM_KB_DATA[1] = 0;
 358   3                      
 359   3                      kb_idle_cnt=0;
 360   3              }
 361   2              
 362   2              if(NEW_MM_KB_DATA && ((USB_CTL3 & 0x80)==0)){
 363   3                      
 364   3                      // ep2 traffic, 3 bytes data packet
 365   3                      NEW_MM_KB_DATA = 0;
C51 COMPILER V7.07   TEST02                                                                01/26/2007 14:58:49 PAGE 7   

 366   3                      USB_EPP = 0;      
 367   3                      USB_EP2 = 3; //Report Id=3                      
 368   3                      USB_EP2 = MM_KB_DATA[0];
 369   3                      USB_EP2 = MM_KB_DATA[1];
 370   3                      
 371   3                      if(ep2toggle) USB_CTL3 = 0x93;  
 372   3                      else USB_CTL3 = 0x83;
 373   3                      
 374   3                      
 375   3                      while(!(USB_STA0 & 0x10));
 376   3                      USB_CTL3 = USB_CTL3 & 0x7F; //clear tx2e
 377   3                      USB_STA0 = USB_STA0 | 0x10; //txd2f=0
 378   3                      ep2toggle = ~ep2toggle;         
 379   3                      //
 380   3                      // flush buffer
 381   3                      //
 382   3                      MM_KB_DATA[0] = 0;
 383   3                      MM_KB_DATA[1] = 0; 
 384   3                      
 385   3                      kb_idle_cnt=0;
 386   3              }
 387   2      
 388   2              //==============================================================//
 389   2              
 390   2              if(key_make | (KB_idle_rate & (kb_idle_cnt > (KB_idle_rate << 2)))){
 391   3                      //forced to tx one kb packet    
 392   3                      USB_EPP=0;
 393   3                      USB_EP1=0;
 394   3                      USB_EP1=0;
 395   3                      USB_EP1=0;
 396   3                      USB_EP1=0;
 397   3                      USB_EP1=0;
 398   3                      USB_EP1=0;
 399   3                      USB_EP1=0;
 400   3                      USB_EP1=0;
 401   3                      

⌨️ 快捷键说明

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