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

📄 usb_main.lst

📁 CyPress的C8051F32X系列底层驱动(C语言)及上位机demo(vc环境)
💻 LST
📖 第 1 页 / 共 2 页
字号:
 147          //-------------------------
 148          // Usb0_Init
 149          //-------------------------
 150          // USB Initialization
 151          // - Initialize USB0
 152          // - Enable USB0 interrupts
 153          // - Enable USB0 transceiver
 154          // - Enable USB0 with suspend detection
 155          //
 156          void Usb0_Init(void)
 157          {
 158   1         POLL_WRITE_BYTE(POWER,  0x08);          // Force Asynchronous USB Reset
 159   1         POLL_WRITE_BYTE(IN1IE,  0x07);          // Enable Endpoint 0-2 in interrupts
 160   1         POLL_WRITE_BYTE(OUT1IE, 0x07);          // Enable Endpoint 0-2 out interrupts
 161   1         POLL_WRITE_BYTE(CMIE,   0x07);          // Enable Reset, Resume, and Suspend interrupts
 162   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                                      
 167   1         USB0XCN = 0xE0;                         // Enable transceiver; select full speed
 168   1         POLL_WRITE_BYTE(CLKREC, 0x80);          // Enable clock recovery, single-step mode
 169   1                                                 // disabled
 170   1      #endif /* _USB_LOW_SPEED_ */
 171   1      
 172   1         EIE1 |= 0x02;                           // Enable USB0 Interrupts
 173   1         EA = 1;                                 // Global Interrupt enable
 174   1                                                 // Enable USB0 by clearing the USB Inhibit bit
 175   1         POLL_WRITE_BYTE(POWER,  0x01);          // and enable suspend detection
 176   1      }
 177          
 178          //-------------------------
 179          // Timer_Init
C51 COMPILER V7.05   USB_MAIN                                                              03/07/2006 11:28:07 PAGE 4   

 180          //-------------------------
 181          // Timer initialization
 182          // - Timer 2 reload, used to check if switch pressed on overflow and
 183          // used for ADC continuous conversion
 184          //
 185          void Timer_Init(void)
 186          {
 187   1         TMR2CN  = 0x00;                        // Stop Timer2; Clear TF2;
 188   1      
 189   1         CKCON  &= ~0xF0;                       // Timer2 clocked based on T2XCLK;
 190   1         TMR2RL  = 0;                           // Initialize reload value
 191   1         TMR2    = 0xffff;                      // Set to reload immediately
 192   1      
 193   1         ET2     = 1;                           // Enable Timer2 interrupts
 194   1         TR2     = 1;                           // Start Timer2
 195   1      }
 196          
 197          //-------------------------
 198          // Adc_Init
 199          //-------------------------
 200          // ADC initialization
 201          // - Configures ADC for single ended continuous conversion or Timer2
 202          //
 203          void Adc_Init(void)
 204          {                 
 205   1         REF0CN  = 0x0E;                        // Enable voltage reference VREF
 206   1         AMX0P = 0x1E;                        // Positive input starts as temp sensor  
 207   1         AMX0N = 0x1F;                        // Single ended mode(negative input = gnd)
 208   1      
 209   1         ADC0CF  = 0xF8;                        // SAR Period 0x1F, Right adjusted output
 210   1      
 211   1         ADC0CN  = 0xC2;                        // Continuous converion on timer 2 overflow
 212   1                                                // with low power tracking mode on
 213   1      
 214   1         EIE1   |= 0x08;                        // Enable conversion complete interrupt
 215   1      }
 216          
 217          //-------------------------
 218          // Timer2_ISR
 219          //-------------------------
 220          // Called when timer 2 overflows, check to see if switch is pressed,
 221          // then watch for release.
 222          //
 223          void Timer2_ISR(void) interrupt 5
 224          {
 225   1         if (!(P2 & Sw1))                      // Check for switch #1 pressed
 226   1         {
 227   2            if (Toggle1 == 0)                   // Toggle is used to debounce switch
 228   2            {                                   // so that one press and release will
 229   3               Switch1State = ~Switch1State;    // toggle the state of the switch sent
 230   3               Toggle1 = 1;                     // to the host
 231   3            }
 232   2         }
 233   1         else Toggle1 = 0;                      // Reset toggle variable
 234   1      
 235   1         if (!(P2 & Sw2))                       // This is the same as above, but for Switch2
 236   1         {
 237   2            if (Toggle2 == 0)
 238   2            {  
 239   3               Switch2State = ~Switch2State;
 240   3               Toggle2 = 1;
 241   3            }
C51 COMPILER V7.05   USB_MAIN                                                              03/07/2006 11:28:07 PAGE 5   

 242   2         }
 243   1         else Toggle2 = 0;
 244   1      
 245   1         TF2H = 0;                              // Clear Timer2 interrupt flag
 246   1      }
 247          
 248          //-------------------------
 249          // Adc_ConvComplete_ISR
 250          //-------------------------
 251          // Called after a conversion of the ADC has finished
 252          // - Updates the appropriate variable for either potentiometer or temperature sensor
 253          // - Switches the Adc multiplexor value to switch between the potentiometer and temp sensor
 254          //
 255          void Adc_ConvComplete_ISR(void) interrupt 10
 256          {
 257   1         if (AMX0P == 0x1E)                    // This switches the AMUX between
 258   1         {                                     // the temperature sensor and the
 259   2            Temperature   = ADC0L;             // potentiometer pin after each conversion
 260   2            Temperature  += TEMP_ADD;          // Add offset to Temperature
 261   2            AMX0P       = 0x07;                // switch to potentiometer
 262   2                ADC0CF      = 0xFC;                // Place ADC0 in left-adjusted mode
 263   2         }
 264   1         else
 265   1         {
 266   2            Potentiometer = ADC0H;
 267   2            AMX0P       = 0x1E;                // switch to temperature sensor
 268   2                ADC0CF      = 0xF8;                // place ADC0 in right-adjusted mode
 269   2         }
 270   1      
 271   1         AD0INT = 0;
 272   1      }
 273          
 274          //-------------------------
 275          // Delay
 276          //-------------------------
 277          // Used for a small pause, approximately 80 us in Full Speed,
 278          // and 1 ms when clock is configured for Low Speed
 279          //
 280          void Delay(void)
 281          {
 282   1         int x;
 283   1         for(x = 0;x < 500;x)
 284   1            x++;
 285   1      }


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