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

📄 usb2ser.lst

📁 usb serial converter
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V6.03b  USB2SER                                                               08/16/2001 12:50:55 PAGE 1   


C51 COMPILER V6.03b, COMPILATION OF MODULE USB2SER
OBJECT MODULE PLACED IN .\usb2ser.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\usb2ser.c REGFILE(.\usb2ser.ORC) BROWSE DEBUG OBJECTEXTEND CODE

stmt level    source

   1          #pragma NOIV					// Do not generate interrupt vectors
   2          //-----------------------------------------------------------------------------
   3          //	File:		periph.c
   4          //	Contents:	Hooks required to implement USB peripheral function.
   5          //
   6          //	Copyright (c) 2000 Cypress Semiconductor, Inc. All rights reserved
   7          //-----------------------------------------------------------------------------
   8          
   9          #include "ezusb.h"
  10          #include "ezregs.h"
  11          #include "serial.h"
  12          
  13          //////////////////////////////////////
  14          //                                  //
  15          // Conditional-Compilation Switches //
  16          //                                  //
  17          //////////////////////////////////////
  18          
  19          #define DEBUG			TRUE		// TRUE  = Indicate progress via Port A output pins
  20          									// FALSE = Port A pins are configured as Hi-Z inputs
  21          
  22          #define PARITY			FALSE		// TRUE  = Use Serial Port Mode 3 (parity enabled)
  23          									// FALSE = Use Serial Port Mode 1 (no parity)
  24          
  25          #define	PASS_DTR		TRUE		// TRUE  = Pass DTR state from host to RS-232.
  26          									// FALSE = DTR always on.
  27          									
  28          #define USE_CTS			FALSE		// TRUE  = Only transmit when CTS is ON.
  29          									// FALSE = Transmit regardless of CTS state.
  30          
  31          #define USE_DSR			TRUE		// TRUE  = Only transmit when DSR is ON.
  32          									// FALSE = Transmit regardless of DSR state.
  33          									
  34          #define RTS_MODE		1			// 0 = Local RTS state: Always ON.
  35          									// 1 = Local RTS state: ON when ready to send, OFF otherwise.
  36          									// 2 = Local RTS state: ON when ready to receive, OFF otherwise.
  37          
  38          #define COMBINE_RTS		TRUE		// TRUE  = Combine (AND) the host's RTS state with our own local
  39          									//         RTS state, so the RTS pin will only be ON if we and
  40          									//         the host BOTH want it ON.
  41          									// FALSE = Ignore the host's RTS state and simply pass our local
  42          									//         state to the RTS pin.
  43          
  44          #define STRICT_RTS_SPEC	FALSE		// TRUE  = In RTS_MODE 1, the RTS pin strictly follows the RS-232 spec:
  45          									//         it only transistions from OFF to ON while CTS is OFF.
  46          									// FALSE = In RTS_MODE 1, the RTS pin transitions from OFF to ON
  47          									//         regardless of the state of the CTS pin.
  48          
  49          ////////////
  50          //        //
  51          // Macros //
  52          //        //
  53          ////////////
  54          
  55          #define min(a,b) (((a)<(b))?(a):(b))
C51 COMPILER V6.03b  USB2SER                                                               08/16/2001 12:50:55 PAGE 2   

  56          
  57          ////////////////////
  58          //                //
  59          // RS-232 Defines //
  60          //                //
  61          ////////////////////
  62          
  63          // Timing
  64          
  65          #define BAUDRATE_57600		0xE1	// 0xE100
  66          #define BAUDRATE_38400		0x96	// 0x9600
  67          #define BAUDRATE_28800		0x70	// 0x7080
  68          #define BAUDRATE_19200		0x4B	// 0x4B00
  69          #define BAUDRATE_9600		0x25	// 0x2580
  70          #define BAUDRATE_4800		0x12	// 0x12C0	      
  71          #define BAUDRATE_2400		0x09	// 0x0960
  72          #define BAUDRATE_1200		0x04	// 0x04B0
  73          #define BAUDRATE_300		0x01	// 0x012C
  74          
  75          // Handshake Pins
  76          
  77          #define CTSin  (PINSC &  bmBIT2)
  78          #define DSRin  (PINSC &  bmBIT3)
  79          #define RTSout (PINSC &  bmBIT4)
  80          #define DCDin  (PINSC &  bmBIT6)
  81          #define RIin   (PINSC &  bmBIT7)
  82          
  83          #define RTSoff (OUTC |=  bmBIT4)
  84          #define RTSon  (OUTC &= ~bmBIT4)
  85          #define DTRoff (OUTC |=  bmBIT5)
  86          #define DTRon  (OUTC &= ~bmBIT5)
  87          
  88          #define CTSisOn (!(CTSin))
  89          #define DSRisOn (!(DSRin)) 
  90          #define DCDisOn (!(DCDin))
  91          #define RIisOn  (!(RIin)) 
  92          #define RTSisOn (!(RTSout))
  93          
  94          /////////////////
  95          //             //
  96          // HID Defines //
  97          //             //
  98          /////////////////
  99          
 100          #define GD_HID				0x21
 101          #define GD_REPORT			0x22
 102          #define CR_SET_REPORT 		0x09
 103          #define CR_GET_REPORT 		0x01
 104          #define HID_OUTPUT_REPORT	2
 105          #define TOTAL_IN_LENGTH 	64		// Length of IN Byte Count
 106          
 107          ///////////////
 108          //           //
 109          // Variables //
 110          //           //
 111          ///////////////
 112          
 113          // USB
 114          
 115          extern BOOL	GotSUD;					// Received setup data flag
 116          extern BOOL Sleep;
 117          
