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

📄 f320_hidtouart.lst

📁 hid to rs232 usb_hid 转 串口程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.17   F320_HIDTOUART                                                        03/18/2009 09:55:18 PAGE 1   


C51 COMPILER V8.17, COMPILATION OF MODULE F320_HIDTOUART
OBJECT MODULE PLACED IN F320_HIDtoUART.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE F320_HIDtoUART.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //-----------------------------------------------------------------------------
   2          // F320_HIDtoUART.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2008 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          //
   9          // Stub file for Firmware Template.
  10          //
  11          //
  12          // How To Test:    See Readme.txt
  13          //
  14          //
  15          // FID             
  16          // Target:         C8051F32x/C8051F340
  17          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  18          //                 Silicon Laboratories IDE version 2.6
  19          // Command Line:   See Readme.txt
  20          // Project Name:   HIDtoUART
  21          //
  22          // Release 1.0
  23          //    -Initial Revision (PD)
  24          //    -04 JUN 2008
  25          //
  26          
  27          //-----------------------------------------------------------------------------
  28          // Header Files
  29          //-----------------------------------------------------------------------------
  30          #include <c8051f3xx.h>
  31          #include "F3xx_USB0_InterruptServiceRoutine.h"
  32          #include "F3xx_USB0_Register.h"
  33          #include "F3xx_HIDtoUART.h"
  34          #include <intrins.h>
  35          //-----------------------------------------------------------------------------
  36          // Definitions
  37          //-----------------------------------------------------------------------------
  38          #define SYSCLK             24000000    // SYSCLK frequency in Hz
  39          
  40          // USB clock selections (SFR CLKSEL)
  41          #define USB_4X_CLOCK       0x00        // Select 4x clock multiplier, for USB
  42          #define USB_INT_OSC_DIV_2  0x10        // Full Speed
  43          #define USB_EXT_OSC        0x20
  44          #define USB_EXT_OSC_DIV_2  0x30
  45          #define USB_EXT_OSC_DIV_3  0x40
  46          #define USB_EXT_OSC_DIV_4  0x50
  47          
  48          // System clock selections (SFR CLKSEL)
  49          #define SYS_INT_OSC        0x00        // Select to use internal oscillator
  50          #define SYS_EXT_OSC        0x01        // Select to use an external oscillator
  51          #define SYS_4X_DIV_2       0x02
  52          
  53          
  54          //-----------------------------------------------------------------------------
  55          // Local Function Prototypes
