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

📄 combi.lst

📁 单片机快速入门原程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 414          ** or a response to a command (device id, BAT response, etc).
 415          */
 416          typedef struct
 417          {
 418                  char bMsgBuff[5];                                               //array of bytes
 419                  char bMsgLen;                                                   //initial length of message
 420                  char bXmtLen;                                                   //length of bytes remaining to send
 421          }PS2_XMT_STRUCT;
 422          
 423          
 424          int16 bBatDelay;                                                        //bat delay, in msec.
 425          
 426          char ConsecutiveSetSamples;                                     //keeps track of number of consecutive set-sample commands
 427                                                                                                  //received from the host (for enabling z-mice)
 428          char  bIntervalCount;                                           //interval count, in msec, for reporting mouse packets
 429          
 430          MOUSEPARMS  MouseParms;                                         //mouse parameters
 431          PS2_XMT_STRUCT Ps2Xmt;                                          //transmit buffer
 432          char ksc_delay;                                                         //storage for assembly routines
 433          char ps2_temp0;                                                         //storage for assembly routines
 434          
 435          
 436          
 437          
 438          /*
 439          ** function prototypes for PS2 routines
 440          */
 441          
 442          void ps2BAT(void);
 443          void ps2_send(char data);
 444          char ps2_receive(void);
 445          void Reset(void);
 446          void Resend(void);
 447          void SetDefault(void);
 448          void Disable(void);
 449          void Enable(void);
 450          char SetSampleRate(char p);
 451          void ReadDeviceType(void);
 452          void SetRemoteMode(void);
 453          void SetWrapMode(void);
 454          void ReadData(void);
 455          void SetStreamMode(void);
 456          void StatusRequest(void);
 457          char SetResolution(char p);
 458          void SetScaling(void);
 459          void ResetScaling(void);
 460          char GetByte ( void);
 461          void ProcessCommand(char p);
 462          void SendMouseData(void);
 463          void Put(char p);
 464          void PutMsgBuff(void);
 465          void SendMouseData(void);
 466          void ps2main(void);
 467          void PutNextByte(void);
 468          void ReInitialize(void);
 469          void ResetInterval(void);
