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

📄 f340_usb0_mouse.lst

📁 基于单片机的USB鼠标的实现
💻 LST
📖 第 1 页 / 共 2 页
字号:
 184          // Parameters - None
 185          //
 186          // This top-level initialization routine calls all support routine.
 187          //
 188          // ----------------------------------------------------------------------------
 189          void System_Init (void)
 190          {
 191   1         PCA0MD &= ~0x40;                    // Disable Watchdog timer
 192   1         Sysclk_Init ();                     // initialize system clock
 193   1         Port_Init ();                             // configure cross bar
 194   1         Timer_Init ();                      // configure timer
 195   1         ADC0_Init ();
 196   1      }
 197          
 198          //-----------------------------------------------------------------------------
 199          // USB0_Init
 200          //-----------------------------------------------------------------------------
 201          //
 202          // Return Value - None
 203          // Parameters - None
 204          //
 205          // - Initialize USB0
 206          // - Enable USB0 interrupts
 207          // - Enable USB0 transceiver
 208          // - Enable USB0 with suspend detection
 209          //
 210          // ----------------------------------------------------------------------------
 211          
 212          void USB0_Init (void)
 213          {
 214   1      
 215   1         POLL_WRITE_BYTE (POWER, 0x08);      // Force Asynchronous USB Reset
 216   1         POLL_WRITE_BYTE (IN1IE, 0x07);      // Enable Endpoint 0-1 in interrupts
 217   1         POLL_WRITE_BYTE (OUT1IE,0x07);      // Enable Endpoint 0-1 out interrupts
 218   1         POLL_WRITE_BYTE (CMIE, 0x07);       // Enable Reset, Resume, and Suspend
 219   1                                             // interrupts
 220   1         USB0XCN = 0xE0;                     // Enable transceiver; select full speed
 221   1         POLL_WRITE_BYTE (CLKREC,0x80);      // Enable clock recovery, single-step
 222   1                                             // mode disabled
 223   1      
 224   1         EIE1 |= 0x02;                       // Enable USB0 Interrupts
 225   1      
 226   1                                             // Enable USB0 by clearing the USB
 227   1         POLL_WRITE_BYTE (POWER, 0x01);      // Inhibit Bit and enable suspend
 228   1                                             // detection
 229   1      
 230   1      }
 231          
 232          
 233          //-----------------------------------------------------------------------------
 234          // Sysclk_Init
 235          //-----------------------------------------------------------------------------
 236          //
 237          // Return Value - None
 238          // Parameters - None
 239          //
 240          // Initialize system clock to maximum frequency.
 241          //
C51 COMPILER V7.06   F340_USB0_MOUSE                                                       09/12/2006 16:12:59 PAGE 5   

 242          // ----------------------------------------------------------------------------
 243          void Sysclk_Init (void)
 244          {
 245   1      #ifdef _USB_LOW_SPEED_
              
                 OSCICN |= 0x03;                     // Configure internal oscillator for
                                                     // its maximum frequency and enable
                                                     // missing clock detector
              
                 CLKSEL  = SYS_EXT_OSC;              // Select System clock
                 CLKSEL |= USB_INT_OSC_DIV_2;        // Select USB clock
              #else
 254   1         OSCICN |= 0x03;                     // Configure internal oscillator for
 255   1                                             // its maximum frequency and enable
 256   1                                             // missing clock detector
 257   1      
 258   1         CLKMUL  = 0x00;                     // Select internal oscillator as
 259   1                                             // input to clock multiplier
 260   1      
 261   1         CLKMUL |= 0x80;                     // Enable clock multiplier
 262   1         Delay();                            // Delay for clock multiplier to begin
 263   1         CLKMUL |= 0xC0;                     // Initialize the clock multiplier
 264   1         Delay();                            // Delay for clock multiplier to begin
 265   1      
 266   1         while(!(CLKMUL & 0x20));            // Wait for multiplier to lock
 267   1         CLKSEL  = SYS_INT_OSC;              // Select system clock
 268   1         CLKSEL |= USB_4X_CLOCK;             // Select USB clock
 269   1      #endif  // _USB_LOW_SPEED_
 270   1      }
 271          
 272          //-----------------------------------------------------------------------------
 273          // Port_Init
 274          //-----------------------------------------------------------------------------
 275          //
 276          // Return Value - None
 277          // Parameters - None
 278          //
 279          // - Configure the Crossbar and GPIO ports.
 280          //
 281          // ----------------------------------------------------------------------------
 282          void Port_Init(void)
 283          {
 284   1         P2MDIN   = ~(0x20);                 // Port 2 pin 5 set as analog input
 285   1         P0MDOUT |= 0x0F;                    // Port 0 pins 0-3 set high impedence
 286   1         P1MDOUT |= 0x0F;                    // Port 1 pins 0-3 set high impedence
 287   1         P2MDOUT |= 0x0C;                    // Port 2 pins 0,1 set high empedence
 288   1         P2SKIP   = 0x20;                    // Port 2 pin 5 skipped by crossbar
 289   1         XBR0     = 0x00;
 290   1         XBR1     = 0x40;                    // Enable Crossbar
 291   1      }
 292          
 293          //-----------------------------------------------------------------------------
 294          // Timer_Init
 295          //-----------------------------------------------------------------------------
 296          //
 297          // Return Value - None
 298          // Parameters - None
 299          //
 300          // - Timer 2 reload, used to check if switch pressed on overflow and
 301          // used for ADC continuous conversion
 302          //
 303          // ----------------------------------------------------------------------------
