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

📄 f34x_usb_main.lst

📁 学习usb编程很好的例子 自己学习用的。
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   F34X_USB_MAIN                                                         08/01/2007 13:13:23 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE F34X_USB_MAIN
OBJECT MODULE PLACED IN F34x_USB_Main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe F34x_USB_Main.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // F34x_USB_Main.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2005 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          //
   9          // This application note covers the implementation of a simple USB application 
  10          // using the interrupt transfer type. This includes support for device
  11          // enumeration, control and interrupt transactions, and definitions of 
  12          // descriptor data. The purpose of this software is to give a simple working 
  13          // example of an interrupt transfer application; it does not include
  14          // support for multiple configurations or other transfer types.
  15          //
  16          // How To Test:    See Readme.txt
  17          //
  18          //
  19          // FID:            34X000019
  20          // Target:         C8051F34x
  21          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  22          //                 Silicon Laboratories IDE version 2.6
  23          // Command Line:   See Readme.txt
  24          // Project Name:   F34x_USB_Interrupt
  25          //
  26          //
  27          // Release 1.0
  28          //    -Initial Revision (GP)
  29          //    -22 NOV 2005
  30          //    -Ported from 'F320_USB_Bulk
  31          //
  32          
  33          //-----------------------------------------------------------------------------
  34          // Includes
  35          //-----------------------------------------------------------------------------
  36          
  37          #include <c8051f340.h>
  38          #include "F34x_USB_Register.h"
  39          #include "F34x_USB_Main.h"
  40          #include "F34x_USB_Descriptor.h"
  41          
  42          //-----------------------------------------------------------------------------
  43          // 16-bit SFR Definitions for 'F32x
  44          //-----------------------------------------------------------------------------
  45          
  46          sfr16 TMR2RL   = 0xca;                 // Timer2 reload value
  47          sfr16 TMR2     = 0xcc;                 // Timer2 counter
  48          
  49          //-----------------------------------------------------------------------------
  50          // Globals
  51          //-----------------------------------------------------------------------------
  52          
  53          sbit Led1 = P2^2;                      // LED='1' means ON
  54          sbit Led2 = P2^3;
  55          
C51 COMPILER V7.50   F34X_USB_MAIN                                                         08/01/2007 13:13:23 PAGE 2   

  56          #define Sw1 0x01                       // These are the port2 bits for Sw1
  57          #define Sw2 0x02                       // and Sw2 on the development board
  58          BYTE Switch1State = 0;                 // Indicate status of switch
  59          BYTE Switch2State = 0;                 // starting at 0 == off
  60          
  61          BYTE Toggle1 = 0;                      // Variable to make sure each button
  62          BYTE Toggle2 = 0;                      // press and release toggles switch
  63          
  64          BYTE Potentiometer = 0x00;             // Last read potentiometer value
  65          BYTE Temperature = 0x00;               // Last read temperature sensor value
  66          
  67          idata BYTE Out_Packet[64];             // Last packet received from host
  68          idata BYTE In_Packet[64];              // Next packet to sent to host
  69          
  70          code const BYTE TEMP_ADD = 112;        // This constant is added to Temperature
  71          
  72          
  73          //-----------------------------------------------------------------------------
  74          // Main Routine
  75          //-----------------------------------------------------------------------------
  76          void main(void)
  77          {
  78   1         PCA0MD &= ~0x40;                    // Disable Watchdog timer
  79   1      
  80   1         OSCILLATOR_Init();                  // Initialize oscillator
  81   1         PORT_Init();                        // Initialize crossbar and GPIO
  82   1         USB0_Init();                        // Initialize USB0
  83   1         Timer2_Init();                      // Initialize Timer2
  84   1         ADC0_Init();                        // Initialize ADC0
  85   1      
  86   1         while (1)
  87   1         {
  88   2          // It is possible that the contents of the following packets can change
  89   2          // while being updated.  This doesn't cause a problem in the sample
  90   2          // application because the bytes are all independent.  If data is NOT
  91   2          // independent, packet update routines should be moved to an interrupt
  92   2          // service routine, or interrupts should be disabled during data updates.
  93   2      
  94   2            if (Out_Packet[0] == 1) Led1 = 1;   // Update status of LED #1
  95   2            else Led1 = 0;
  96   2            if (Out_Packet[1] == 1) Led2 = 1;   // Update status of LED #2
  97   2            else Led2 = 0;
  98   2            P1 = (Out_Packet[2] & 0x0F);        // Set Port 1 pins
  99   2      
 100   2      
 101   2            In_Packet[0] = Switch1State;        // Send status of switch 1
 102   2            In_Packet[1] = Switch2State;        // and switch 2 to host
 103   2            In_Packet[2] = (P0 & 0x0F);         // Port 0 [0-3]
 104   2            In_Packet[3] = Potentiometer;       // Potentiometer value
 105   2            In_Packet[4] = Temperature;         // Temperature sensor value
 106   2         }
 107   1      }
 108          
 109          //-----------------------------------------------------------------------------
 110          // Initialization Subroutines
 111          //-----------------------------------------------------------------------------
 112          
 113          //-----------------------------------------------------------------------------
 114          // OSCILLATOR_Init
 115          //-----------------------------------------------------------------------------
 116          //
 117          // Return Value : None