C51 COMPILER V6.03b  USB2SER                                                               08/16/2001 12:50:55 PAGE 3   

 118          BYTE 		Configuration;			// Current configuration
 119          BYTE 		AlternateSetting;		// Alternate settings
 120          
 121          // HID
 122          
 123          extern code HIDDscr;
 124          extern code ReportDscr; 
 125          extern code ReportDscrEnd;
 126          
 127          WORD		pHIDDscr;
 128          WORD		pReportDscr;
 129          WORD		pReportDscrEnd;
 130          
 131          // TX Buffer
 132          
 133          #define TX_BUFFER_SIZE 1024
 134          
 135          BYTE xdata	txBuffer[TX_BUFFER_SIZE] _at_ 0x2000;	// 1K ISO Buffer space
 136          static WORD txInPtr;								// Buffer fills (from USB) here
 137          static WORD txOutPtr;								// Buffer empties (to RS-232) here
 138          
 139          // RX Buffer
 140          
 141          #define RX_BUFFER_SIZE 1024
 142          
 143          BYTE xdata	rxBuffer[RX_BUFFER_SIZE] _at_ 0x2400;	// 1K ISO Buffer space
 144          static WORD rxInPtr;								// Buffer fills (from RS-232) here
 145          static WORD rxOutPtr;								// Buffer empties (to USB) here
 146          WORD 		nextRxInPtr;							// Used by "From RS-232" routine 
 147          
 148          // Misc
 149          
 150          static BYTE Ep1Index;				// Index into the EP1 buffer
 151          static BYTE Ep2Index;				// Index into the EP2 buffer
 152          
 153          BYTE bdata bitTemp;					// Temporary storage for the
 154          									// states of the handshake pins
 155          sbit ri  = bitTemp ^ 7;				//
 156          sbit cd  = bitTemp ^ 6;				//
 157          sbit dsr = bitTemp ^ 5;				//
 158          sbit cts = bitTemp ^ 4;				//
 159          
 160          static BYTE bdata oldTemp;			// holds the last-read status of the handshake pins.
 161          
 162          BYTE bdata bitFlags;				// Miscellaneous flags.
 163          
 164          sbit localRTS = bitFlags ^ 7;		// local RTS state
 165          sbit hostRTS  = bitFlags ^ 6;		// host's RTS state
 166          sbit sendToUSB = bitFlags ^ 5;		// 1 = we have data (or handshake-pin changes) to send to USB
 167          
 168          /////////////////////////
 169          //                     //
 170          // Function Prototypes //
 171          //                     //
 172          /////////////////////////
 173          
 174          void TD_Init   	(void);				// Initialization -- Called once from FW.C
 175          void TD_Poll	(void);				// Main routine -- Called repeatedly from FW.C's main()
 176          void setup_uart	(BYTE []);			// Setup the baud rate -- Called whenever we receive a SET_REPORT 
 177          
 178          //-----------------------------------------------------------------------------
 179          // Task Dispatcher hooks
