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

📄 f34x_usb_main.lst

📁 C8051F340的USB应用例程
💻 LST
📖 第 1 页 / 共 2 页
字号:
 188   1         P2SKIP   = 0x20;                    // P2.5 skipped by crossbar
 189   1      
 190   1         XBR0     = 0x00;
 191   1         XBR1     = 0x40;                    // Enable Crossbar
 192   1      }
 193          
 194          //-----------------------------------------------------------------------------
 195          // USB0_Init
 196          //-----------------------------------------------------------------------------
 197          //
 198          // Return Value : None
 199          // Parameters   : None
 200          // 
 201          // - Initialize USB0
 202          // - Enable USB0 interrupts
 203          // - Enable USB0 transceiver
 204          // - Enable USB0 with suspend detection
 205          //-----------------------------------------------------------------------------
 206          void USB0_Init(void)
 207          {
 208   1         BYTE Count;
 209   1      
 210   1         // Set initial values of In_Packet and Out_Packet to zero
 211   1         // Initialize here as opposed to above main() to prevent WDT reset
 212   1         for (Count = 0; Count < 64; Count++)
 213   1         {
 214   2            Out_Packet[Count] = 0;
 215   2            In_Packet[Count] = 0;
 216   2         }
 217   1      
 218   1         POLL_WRITE_BYTE(POWER,  0x08);      // Force Asynchronous USB Reset
 219   1         POLL_WRITE_BYTE(IN1IE,  0x07);      // Enable Endpoint 0-2 in interrupts
 220   1         POLL_WRITE_BYTE(OUT1IE, 0x07);      // Enable Endpoint 0-2 out interrupts
 221   1         POLL_WRITE_BYTE(CMIE,   0x07);      // Enable Reset,Resume,Suspend interrupts
 222   1      #ifdef _USB_LOW_SPEED_
                 USB0XCN = 0xC0;                     // Enable transceiver; select low speed
                 POLL_WRITE_BYTE(CLKREC, 0xA0);      // Enable clock recovery; single-step mode
                                                     // disabled; low speed mode enabled
              #else
 227   1         USB0XCN = 0xE0;                     // Enable transceiver; select full speed
 228   1         POLL_WRITE_BYTE(CLKREC, 0x80);      // Enable clock recovery, single-step mode
 229   1                                             // disabled
 230   1      #endif // _USB_LOW_SPEED_
 231   1      
 232   1         EIE1 |= 0x02;                       // Enable USB0 Interrupts
 233   1         EA = 1;                             // Global Interrupt enable
 234   1                                             // Enable USB0 by clearing the USB 
 235   1                                             // Inhibit bit
 236   1         POLL_WRITE_BYTE(POWER,  0x01);      // and enable suspend detection
 237   1      }
 238          
 239          //-----------------------------------------------------------------------------
 240          // Timer2_Init
 241          //-----------------------------------------------------------------------------