C51 COMPILER V7.50   F34X_USB_MAIN                                                         08/01/2007 13:13:23 PAGE 3   

 118          // Parameters   : None
 119          //
 120          // Initialize the system clock and USB clock
 121          //
 122          //-----------------------------------------------------------------------------
 123          void OSCILLATOR_Init(void)
 124          {
 125   1      #ifdef _USB_LOW_SPEED_
              
                 OSCICN |= 0x03;                     // Configure internal oscillator for
                                                     // its maximum frequency and enable
                                                     // missing clock detector
              
                 CLKSEL  = SYS_INT_OSC;              // Select System clock
                 CLKSEL |= USB_INT_OSC_DIV_2;        // Select USB clock
              #else
 134   1         OSCICN |= 0x03;                     // Configure internal oscillator for
 135   1                                             // its maximum frequency and enable
 136   1                                             // missing clock detector
 137   1      
 138   1         CLKMUL  = 0x00;                     // Select internal oscillator as
 139   1                                             // input to clock multiplier
 140   1      
 141   1         CLKMUL |= 0x80;                     // Enable clock multiplier
 142   1         Delay();                            // Delay for clock multiplier to begin
 143   1         CLKMUL |= 0xC0;                     // Initialize the clock multiplier
 144   1         Delay();                            // Delay for clock multiplier to begin
 145   1      
 146   1         while(!(CLKMUL & 0x20));            // Wait for multiplier to lock
 147   1         CLKSEL  = SYS_INT_OSC;              // Select system clock
 148   1         CLKSEL |= USB_4X_CLOCK;             // Select USB clock
 149   1      #endif  /* _USB_LOW_SPEED_ */
 150   1      }
 151          
 152          //-----------------------------------------------------------------------------
 153          // PORT_Init
 154          //-----------------------------------------------------------------------------
 155          //
 156          // Return Value : None
 157          // Parameters   : None
 158          //
 159          // This function configures the crossbar and GPIO ports.
 160          //
 161          // P2.2   digital   push-pull     LED
 162          // P2.3   digital   push-pull     LED
 163          // P2.5   analog                  Potentiometer
 164          //-----------------------------------------------------------------------------
 165          void PORT_Init(void)
 166          {
 167   1         P2MDIN   = 0xDF;                    // P2.5 set as analog input
 168   1      
 169   1         P0MDOUT |= 0x0F;                    // P0 pins 0-3 set high impedance
 170   1         P1MDOUT |= 0x0F;                    // P1 pins 0-3 set high impedance
 171   1         P2MDOUT |= 0x0C;                    // P2 pins 0,1 set high impedance
 172   1      
 173   1         P2SKIP   = 0x20;                    // P2.5 skipped by crossbar
 174   1      
 175   1         XBR0     = 0x00;
 176   1         XBR1     = 0x40;                    // Enable Crossbar
 177   1      }
 178          
 179          //-----------------------------------------------------------------------------
C51 COMPILER V7.50   F34X_USB_MAIN                                                         08/01/2007 13:13:23 PAGE 4   

⌨️ 快捷键说明

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