C51 COMPILER V6.03b  USB2SER                                                               08/16/2001 12:50:55 PAGE 4   

 180          // The following hooks are called by the task dispatcher.
 181          //-----------------------------------------------------------------------------
 182          
 183          //
 184          // This function is called once at startup
 185          //
 186          
 187          void TD_Init(void)
 188          {
 189   1      
 190   1      // Initialize Endpoints
 191   1          
 192   1         	IN07VAL |= bmEP1;				// Enable EP1IN
 193   1      	OUT07VAL |= bmEP2;				// Enable EP2OUT
 194   1      
 195   1      	OUT07IEN = 0;					// Make sure endpoint interrupts are disabled.
 196   1      	USBPAIR |= 0x08;				// Double-buffer EP2OUT
 197   1      	
 198   1          Ep2Index = 2;					// Initialize the Endpoint-buffer indexes.
 199   1          Ep1Index = 0;					//
 200   1      
 201   1      // Initialize I/O Ports
 202   1          
 203   1         	PORTCCFG = 0x03; 				// PC0 and PC1 are configured for alternate functions RXD0 & TXD0
 204   1      	OEC = 0x30;		 				// Use the rest as I/O pins:
 205   1      	OUTC = 0xDF;					//     PC2: CTS (input)
 206   1      									//     PC3: DSR (input)
 207   1      					 				//     PC4: RTS (output)
 208   1      					 				//     PC5: DTR (output)
 209   1      					 				//     PC6: DCD (input)
 210   1      					 				//     PC7: RI  (input) 
 211   1      	
 212   1      	#if (DEBUG)
 213   1      	PORTACFG = 0x00;
 214   1      	OEA = 0xFF;		
 215   1      	OUTA = 0x00;	
 216   1      	#endif
 217   1      
 218   1      // Initialize TX / RX Buffers and pointers
 219   1          
 220   1         	ISOCTL |= 0x01;					// Free up isochronous endpoint RAM for TX/RX buffer space
 221   1      
 222   1      	txInPtr = txOutPtr = 0;			// Reset TX- & RX-buffer pointers to zero
 223   1      	rxInPtr = rxOutPtr = 0;			//
 224   1      
 225   1      // Setup breakpoint to trigger on TD_Poll() so the green
 226   1      // LED will light to indicate that the code's running.
 227   1      
 228   1      	BPADDR = (WORD)TD_Poll;			// Point breakpoint at TD_Poll()
 229   1      	USBBAV |= bmBPEN;				// Enable the breakpoint
 230   1      	USBBAV &= ~bmBPPULSE;			// Configure it to pulse when hit
 231   1      
 232   1      // Initialize the UART (baud rate is set later, whenever we receive
 233   1      // SET_REPORT packets from the host).
 234   1          
 235   1         	ES0	= 0;						// Make sure RX/TX interrupts are disabled.
 236   1      	TI = 1;							// Arm the TI bit to kick-start the transmitter.
 237   1      
 238   1      	DTRon;							// Initialize DTR ON.
 239   1      
 240   1      	#if ((RTS_MODE == 0) || (RTS_MODE == 2))	// If RTS_MODE = 0 (always ON) or 2 (ON when
              	localRTS = 1;								// ready to receive), initialize local RTS ON.
C51 COMPILER V6.03b  USB2SER                                                               08/16/2001 12:50:55 PAGE 5   

              	#else										// Otherwise, initialize local RTS OFF.
 243   1      	localRTS = 0;								//
 244   1      	#endif										//
 245   1      
 246   1      	hostRTS = 1;								// Assume host's RTS state is ON.
 247   1      }
 248          
 249          //
 250          // This function is called repeatedly by the main loop in FW.C
 251          //
 252          
 253          void TD_Poll(void)
 254          {
 255   1      	#if (DEBUG)
 256   1      	OUTA ^= 0x01;
 257   1      	#endif
 258   1      
 259   1      //
 260   1      // Every time through the loop, set or clear RTS appropriately.
 261   1      //
 262   1      
 263   1      	#if (COMBINE_RTS)
 264   1      	if (localRTS && hostRTS)
 265   1      	#else
              	if (localRTS)
              	#endif
 268   1      	{
 269   2      		RTSon;
 270   2      	}
 271   1      	else
 272   1      	{
 273   2      		RTSoff;
 274   2      	}
 275   1      									
 276   1      //
 277   1      // TO USB
 278   1      //
 279   1      
 280   1      	if (!(IN1CS & bmEPBUSY))		// If EP1IN is idle
 281   1      	{
 282   2      		#if (DEBUG)
 283   2      		OUTA ^= 0x02;
 284   2      		#endif
 285   2      
 286   2      		bitTemp = 0;
 287   2      		ri  = RIisOn;
 288   2      		cd  = DCDisOn;
 289   2      		dsr = DSRisOn;
 290   2      		cts = CTSisOn;
 291   2      
 292   2      		Ep1Index = 2;
 293   2      		
 294   2      		sendToUSB = 0;				// Assume we won't be sending to USB.
 295   2      
 296   2      		if (bitTemp != oldTemp)		// If the handshake pins have changed...
 297   2      		{
 298   3      			oldTemp = bitTemp;		// update oldTemp with the new pin status.

⌨️ 快捷键说明

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