C51 COMPILER V8.02   F34X_USB_MAIN                                                         04/28/2008 13:24:09 PAGE 5   

 242          //
 243          // Return Value : None
 244          // Parameters   : None
 245          // 
 246          // Timer 2 reload, used to check if switch pressed on overflow and
 247          // used for ADC continuous conversion
 248          //-----------------------------------------------------------------------------
 249          
 250          void Timer2_Init(void)
 251          {
 252   1         TMR2CN  = 0x00;                     // Stop Timer2; Clear TF2;
 253   1      
 254   1         CKCON  &= ~0xF0;                    // Timer2 clocked based on T2XCLK;
 255   1         TMR2RL  = 0;                        // Initialize reload value
 256   1         TMR2    = 0xffff;                   // Set to reload immediately
 257   1      
 258   1         ET2     = 1;                        // Enable Timer2 interrupts
 259   1         TR2     = 1;                        // Start Timer2
 260   1      }
 261          
 262          //-----------------------------------------------------------------------------
 263          // ADC0_Init
 264          //-----------------------------------------------------------------------------
 265          //
 266          // Return Value : None
 267          // Parameters   : None
 268          // 
 269          // Configures ADC for single ended continuous conversion or Timer2
 270          //-----------------------------------------------------------------------------
 271          
 272          void ADC0_Init(void)
 273          {
 274   1         REF0CN  = 0x0F;                     // Enable voltage reference VREF
 275   1         AMX0P = 0x1E;                       // Positive input starts as temp sensor
 276   1         AMX0N = 0x1F;                       // Single ended mode(neginput = gnd)
 277   1      
 278   1         ADC0CF  = 0xF8;                     // SAR Period 0x1F, Right adjusted
 279   1      
 280   1         ADC0CN  = 0xC2;                     // Continuous converion on timer 2 
 281   1                                             // overflow; low power tracking mode on
 282   1      
 283   1         EIE1   |= 0x08;                     // Enable conversion complete interrupt
 284   1      }
 285          
 286          //-----------------------------------------------------------------------------
 287          // Timer2_ISR
 288          //-----------------------------------------------------------------------------
 289          //
 290          // Called when timer 2 overflows, check to see if switch is pressed,
 291          // then watch for release.
 292          //
 293          //-----------------------------------------------------------------------------
 294          
 295          void Timer2_ISR(void) interrupt 5
 296          {
 297   1         if (!(P2 & Sw1))                    // Check for switch #1 pressed
 298   1         {
 299   2            if (Toggle1 == 0)                // Toggle is used to debounce switch
 300   2            {                                // so that one press and release will
 301   3               Switch1State = ~Switch1State; // toggle the state of the switch sent
 302   3               Toggle1 = 1;                  // to the host
 303   3            }
C51 COMPILER V8.02   F34X_USB_MAIN                                                         04/28/2008 13:24:09 PAGE 6   

 304   2         }
 305   1         else Toggle1 = 0;                   // Reset toggle variable
 306   1      
 307   1         if (!(P2 & Sw2))                    // Same as above, but Switch2
 308   1         {
 309   2            if (Toggle2 == 0)
 310   2            {
 311   3               Switch2State = ~Switch2State;
 312   3               Toggle2 = 1;
 313   3            }
 314   2         }
 315   1         else Toggle2 = 0;
 316   1      
 317   1         TF2H = 0;                           // Clear Timer2 interrupt flag
 318   1      }
 319          
 320          //-----------------------------------------------------------------------------
 321          // ADC0_ConvComplete_ISR
 322          //-----------------------------------------------------------------------------
 323          //
 324          // Called after a conversion of the ADC has finished
 325          // Updates the appropriate variable for potentiometer or temperature sensor
 326          // Switches the ADC multiplexor value to switch between the potentiometer 
 327          // and temp sensor
 328          //
 329          //-----------------------------------------------------------------------------
 330          
 331          void ADC0_ConvComplete_ISR(void) interrupt 10
 332          {
 333   1         if (AMX0P == 0x1E)                  // This switches the AMUX between
 334   1         {                                   // the temperature sensor and the
 335   2            Temperature   = ADC0L;           // potentiometer pin after conversion
 336   2            Temperature  += TEMP_ADD;        // Add offset to Temperature
 337   2            AMX0P       = 0x04;              // switch to potentiometer
 338   2            ADC0CF      = 0xFC;              // Place ADC0 in left-adjusted mode
 339   2         }
 340   1         else
 341   1         {
 342   2            Potentiometer = ADC0H;
 343   2            AMX0P       = 0x1E;              // switch to temperature sensor
 344   2            ADC0CF      = 0xF8;              // place ADC0 in right-adjusted mode
 345   2         }
 346   1      
 347   1         AD0INT = 0;
 348   1      }
 349          
 350          //-----------------------------------------------------------------------------
 351          // Delay
 352          //-----------------------------------------------------------------------------
 353          //
 354          // Used for a small pause, approximately 80 us in Full Speed,
 355          // and 1 ms when clock is configured for Low Speed
 356          //
 357          //-----------------------------------------------------------------------------
 358          
 359          void Delay(void)
 360          {
 361   1         int x;
 362   1         for(x = 0;x < 500;x)
 363   1            x++;
 364   1      }
 365          
C51 COMPILER V8.02   F34X_USB_MAIN                                                         04/28/2008 13:24:09 PAGE 7   

 366          //-----------------------------------------------------------------------------
 367          // End Of File
 368          //-----------------------------------------------------------------------------


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    356    ----
   CONSTANT SIZE    =      1    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      6    ----
   IDATA SIZE       =    128    ----
   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 + -