C51 COMPILER V7.06   F340_USB0_MOUSE                                                       09/12/2006 16:12:59 PAGE 6   

 304          void Timer_Init (void)
 305          {
 306   1         TMR2CN  = 0x00;                     // Stop Timer2; Clear TF2;
 307   1      
 308   1         CKCON  &= ~0xF0;                    // Timer2 clocked based on T2XCLK;
 309   1         TMR2RL  = 0;                        // Initialize reload value
 310   1         TMR2    = 0xffff;                   // Set to reload immediately
 311   1      
 312   1         ET2     = 1;                        // Enable Timer2 interrupts
 313   1         TR2     = 1;                        // Start Timer2
 314   1      }
 315          
 316          //-----------------------------------------------------------------------------
 317          // ADC0_Init
 318          //-----------------------------------------------------------------------------
 319          //
 320          // Return Value - None
 321          // Parameters - None
 322          //
 323          // - Configures ADC for single ended continuous conversion or Timer2
 324          //
 325          // ----------------------------------------------------------------------------
 326          void ADC0_Init (void)
 327          {
 328   1         REF0CN = 0x0E;                      // Enable voltage reference VREF
 329   1         AMX0P = 0x04;                       // switch to potentiometer
 330   1         ADC0CF = 0xFC;                      // place ADC0 in left-adjusted mode
 331   1         AMX0N = 0x1F;                       // Single ended mode(negative input=gnd)
 332   1      
 333   1         ADC0CF = 0xFC;                      // SAR Period 0x1F, Left adjusted output
 334   1      
 335   1         ADC0CN = 0xC2;                      // Continuous converion on timer 2
 336   1                                             // overflow with low power tracking
 337   1                                             // mode on
 338   1      
 339   1         EIE1 |= 0x08;                       // Enable conversion complete interrupt
 340   1      }
 341          
 342          
 343          //-----------------------------------------------------------------------------
 344          // Delay
 345          //-----------------------------------------------------------------------------
 346          //
 347          // Return Value - None
 348          // Parameters - None
 349          //
 350          // Used for a small pause, approximately 80 us in Full Speed,
 351          // and 1 ms when clock is configured for Low Speed
 352          //
 353          // ----------------------------------------------------------------------------
 354          void Delay (void)
 355          {
 356   1         int x;
 357   1         for (x = 0; x < 500; x)
 358   1            x++;
 359   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    324    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
C51 COMPILER V7.06   F340_USB0_MOUSE                                                       09/12/2006 16:12:59 PAGE 7   

   PDATA SIZE       =   ----    ----
   DATA SIZE        =     11    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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