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

📄 f32x_usb_main.lst

📁 Silicon Laboratories C8051F320/1单片机例子
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   F32X_USB_MAIN                                                         07/05/2008 17:13:18 PAGE 1   


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

line level    source

   1          //-----------------------------------------------------------------------------
   2          // F32x_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:            32X000024
  20          // Target:         C8051F32x
  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:   F32x_USB_Interrupt
  25          //
  26          //
  27          // Release 1.3
  28          //    -All changes by GP
  29          //    -22 NOV 2005
  30          //    -Changed revision number to match project revision
  31          //     No content changes to this file
  32          //    -Modified file to fit new formatting guidelines
  33          //    -Changed file name from USB_MAIN.c
  34          
  35          // Release 1.1
  36          //    -All changes by DM
  37          //    -22 NOV 2002
  38          //    -Added support for switches and sample USB interrupt application.
  39          //
  40          // Release 1.0
  41          //    -Initial Revision (JS)
  42          //    -22 FEB 2002
  43          //
  44          
  45          //-----------------------------------------------------------------------------
  46          // Includes
  47          //-----------------------------------------------------------------------------
  48          
  49          #include <c8051f320.h>
  50          #include "F32x_USB_Register.h"
  51          #include "F32x_USB_Main.h"
  52          #include "F32x_USB_Descriptor.h"
  53          
  54          //-----------------------------------------------------------------------------
  55          // 16-bit SFR Definitions for 'F32x
C51 COMPILER V7.50   F32X_USB_MAIN                                                         07/05/2008 17:13:18 PAGE 2   

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

 118   2            In_Packet[1] = Switch2State;        // and switch 2 to host
 119   2            In_Packet[2] = (P0 & 0x0F);         // Port 0 [0-3]
 120   2            In_Packet[3] = Potentiometer;       // Potentiometer value
 121   2            In_Packet[4] = Temperature;         // Temperature sensor value
 122   2         }
 123   1      }
 124          
 125          //-----------------------------------------------------------------------------
 126          // Initialization Subroutines
 127          //-----------------------------------------------------------------------------
 128          
 129          //-----------------------------------------------------------------------------
 130          // Sysclk_Init
 131          //-----------------------------------------------------------------------------
 132          //
 133          // Return Value : None
 134          // Parameters   : None
 135          //
 136          // Initialize the system clock and USB clock
 137          //
 138          //-----------------------------------------------------------------------------
 139          void Sysclk_Init(void)
 140          {
 141   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
 150   1              USB0XCN |=0x80;
 151   1         OSCICN |= 0x03;                     // Configure internal oscillator for
 152   1                                             // its maximum frequency and enable
 153   1                                             // missing clock detector
 154   1      
 155   1         CLKMUL  = 0x00;                     // Select internal oscillator as
 156   1                                             // input to clock multiplier
 157   1      
 158   1         CLKMUL |= 0x80;                     // Enable clock multiplier
 159   1         Delay();                            // Delay for clock multiplier to begin
 160   1         CLKMUL |= 0xC0;                     // Initialize the clock multiplier
 161   1         Delay();                            // Delay for clock multiplier to begin
 162   1      
 163   1         while(!(CLKMUL & 0x20));            // Wait for multiplier to lock
 164   1         CLKSEL  = SYS_INT_OSC;              // Select system clock
 165   1         CLKSEL |= USB_4X_CLOCK;             // Select USB clock
 166   1      #endif  /* _USB_LOW_SPEED_ */
 167   1      }
 168          
 169          //-----------------------------------------------------------------------------
 170          // PORT_Init
 171          //-----------------------------------------------------------------------------
 172          //
 173          // Return Value : None
 174          // Parameters   : None
 175          //
 176          // This function configures the crossbar and GPIO ports.
 177          //
 178          // P1.7   analog                  Potentiometer
 179          // P2.2   digital   push-pull     LED
C51 COMPILER V7.50   F32X_USB_MAIN                                                         07/05/2008 17:13:18 PAGE 4   

 180          // P2.3   digital   push-pull     LED
 181          //-----------------------------------------------------------------------------
 182          void Port_Init(void)
 183          {
 184   1         P1MDIN   = 0x7F;                    // Port 1 pin 7 set as analog input
 185   1         P0MDOUT |= 0x0F;                    // Port 0 pins 0-3 set push-pull
 186   1         P1MDOUT |= 0x0F;                    // Port 1 pins 0-3 set push-pull
 187   1         P2MDOUT |= 0x0C;                    // P2.2 and P2.3 set to push-pull

⌨️ 快捷键说明

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