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

📄 usb_main.lst

📁 自己写的 USB数据采集的固件程序
💻 LST
字号:
C51 COMPILER V7.06   USB_MAIN                                                              08/29/2007 09:51:41 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE USB_MAIN
OBJECT MODULE PLACED IN USB_MAIN.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE USB_MAIN.c ROM(COMPACT) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include <c8051f320.h>               
   2          #include "USB_REGISTER.h"
   3          #include "USB_MAIN.h"
   4          #include "USB_DESCRIPTOR.h"
   5          int k=1;
   6          int c=0;
   7          int counter=1;
   8          sfr16 TMR2RL   = 0xCC;                   // Timer2 reload value
   9          sfr16 TMR2     = 0xCD;                   // Timer2 counter  低   
  10          int n=0;  
  11          int n1=0;
  12          sbit Led1 = P2^2;        
  13          int flag=1;
  14          unsigned long  buffer[8]={0,0,0,0,0,0,0,0};
  15          BYTE Out_Packet[8] = {0,0,0,0,0,0,0,0};   // Last packet received from host
  16          BYTE In_Packet[8]  = {0,0,0,0,0,0,0,0};   // Next packet to sent to host
  17          int a,b ; 
  18          void main(void) 
  19          {
  20   1         PCA0MD &= ~0x40;                       // Disable Watchdog timer
  21   1      
  22   1         Sysclk_Init();                         // Initialize oscillator
  23   1         Port_Init();                           // Initialize crossbar and GPIO
  24   1         Usb0_Init();                           // Initialize USB0
  25   1         Timer_Init();                          // Initialize timer2
  26   1         Adc_Init();                            // Initialize ADC
  27   1      
  28   1         while (1)
  29   1          if(flag)
  30   1         { In_Packet[0]=c;
  31   2           In_Packet[3]=a;
  32   2           In_Packet[4]=b;
  33   2               In_Packet[3]=0;
  34   2               flag=0;
  35   2           Led1 = ~Led1; 
  36   2         }
  37   1      }
  38          
  39          void Sysclk_Init(void)
  40          {
  41   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
  50   1         OSCICN |= 0x03;                       // Configure internal oscillator for
  51   1                                               // its maximum frequency and enable
  52   1                                               // missing clock detector
  53   1      
  54   1         CLKMUL  = 0x00;                       // Select internal oscillator as 
  55   1                                               // input to clock multiplier
C51 COMPILER V7.06   USB_MAIN                                                              08/29/2007 09:51:41 PAGE 2   

  56   1      
  57   1         CLKMUL |= 0x80;                       // Enable clock multiplier
  58   1         CLKMUL |= 0xC0;                       // Initialize the clock multiplier
  59   1         Delay(1);                              // Delay for clock multiplier to begin
  60   1      
  61   1         while(!(CLKMUL & 0x20));                // Wait for multiplier to lock
  62   1         CLKSEL  = SYS_INT_OSC;                // Select system clock  
  63   1         CLKSEL |= USB_4X_CLOCK;               // Select USB clock
  64   1      #endif  /* _USB_LOW_SPEED_ */ 
  65   1      }
  66          
  67          void Port_Init(void)
  68          {  
  69   1         P1MDIN   = 0x7F;                        // Port 1 pin 7 set as analog input
  70   1         P0MDOUT |= 0x0F;                        // Port 0 pins 0-3 set high impedence
  71   1         P1MDOUT |= 0x0F;                        // Port 1 pins 0-3 set high impedence
  72   1         P2MDOUT |= 0x0C; 
  73   1         P2SKIP=0X00;                       // Port 2 pins 0,1 set high impedence
  74   1         P1SKIP   = 0x80;                        // Port 1 pin 7 skipped by crossbar
  75   1         XBR0     = 0x00;                                                 
  76   1         XBR1     = 0x40;                        // Enable Crossbar
  77   1      }
  78          
  79          void Usb0_Init(void)
  80          {
  81   1         POLL_WRITE_BYTE(POWER,  0x08);          // Force Asynchronous USB Reset
  82   1         POLL_WRITE_BYTE(IN1IE,  0x07);          // Enable Endpoint 0-2 in interrupts
  83   1         POLL_WRITE_BYTE(OUT1IE, 0x07);          // Enable Endpoint 0-2 out interrupts
  84   1         POLL_WRITE_BYTE(CMIE,   0x07);          // Enable Reset, Resume, and Suspend interrupts
  85   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                                      
  90   1         USB0XCN = 0xE0;                         // Enable transceiver; select full speed
  91   1         POLL_WRITE_BYTE(CLKREC, 0x80);          // Enable clock recovery, single-step mode
  92   1                                                 // disabled
  93   1      #endif /* _USB_LOW_SPEED_ */
  94   1      
  95   1         EIE1 |= 0x02;                           // Enable USB0 Interrupts
  96   1         EA = 1;                                 // Global Interrupt enable
  97   1                                                 // Enable USB0 by clearing the USB Inhibit bit
  98   1         POLL_WRITE_BYTE(POWER,  0x01);          // and enable suspend detection
  99   1      }
 100          
 101          void Timer_Init(void)
 102          {   TMR2CN  = 0x00;   
 103   1          CKCON  &= ~0xF0;  
 104   1              TMR2L     = 0x00;
 105   1          TMR2H     = 0x00;
 106   1          TMR2RLL   = 0xB0;
 107   1          TMR2RLH   = 0x3C;             
 108   1         ET2     = 1;                      
 109   1         TR2     = 1;                         
 110   1      }
 111          
 112          void Adc_Init(void)
 113          {                 
 114   1         REF0CN  = 0x0E;                        // Enable voltage reference VREF
 115   1         AMX0P = 0x1E;                        // Positive input starts as temp sensor  
 116   1         AMX0N = 0x1F;                        // Single ended mode(negative input = gnd)
 117   1         
C51 COMPILER V7.06   USB_MAIN                                                              08/29/2007 09:51:41 PAGE 3   

 118   1         ADC0CF  = 0xF8;                        // 0xFC  对齐方式 AR Period 0x1F, Right adjusted output
 119   1      
 120   1         ADC0CN  = 0xC0;                        // Continuous converion on timer 2 overflow
 121   1                                                // with low power tracking mode on
 122   1         EIE1   |= 0x08;                        // Enable conversion complete interrupt
 123   1      }
 124          
 125          
 126          void Timer2_ISR(void) interrupt 5
 127          { if(counter==0)
 128   1          {a=buffer[0]/n;
 129   2            b=buffer[1]/n;
 130   2              c=k++;
 131   2              n1=n;
 132   2              if(k==0xff) k=1;
 133   2          buffer[0]=0;
 134   2          buffer[1]=0;
 135   2           n=0;
 136   2              flag=1;
 137   2              AD0BUSY=1;
 138   2              counter=1;
 139   2              }
 140   1      else    
 141   1        counter--;
 142   1           TF2H = 0; 
 143   1                                 
 144   1      }
 145          
 146          //-------------------------
 147          // Adc_ConvComplete_ISR
 148          //-------------------------
 149          // Called after a conversion of the ADC has finished
 150          // - Updates the appropriate variable for either potentiometer or temperature sensor
 151          // - Switches the Adc multiplexor value to switch between the potentiometer and temp sensor
 152          //
 153          void Adc_ConvComplete_ISR(void) interrupt 10
 154          {
 155   1      
 156   1          buffer[1]+=ADC0L; 
 157   1          buffer[0]+=ADC0H;
 158   1          n++;
 159   1         AD0INT = 0;
 160   1      }
 161          
 162          void Delay(i)
 163          {  
 164   1         int x,y;
 165   1         for(y=0;y<i;y++)
 166   1         {
 167   2         for(x = 0;x < 500;)
 168   2            x++;
 169   2                }
 170   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    544    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     64    ----
   IDATA SIZE       =   ----    ----
C51 COMPILER V7.06   USB_MAIN                                                              08/29/2007 09:51:41 PAGE 4   

   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 + -