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

📄 usb_main.lst

📁 CyPress的C8051F32X系列底层驱动(C语言)及上位机demo(vc环境)
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.05   USB_MAIN                                                              03/07/2006 11:28:07 PAGE 1   


C51 COMPILER V7.05, COMPILATION OF MODULE USB_MAIN
OBJECT MODULE PLACED IN USB_MAIN.OBJ
COMPILER INVOKED BY: E:\program files\silabs\IDEfiles\C51\BIN\C51.exe USB_MAIN.c DB OE

stmt level    source

   1          //-----------------------------------------------------------------------------
   2          // USB_MAIN.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2005 Silicon Laboratories, Inc.
   5          //
   6          // AUTH: JS
   7          // DATE: 22 FEB 02
   8          //
   9          //
  10          // Target: C8051F32x
  11          // Tool chain: KEIL C51 6.03 / KEIL EVAL C51
  12          //
  13          // REVISIONS:  11/22/02 - DM:  Added support for switches and sample USB
  14          // interrupt application.
  15          //
  16          //-----------------------------------------------------------------------------
  17          // Includes
  18          //-----------------------------------------------------------------------------
  19          
  20          #include <c8051f320.h>               
  21          #include "USB_REGISTER.h"
  22          #include "USB_MAIN.h"
  23          #include "USB_DESCRIPTOR.h"
  24          
  25          //-----------------------------------------------------------------------------
  26          // 16-bit SFR Definitions for 'F32x
  27          //-----------------------------------------------------------------------------
  28          
  29          sfr16 TMR2RL   = 0xca;                   // Timer2 reload value
  30          sfr16 TMR2     = 0xcc;                   // Timer2 counter     
  31          
  32          //-----------------------------------------------------------------------------
  33          // Global CONSTANTS
  34          //-----------------------------------------------------------------------------
  35          
  36          sbit Led1 = P2^2;                         // LED='1' means ON
  37          sbit Led2 = P2^3;
  38          
  39          #define Sw1 0x01                          // These are the port2 bits for Sw1
  40          #define Sw2 0x02                          // and Sw2 on the development board
  41          BYTE Switch1State = 0;                    // Indicate status of switch 
  42          BYTE Switch2State = 0;                    // starting at 0 == off
  43          
  44          BYTE Toggle1 = 0;                         // Variable to make sure each button
  45          BYTE Toggle2 = 0;                         // press and release toggles switch
  46          
  47          BYTE Potentiometer = 0x00;                // Last read potentiometer value
  48          BYTE Temperature = 0x00;                  // Last read temperature sensor value
  49          
  50          BYTE Out_Packet[8] = {0,0,0,0,0,0,0,0};   // Last packet received from host
  51          BYTE In_Packet[8]  = {0,0,0,0,0,0,0,0};   // Next packet to sent to host
  52          
  53          code const BYTE TEMP_ADD = 112;           // This constant is added to Temperature
  54          
  55          
C51 COMPILER V7.05   USB_MAIN                                                              03/07/2006 11:28:07 PAGE 2   

  56          //-----------------------------------------------------------------------------
  57          // Main Routine
  58          //-----------------------------------------------------------------------------
  59          void main(void) 
  60          {
  61   1         PCA0MD &= ~0x40;                       // Disable Watchdog timer
  62   1      
  63   1         Sysclk_Init();                         // Initialize oscillator
  64   1         Port_Init();                           // Initialize crossbar and GPIO
  65   1         Usb0_Init();                           // Initialize USB0
  66   1         Timer_Init();                          // Initialize timer2
  67   1         Adc_Init();                            // Initialize ADC
  68   1      
  69   1         while (1)
  70   1         {
  71   2          // It is possible that the contents of the following packets can change
  72   2          // while being updated.  This doesn't cause a problem in the sample 
  73   2          // application because the bytes are all independent.  If data is NOT 
  74   2          // independent, packet update routines should be moved to an interrupt
  75   2          // service routine, or interrupts should be disabled during data updates.
  76   2      
  77   2            if (Out_Packet[0] == 1) Led1 = 1;   // Update status of LED #1
  78   2            else Led1 = 0;
  79   2            if (Out_Packet[1] == 1) Led2 = 1;   // Update status of LED #2
  80   2            else Led2 = 0;
  81   2            P1 = (Out_Packet[2] & 0x0F);        // Set Port 1 pins 
  82   2      
  83   2      
  84   2            In_Packet[0] = Switch1State;        // Send status of switch 1
  85   2            In_Packet[1] = Switch2State;        // and switch 2 to host
  86   2            In_Packet[2] = (P0 & 0x0F);         // Port 0 [0-3] (make sure j9 & j10 jumpered)
  87   2            In_Packet[3] = Potentiometer;       // Potentiometer value
  88   2            In_Packet[4] = Temperature;         // Temperature sensor value
  89   2         }
  90   1      }
  91          
  92          //-----------------------------------------------------------------------------
  93          // Initialization Subroutines
  94          //-----------------------------------------------------------------------------
  95          
  96          //-------------------------
  97          // Sysclk_Init
  98          //-------------------------
  99          // SYSLCK Initialization
 100          // - Initialize the system clock and USB clock
 101          //
 102          void Sysclk_Init(void)
 103          {
 104   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
 113   1         OSCICN |= 0x03;                       // Configure internal oscillator for
 114   1                                               // its maximum frequency and enable
 115   1                                               // missing clock detector
 116   1      
 117   1         CLKMUL  = 0x00;                       // Select internal oscillator as 
C51 COMPILER V7.05   USB_MAIN                                                              03/07/2006 11:28:07 PAGE 3   

 118   1                                               // input to clock multiplier
 119   1      
 120   1         CLKMUL |= 0x80;                       // Enable clock multiplier
 121   1         CLKMUL |= 0xC0;                       // Initialize the clock multiplier
 122   1         Delay();                              // Delay for clock multiplier to begin
 123   1      
 124   1         while(!(CLKMUL & 0x20));                // Wait for multiplier to lock
 125   1         CLKSEL  = SYS_INT_OSC;                // Select system clock  
 126   1         CLKSEL |= USB_4X_CLOCK;               // Select USB clock
 127   1      #endif  /* _USB_LOW_SPEED_ */ 
 128   1      }
 129          
 130          //-------------------------
 131          // Port_Init
 132          //-------------------------
 133          // Port Initialization
 134          // - Configure the Crossbar and GPIO ports.
 135          //
 136          void Port_Init(void)
 137          {  
 138   1         P1MDIN   = 0x7F;                        // Port 1 pin 7 set as analog input
 139   1         P0MDOUT |= 0x0F;                        // Port 0 pins 0-3 set high impedence
 140   1         P1MDOUT |= 0x0F;                        // Port 1 pins 0-3 set high impedence
 141   1         P2MDOUT |= 0x0C;                        // Port 2 pins 0,1 set high impedence
 142   1         P1SKIP   = 0x80;                        // Port 1 pin 7 skipped by crossbar
 143   1         XBR0     = 0x00;                                                 
 144   1         XBR1     = 0x40;                        // Enable Crossbar
 145   1      }
 146          

⌨️ 快捷键说明

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