C51 COMPILER V8.17   F320_HIDTOUART                                                        03/18/2009 09:55:18 PAGE 2   

  56          //-----------------------------------------------------------------------------
  57          // Initialization Routines
  58          void Sysclk_Init (void);               // Initialize the system clock
  59          void Port_Init (void);                 // Configure ports
  60          void Usb0_Init (void);                 // Configure USB core
  61          void Delay (void);                     // Approximately 80 us/1 ms on
  62                                                 // Full/Low Speed
  63          void UART0_Init(void);
  64          
  65          //-----------------------------------------------------------------------------
  66          // Global Variables
  67          //-----------------------------------------------------------------------------
  68          #ifndef BAUDRATE_HARDCODED
  69          unsigned long BaudRate;
  70          #endif
  71          
  72          // IN_PACKET and OUT_PACKEt buffer bytes immediately before and
  73          // after they are transferred across USB inside the report handlers
  74          unsigned char xdata IN_PACKET[64];
  75          unsigned char xdata OUT_PACKET[64];
  76          
  77          // UART_INPUT and UART_OUTPUT buffer bytes immediately before
  78          // and after they are transferred across the UART interface
  79          unsigned char xdata UART_INPUT[UART_INPUT_BUFFERSIZE];
  80          unsigned char xdata UART_OUTPUT[UART_OUTPUT_BUFFERSIZE];
  81          
  82          // UART_OUTPUT_OVERFLOW_BOUNDARY holds a calculation showing how
  83          // many bytes can be transmitted out of the buffer in the span of time
  84          // before another USB report is received
  85          // If the buffer size crosses this boundary, USB communication should be
  86          // suspended until the buffer shrinks below the boundary
  87          unsigned char UART_OUTPUT_OVERFLOW_BOUNDARY;
  88          
  89          unsigned char USB_OUT_SUSPENDED;       // Flag set when buffer size crosses
  90                                                 // boundary
  91          
  92          unsigned char UART_INPUT_SIZE = 0;     // Maintains size of input buffer
  93          unsigned char UART_OUTPUT_SIZE = 0;    // Maintains size of output buffer
  94          
  95          unsigned char UART_INPUT_LAST = 0;     // Points to oldest byte received
  96          unsigned char UART_INPUT_FIRST = 0;    // Points to newest byte received
  97          
  98          unsigned char UART_OUTPUT_LAST = 0;    // Points to oldest byte received
  99          unsigned char UART_OUTPUT_FIRST = 0;   // Points to newest byte received
 100          unsigned char TX_Ready;                // Flag used to initiate UART transfer
 101          
 102          
 103          //-----------------------------------------------------------------------------
 104          // Interrupt Service Routines
 105          //-----------------------------------------------------------------------------
 106          //-----------------------------------------------------------------------------
 107          // UART0 Interrupt Service Routine
 108          //-----------------------------------------------------------------------------
 109          // Routine transmits a byte by pulling LAST byte from UART_OUTPUT buffer.
 110          // Routine receives a byte by pushing it as FIRST byte on UART_INPUT buffer.
 111          //
 112          void UART0_Interrupt (void) interrupt 4
 113          {
 114   1      //   DEBUG_UART = 1;
 115   1         if (RI0 == 1)                       // Received byte flag
 116   1         {
 117   2            RI0 = 0;                         // Acknowledge flag
C51 COMPILER V8.17   F320_HIDTOUART                                                        03/18/2009 09:55:18 PAGE 3   

 118   2      
 119   2            // Note: the code below only works correctly if the UART buffers
 120   2            // are 127 bytes (0x7F) in length
 121   2            // This allows buffer wrapping to be accomplished by simply
 122   2            // clearing the MSB
 123   2            UART_INPUT_FIRST++;              // Move pointer
 124   2            UART_INPUT_FIRST &= ~0x80;       // Wrap pointer if necessary
 125   2                         
 126   2            // Save received byte onto buffer
 127   2            UART_INPUT[UART_INPUT_FIRST] = SBUF0;
 128   2      
 129   2            UART_INPUT_SIZE++;               // Increment buffer size
 130   2         }
 131   1      
 132   1         if (TI0 == 1)                       // Transmit complete flag
 133   1         {
 134   2            TI0 = 0;                         // Acknowledge flag
 135   2            if (UART_OUTPUT_SIZE != 0)       // If buffer is not empty
 136   2            {  
 137   3               UART_OUTPUT_LAST++;           // Move buffer pointer
 138   3      
 139   3               UART_OUTPUT_LAST &= ~0x80;    // Wrap pointer
 140   3      
 141   3               // Transmit byte from buffer
 142   3               SBUF0 = UART_OUTPUT[UART_OUTPUT_LAST];
 143   3               UART_OUTPUT_SIZE--;           // Decrement buffer size
 144   3            }
 145   2            else
 146   2            {
 147   3               TX_Ready = 1;                 // Buffer is empty, signal that
 148   3                                             // UART TX is free and ready to
 149   3                                             // transmit
 150   3            }
 151   2         }
 152   1      
 153   1      }
 154          //-----------------------------------------------------------------------------
 155          // Initialization Routines
 156          //-----------------------------------------------------------------------------
 157          
 158          //-----------------------------------------------------------------------------
 159          // DEFAULT_InitRoutine
 160          //-----------------------------------------------------------------------------
 161          // This function is declared in the header file F3xx_HIDtoUART.h and is
 162          // called in the main(void) function.  It calls initialization routines
 163          // local to this file.
 164          //
 165          //-----------------------------------------------------------------------------
 166          void System_Init (void)
 167          {
 168   1         Sysclk_Init ();                     // Initialize oscillator
 169   1         Port_Init ();                       // Initialize crossbar and GPIO

⌨️ 快捷键说明

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