C51 COMPILER V7.01  COMBI                                                                  04/14/2008 22:57:43 PAGE 9   

 470          void Ps2MouseTask(void);
 471          
 472          
 473          /*
 474          **
 475          ** FUNCTION:            ClearRam
 476          **
 477          ** PURPOSE:                     Clears all RAM except data and program stacks.  
 478          **
 479          ** PARAMETERS:          none
 480          **
 481          ** DESCRIPTION:         Written in assembler so that only X and A are used ( no variables
 482          **                                      that might be cleared as a result of this function executing)
 483          **
 484          */
 485          
 486          void ClearRam(void)
 487          {
 488              #asm 
*** ERROR C315 IN LINE 488 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
 489              mov     X,REGISTER_SIZE - 1
 490              mov     A,0
 491          lp:
 492              mov     [X + REGISTER_START],A
 493              dec     X
 494              jnc     lp
 495              #endasm
*** ERROR C315 IN LINE 495 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'endasm'
 496              return;
 497              }
 498          
 499          
 500          /*
 501          **
 502          ** FUNCTION:            IsUsbInterface
 503          **
 504          ** PURPOSE:                     Determines whether a USB or PS/2 host is connected upstream.  
 505          **
 506          ** PARAMETERS:          none
 507          **
 508          ** DESCRIPTION:         This function performs the following algorithm:
 509          
 510                                                  1) Wake up and delay 50mS. Initialize the PS2 BAT delay counter.
 511          
 512                                                  2) For a period of 2mS, poll the SCLK and SDATA lines every 10uS.
 513                                                     If we get 4 samples in a row with non-zero data on either line, 
 514                                                     detect PS2. If the 2mS expires, go to (3).
 515          
 516                                                  3) Enable USB pull up resistor and delay 500uS. 
 517                                                     Poll the SCLK and SDATA lines indefinitely 
 518                                                     until a non-zero condition exists on either line. 
 519                                                     During this polling period, we begin to count down the PS2 BAT delay.  
 520                                                     If SCLK(D+) is sampled high, detect PS2. If SDATA(D-) 
 521                                                     is sampled high, go to (4).
 522          
 523                                                  4) Disable the USB connect resistor and Delay 100uS.  
 524                                                          if D+ and D- are both 0, detect  USB, else detect PS2.
 525          */
 526          
 527          char    IsUsbInterface(void)
 528          {
 529          
C51 COMPILER V7.01  COMBI                                                                  04/14/2008 22:57:43 PAGE 10  

 530                  char temp;
 531                  char samples = 4;
 532               bBatDelay = (500 - 50);                                                            //initialize BAT delay to 500 msec
 533                  temp = MsecStatus.b1msCounter+50;                                           //wait 50 msec
 534                                                                                                                              
 535                  while (temp != MsecStatus.b1msCounter)
 536                          RESET_COP();
 537                  temp = MsecStatus.b1msCounter+2;
 538                  while (temp != MsecStatus.b1msCounter)                                  //for 2 msec, sample clock and data
 539                  {
 540                          if ((PORT2 & (PS2_CLOCK_BIT | PS2_DATA_BIT)) && (!--samples))
 541                                          return(0);                                                                      //4  consecutive samples of either clock or data high, it's ps2
 542                          samples = 4;                                    
 543                  }
 544          
 545                  USB_STATUS = (VREG_ENABLE_MASK | FORCE_NEG_OPEN_POS_OPEN);//enable USB pullup 
 546                  Delay(250);                                                                                             //and delay 250 usec
 547                  while (1)                                                                                               //wait forever
 548                  {
 549                          RESET_COP();
 550                          if (MsecStatus.b1msFlags & ONE_MSEC_FLAG)
 551                          {
 552                                  if (bBatDelay)                                                                  //if a msec expires, decrease bat delay
 553                                          bBatDelay--;
 554                                  MsecStatus.b1msFlags &= ~ONE_MSEC_FLAG;
 555                          }
 556                          if (PORT2 & PS2_CLOCK_BIT)                                                      
 557                                  return(0);                                                                              //clock bit high it's ps2
 558                          if (PORT2 & PS2_DATA_BIT)                                                       //data bit high, quit the loop
 559                                  break;
 560                  }
 561                  USB_STATUS = FORCE_NEG_OPEN_POS_OPEN;                                   //disable USB pullup 
 562              Delay(100);  
 563                  return(!(PORT2 & (PS2_CLOCK_BIT | PS2_DATA_BIT)));              //if both clock and data go low, it's usb
 564          }
 565          
 566          
 567          /*
 568          **
 569          ** FUNCTION:            MY_RESET_ISR
 570          **
 571          ** PURPOSE:                     Reset ISR, vectored to during power-up or watchdog reset.  
 572          **
 573          ** PARAMETERS:          none
 574          **
 575          ** DESCRIPTION:         This function performs the following initialization:
 576          **                                      
 577          **                                      1)disables interrupts;
 578          **                                      2)resets the watchdog;
 579          **                                      3)initializes data stack pointer;
 580          **                                      4)clears ram;
 581          **                                      5)initializes port I/O;
 582          *                                       6)enables 1msec interrupt;
 583          **                                      7)jumps to main loop
 584          **                                      
 585          **
 586          */
 587          
 588          void MY_RESET_ISR(void)
 589          {
 590              DI();                                                                                       //disable ints
 591                  RESET_COP();                                                                    //reset watchdog
C51 COMPILER V7.01  COMBI                                                                  04/14/2008 22:57:43 PAGE 11  

 592          
 593                  /*
 594                  ** use assembler to initialize data stack
 595                  */
 596          #asm (mov A,RAM_START + STACK_SIZE-1)                           
*** ERROR C315 IN LINE 596 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
 597          #asm (swap A,dsp)
*** ERROR C315 IN LINE 597 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
 598                ClearRam();
 599                  USB_STATUS = FORCE_NEG_OPEN_POS_OPEN;                                           //drive D+,D- to Hi-Z
 600                  PORT0_MODE1 = PORT0_MODE1_INIT;                                                         //set up port modes
 601                  PORT0_MODE0 = PORT0_MODE0_INIT;                                                         //
 602                  PORT1_MODE0 = PORT1_MODE0_INIT ;                                                        //
 603                  PORT1_MODE1 = PORT1_MODE1_INIT;                                                         //
 604                  PORT0 = PORT0_INIT;                                                                                     //set up initial values
 605                  PORT1 = PORT1_INIT;                                                                                     //
 606                  PORT0IE = PORT0_INIT;                                                                           //set up for GPIO interrupts on switch inputs
 607                  PORT1IE = PORT1_INIT;                                                                           //
 608                  PORT0IP = ~PORT0_INIT;                                                                          //set up for negative edges interrupts switch inputs
 609                  PORT1IP = ~PORT1_INIT;
 610                  GLOBAL_INTERRUPT = MILLISECOND_ENABLE;                                          //enable all pertinent interrupts
 611                  EI();
 612              #asm (jmp main)
*** ERROR C315 IN LINE 612 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
 613           }
 614          
 615          
 616          /*
 617          **
 618          ** FUNCTION:            main
 619          **
 620          ** PURPOSE:                     determines interface (usb or ps2) and dispatches to appropriate code.  
 621          **
 622          ** PARAMETERS:          none
 623          **
 624          ** DESCRIPTION:         
 625          **                                      
 626          **
 627          */
 628          
 629           void main(void)
 630           {

⌨️ 快捷键说明

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